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=202412 header.b=PqoFLAGS; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 586745A0621 for ; Fri, 20 Dec 2024 09:58:41 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202412; t=1734685098; bh=qcwgQpTIYBrUp2DYyiNSJ23x3Ys65WeDdnyXuJY7i3Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PqoFLAGSiUe8JD8FsOQfZSdtRQHx3lD7ETiUhPy7pB/mo1lq/ogKfZwqbwgHgGCCn PAcBJmUqLwW1qqudDW+FflIGVRNEJxQYfQEWbu5Apy9Jq6BnwJwNAWDRAGvI8B7nk+ Kbi1TXdKXHkGnXqd0pONlYsu3g7ikUjZvN79SmtssL70gjm/I21Qhc6LdhrPNqfP6G pBKk5HtOKwRphNPnyoWZesBgX6w2oxOG7l0h13N/3YRDFtIprVZDN0+fG0fcxG3LqZ TjuyAU+AWtgTLKjOFoWmEEWp/KPgyUErD2MGzyTo5/2ITGZu/knI3TZbRAC8J81mhe nvLkclMhUMF3A== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4YF1Xp1TsCz4xdw; Fri, 20 Dec 2024 19:58:18 +1100 (AEDT) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH v2 10/12] packet: Move packet length checks into packet_check_range() Date: Fri, 20 Dec 2024 19:35:33 +1100 Message-ID: <20241220083535.1372523-11-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241220083535.1372523-1-david@gibson.dropbear.id.au> References: <20241220083535.1372523-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: R4UHCI23M4OHUWXSBL22UBSFMJ2QEIR7 X-Message-ID-Hash: R4UHCI23M4OHUWXSBL22UBSFMJ2QEIR7 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: Both packet_add_do() and packet_get_do() have a check on the given length, essentially sanity checking it before validating that it's in an expected memory region. This can be folded into packet_check_range() which performs similar checks for both functions. Signed-off-by: David Gibson --- packet.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/packet.c b/packet.c index 24f12448..9e0e6555 100644 --- a/packet.c +++ b/packet.c @@ -37,6 +37,10 @@ static void packet_check_range(const struct pool *p, const char *ptr, size_t len, const char *func, int line) { + ASSERT_WITH_MSG(len <= PACKET_MAX_LEN, + "packet_check_range length %zu (max %zu), %s:%i", + len, PACKET_MAX_LEN, func, line); + if (p->buf_size == 0) { vu_packet_check_range((void *)p->buf, ptr, len, func, line); return; @@ -72,10 +76,6 @@ void packet_add_do(struct pool *p, size_t len, const char *start, packet_check_range(p, start, len, func, line); - ASSERT_WITH_MSG(len <= PACKET_MAX_LEN, - "add packet length %zu (max %zu), %s:%i", - len, PACKET_MAX_LEN, func, line); - p->pkt[idx].iov_base = (void *)start; p->pkt[idx].iov_len = len; @@ -102,9 +102,6 @@ void *packet_get_do(const struct pool *p, size_t idx, size_t offset, ASSERT_WITH_MSG(idx < p->size && idx < p->count, "packet %zu from pool size: %zu, count: %zu, %s:%i", idx, p->size, p->count, func, line); - ASSERT_WITH_MSG(len <= PACKET_MAX_LEN, - "packet range length %zu (max %zu), %s:%i", - len, PACKET_MAX_LEN, func, line); if (len + offset > p->pkt[idx].iov_len) { trace("data length %zu, offset %zu from length %zu, %s:%i", -- 2.47.1