From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202502 header.b=PPdbd0EP; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 8C2475A0274 for ; Wed, 12 Mar 2025 04:07:05 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202502; t=1741748820; bh=HgNd3BN1qY6v6J94AaBhIwIypdp7mNBr9DXIjxsGEks=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PPdbd0EPfb6+6c3jd5SSgURW5eZJm+UaJvSmkD9jmCpYSnzAXKd387/eU/4t8QU+9 /iYvMyBtpm0un4h+VLPT3qouy/b/4PFji0qa5U9swXIM63XdXXwBcU1GDXNOvv9DDn SZa7SrPmVcsi+3frINIAC1fdSNDQ946iG2mXhVJm8X8uGbNHWnWRfWcsU+pcv/oIWP a/T8Hq++5XFPJ2VSTfV3bb92wNw0FQsh9MGN3x1Ee89isGsI938VVGRPBYs9VNMofT Y0r49Lxu0ZAT5is2zDeSDIv8TRvs4UDD8oUwV014O06Qm9/mSJAA2L1l/WQAkbpw4B GMkJRXvnvr1gw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4ZCFsc5KHWz4xG4; Wed, 12 Mar 2025 14:07:00 +1100 (AEDT) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH v2 4/9] packet: Give explicit name to maximum packet size Date: Wed, 12 Mar 2025 13:18:34 +1100 Message-ID: <20250312021839.2405877-5-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250312021839.2405877-1-david@gibson.dropbear.id.au> References: <20250312021839.2405877-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: ZGYQBAGD22MGI73QGZV5PUFBAOKCQOWC X-Message-ID-Hash: ZGYQBAGD22MGI73QGZV5PUFBAOKCQOWC X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: We verify that every packet we store in a pool (and every partial packet we retreive from it) has a length no longer than UINT16_MAX. This originated in the older packet pool implementation which stored packet lengths in a uint16_t. Now, that packets are represented by a struct iovec with its size_t length, this check serves only as a sanity / security check that we don't have some wildly out of range length due to a bug elsewhere. We have may reasons to (slightly) increase this limit in future, so in preparation, give this quantity an explicit name - PACKET_MAX_LEN. Signed-off-by: David Gibson --- packet.c | 4 ++-- packet.h | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packet.c b/packet.c index 0330b548..bcac0375 100644 --- a/packet.c +++ b/packet.c @@ -83,7 +83,7 @@ void packet_add_do(struct pool *p, size_t len, const char *start, if (packet_check_range(p, start, len, func, line)) return; - if (len > UINT16_MAX) { + if (len > PACKET_MAX_LEN) { trace("add packet length %zu, %s:%i", len, func, line); return; } @@ -119,7 +119,7 @@ void *packet_get_do(const struct pool *p, size_t idx, size_t offset, return NULL; } - if (len > UINT16_MAX) { + if (len > PACKET_MAX_LEN) { if (func) { trace("packet data length %zu, %s:%i", len, func, line); diff --git a/packet.h b/packet.h index bdc07fef..d099f026 100644 --- a/packet.h +++ b/packet.h @@ -6,6 +6,9 @@ #ifndef PACKET_H #define PACKET_H +/* Maximum size of a single packet stored in pool, including headers */ +#define PACKET_MAX_LEN UINT16_MAX + /** * struct pool - Generic pool of packets stored in a buffer * @buf: Buffer storing packet descriptors, -- 2.48.1