From nobody Mon Nov 23 04:26:37 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1793650756; cv=none; d=zohomail.com; s=zohoarc; b=cX+G7EwBQzGE1t01Cw4vbn9DostVMtmjWXP2ARQ+YV2BEfodyfrupJ2Sn0L950qheJ5ibtJ3EiE+Zpn2MB1pcizzBFxmkkpgOPeV/81oX/clU/DR45BOEjGz7cohnugxTH7b+4a+IeFHmWeGnNZkrG8JXk9QuYvWukOZhXluseg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793650756; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=t24QZAPTVs1RY8XVA5r9uFyJSsdgfHnAH1qIEZM4lLI=; b=Zw/RlQDPLgbkMN4774zaVK/Es3NdfjVhCh1JYelfcAQMXcsAQJVtAVFJp6npHkm7q06o3AQJMxDcFf77H3O81McIlwH/xrkBtjXyqQGGxtorP0e/o0nD0IDdOzI2I74+NIdnd9vfBV8IusalJW6Hio7Cnhp7rza5CWnVoPifDp0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793650756053672.5619106600319; Mon, 2 Nov 2026 12:19:16 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xNyUm-00072a-U1; Mon, 02 Nov 2026 15:19:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xNyUF-0006yH-GJ for qemu-devel@nongnu.org; Mon, 02 Nov 2026 15:18:35 -0500 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xNyUD-0006i8-LX for qemu-devel@nongnu.org; Mon, 02 Nov 2026 15:18:35 -0500 Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-48df8fe8513so2948349f8f.0 for ; Mon, 02 Nov 2026 12:18:32 -0800 (PST) Received: from lanath.. (wildly.archaic.org.uk. [81.2.115.145]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e71b79059sm22152836f8f.30.2026.11.02.12.18.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2026 12:18:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1793650711; x=1794255511; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=t24QZAPTVs1RY8XVA5r9uFyJSsdgfHnAH1qIEZM4lLI=; b=mtOJ4dnkDK9thEK5HMex7lAX3ILiUXB79dywiW/nKXJ3Kx/ulvJDqBsgJhtYQ1UgKu M1B0YGF7x4S5PLZgFqVQYPgRf/TfBIQYtnGJGbnCxCAH37UCJwDUCiqrBcwwwuhKN7+R qaL9RtN9TCVqLoKgQhEcOjO6k0Ump6Gkjp2czTW6zHwR/4SBq7aglEoumrIDXJDXe2Vy prIE9rzx7gHFWcp7pF8Q/45H0wGb1+sTqiCR643XXf17BcWeJLqp1089UFkL92h4KbG8 OFmjecfQ9mNeSB9eB6Gj5lTd2+6o78FgdUD4+ZCQpnrYUlWb4n5tDQEBU9qZvsGQsImo VRcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793650711; x=1794255511; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=t24QZAPTVs1RY8XVA5r9uFyJSsdgfHnAH1qIEZM4lLI=; b=paeEPPmXDMEuMWdVaBJqXFvzlrfx2zY1pyuaFejbwwKu+lp9kyrp3UnmToWEdGZsP/ 3sQiuQ2Dcuu9hAuXLt/cMuOu7nmm9MxceuFvGdkE2mnwP+M8Ro4eBZR/hNd/8b/caZdV BmxP9HC3xU2+zAGeTmXXC47f1wqoGgP1Vq0l+0PVieI6z7w5evVurM8w8clK9smxIpDH 8kKYUQPKWYYGcI8MmaxjZwIKc6GohPZMFGNYRUryQdoOPNXNSwPX6X1M78Q9hDi0Fchf ipnbHluvmOdoNxyU1Y3oYT7NpsTE8SzWCrlg4P14fjDXofyz4U442on95FD+2G3swPCk I4qw== X-Gm-Message-State: APuU4Z8Aaa6xFj1IJTaK6V6FZCwUg4gVuFX4j3Z3sT3makwopjLRL3zr xaIL6v5cKP+s8Uo51RV1x595z8ukjinzHhERORVgNpAeOTSGDNW3tCSOD57nncmJ2MFqV7piuUA klRXK260= X-Gm-Gg: AYBFou2+k42oH+kH13lmsV9BtYJwxZmjojfweO20Er/gd/AzjvPtn3mXTx/yFkwEjbU AvLbE4dwC7G4qUwSLH83EoZI+10xoTAabXVxeA6tcgzlQ4okIcG0ACI5zw8gZUDIP3SlH0vv91P J/k3KnvN1gBg8RCXlCeMtYdhlfXD4yiAFyBvwHOndTpOP8+jpHwz0j9FA2hN+fL6pdt9/HWom/8 iHgwQ62+1v8CVUJ2rE7pqnaPh4chrvVNrnI8mGuRo9iDJkT6M5icNIgKNsCQBrESPZWoI20kYXk WlCCLfEFJWKpX34cnb09hRDy+eNPkaE0k/X8+8mz1HFNqhq47jVJ5ij/Bvlqn7qsKnpbNoeKLU1 sLYV21z4/gpIi9vto2GaaBg+w+2k0hBWS5cUYxiOCli/zRTuJC/shIrCl2GCrRxVw8s4c4sECy/ WlQEFBT7h1ZeQ/Xvf+w+imspkWZ7AY2yEssYjPPtUPC0xm7AUeZDM1Yzw4yLqlHBfUpivPBrc7h oLidzJkIJl+h3YDHi5wZ3cBXce2wxghWIUyLTT8+AFSlwi/DKlKG2kWqisneRL+fonAk7ZVjYhk 4s6YR38MBedwKLXOKLp1FV3ftBewEXhKSnPQQ5OCLPNsUKGERx6erDAqtAUpornOKWgsgbFtcxf Z9sqBqurnn7nRodfxHe4/WnRW4q67mKPR+3k= X-Received: by 2002:a05:6000:2207:b0:48e:e98:8b6a with SMTP id ffacd0b85a97d-48e6e2db50fmr22513811f8f.4.1793650711593; Mon, 02 Nov 2026 12:18:31 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Jason Wang , Akihiko Odaki , Dmitry Fleytman Subject: [PATCH 01/11] hw/net/net_rx_pkt: Handle bogus l4hdr_off when validating SCTP checksum Date: Mon, 2 Nov 2026 20:18:18 +0000 Message-ID: <20261102201828.1879576-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261102201828.1879576-1-peter.maydell@linaro.org> References: <20261102201828.1879576-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::42a; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1793650756915158500 Content-Type: text/plain; charset="utf-8" In _net_rx_pkt_validate_sctp_sum() we calculate a checksum that starts at the NetRxPkt::l4hdr_off offset. If this offset (which might be guest controlled) is larger than the size of the packet, the loop that walks through the iovec can walk off the end of it. The resulting out-of-bounds read in attempting to convert the iov to a buffer might cause a segfault. We also weren't correctly checking the return values of iov_to_buf() and iov_from_buf() when reading and writing the checksum word: if the l4hdr_off claims the checksum word is half off the end of the packet these functions will return the count of how much data they were able to access, and we should fail if they don't write the entire 4 byte word. Return "checksum not valid" if the l4hdr_off is too large or the iov accesses don't do the full read/write. Note that this affects only the igb network device; the other user of this function (e1000e) does its own check on the l4 header and won't calculate a checksum if it's out of range. Cc: qemu-stable@nongnu.org Fixes: 907209e3111dd62 ("igb: Implement Rx SCTP CSO") Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4138 Signed-off-by: Peter Maydell --- hw/net/net_rx_pkt.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/hw/net/net_rx_pkt.c b/hw/net/net_rx_pkt.c index f87b6f046cc..03a35f03154 100644 --- a/hw/net/net_rx_pkt.c +++ b/hw/net/net_rx_pkt.c @@ -549,19 +549,23 @@ _net_rx_pkt_validate_sctp_sum(struct NetRxPkt *pkt) uint32_t original; bool valid; =20 - for (vec =3D pkt->vec; vec->iov_len < off; vec++) { + for (vec =3D pkt->vec; vec_len > 0 && vec->iov_len < off; vec++) { off -=3D vec->iov_len; vec_len--; } + if (vec_len =3D=3D 0) { + return false; + } =20 csum_off =3D off + 8; =20 - if (!iov_to_buf(vec, vec_len, csum_off, &original, sizeof(original))) { + if (iov_to_buf(vec, vec_len, csum_off, + &original, sizeof(original)) !=3D sizeof(original)) { return false; } =20 - if (!iov_from_buf(vec, vec_len, csum_off, - &calculated, sizeof(calculated))) { + if (iov_from_buf(vec, vec_len, csum_off, + &calculated, sizeof(calculated)) !=3D sizeof(calculat= ed)) { return false; } =20 --=20 2.43.0 From nobody Mon Nov 23 04:26:37 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1793650760; cv=none; d=zohomail.com; s=zohoarc; b=WjkIbpheNPjFtDqZWHoYzOVC/0HEMChZsYJgITJvaauQXP+pFr6IJQrJ+V64fadKHKClI4cSgmY0g57PnZR9JKok7cDbYFa5qmzrPvIpB6qp5IQvNc6Q9badvzlwegsKYjB9KA4X09nBp13O9Lrv5i/qCqqSCSCzthcgmQ8EU/0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793650760; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=3Atfu0g8wY0eKizwD/l8cX4C3K+pWhHyMdzqeBKdenA=; b=geWcMLllbo6sDKEA3NUk3lUD/k0mrnRgRWOmnPiDsiCWtJuSewG8PwFSZZUAqAm10BNK+JKUnkiIXGods5Fl3NcVFBvNIeIWkxx0LsM/8W1dXY8Y4Pdpe+NH90wS89Dc0aQ2OS27jitjRLLeB43b1tZL41aPzz1vFYRtZcMWt2Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793650760601897.4236031611869; Mon, 2 Nov 2026 12:19:20 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xNyUk-00070p-Qn; Mon, 02 Nov 2026 15:19:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xNyUG-0006ye-Nm for qemu-devel@nongnu.org; Mon, 02 Nov 2026 15:18:37 -0500 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xNyUE-0006iF-Vw for qemu-devel@nongnu.org; Mon, 02 Nov 2026 15:18:36 -0500 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-4a208d93758so36624085e9.3 for ; Mon, 02 Nov 2026 12:18:34 -0800 (PST) Received: from lanath.. (wildly.archaic.org.uk. [81.2.115.145]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e71b79059sm22152836f8f.30.2026.11.02.12.18.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2026 12:18:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1793650713; x=1794255513; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=3Atfu0g8wY0eKizwD/l8cX4C3K+pWhHyMdzqeBKdenA=; b=su0gW1q/dyKL5l6YZ+mmmEBdmoITt29CBxuuXOqgxJJuQlYgaEDWX5Vol5qhaq6m14 /9wmshni9+4PYbaMLW0CI0TeNSX71N1tzc7Ws+dqsqT658zcbPJIXSF2jR1q5t93Ckse x7i4ilDAhmECk3hl/hRZnBd7aGuwOH702kJREiFU4C+pdxkq01ex861FkcMWSfj2OgaU 5yjWcJqv+bKqTtrxtiV/glbRmJab+V2yZkeQsg7ZmFySkIs1YCocBgmpFvMuRa7xfqd9 0u/Le5500GD1H2gNel5Hwn00v91L0VknLfVVAIKiNPyz3rm9TNt8czrWjJ1enoCbC+YV wXsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793650713; x=1794255513; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=3Atfu0g8wY0eKizwD/l8cX4C3K+pWhHyMdzqeBKdenA=; b=2p0S0NmjOK5FjIEOSlfKItp3+ZjM6SbrQKpulBd/F5zQ2LGi3/NxVWyYBURuQvNV53 i9KiToP0ubwcIgpbeOGl/6EsreafGCzSXdLUpXHt8mxtJbSWXrG3mvn5VldE6UZ7lkBt pmMOXb+JA7DwYI2wk7Gwh6cJXFty7MYQcBHsPfJJ57bKebHPdKHQZ5/i/UXrwt3XBKKg 9JS+6UR2Z9FAQfmKuE4BVd5DOePv6NaDlDTXzqtRw3Ac+Dd6MwGzOtmQ/nheqFiyxB4t Ec+UMODPuZeRJ4dsyFD7z1ObX04WFVPMbDAaI7u5ld2Ytq1YKG20CCLNo+gEEKq0JseV SkNw== X-Gm-Message-State: AFq9FYJg7ZmnC6WL7p5rwBjaeYh4LWnHJRHGziuLkGsUFzWtt9foinG3 rO6jojtS11L6gqCKit3AfijA9xsJjyfeVyx0pIMbAAeTvlfSqWhYMQ2KW4Ti1xWnDv66a5Fllxe cHAGQ0sE= X-Gm-Gg: AYBFou0R93e+Gj4skVNJuapgjgkCan91b1rme7t9f7uq3Z3zioVouoM4QbfC5u+Fj0y DfM6cqxrjIkxZVj7XdAwlLryhkYH91YL02US7M8ukXQHy8+pQwCYjI2qFsoYZAZb8qZYzcWECkl WEux/ta3PCOyAX3Jnwqef1NRnMa5dJqhEFidfHCQRSOC267ZkUgJDgRxXrrPsNe8T9CIIP9Pzv1 02jbqF1IZYI1lyIBPCtt5pv/3mniBAK3D9yQFuIIEondIfx15U6lYnYETSDvzopk7NJTrodcX8k NRljyrFIxUFI82kg2UKuoHGnHaM5fQqWntX8oTVWZ6rg7yJCgfb5pnp0Ej0ajM1xS93a9xnCOwR YyAmE95TJIGLH6Pw5A2s77rb2gra0GyAnFRdhmXmLCncO12fbzuKhptE0V5OO0IhQdSxESN2Aph K6vBHUfEmB3HMaEsVVQwvL/jiEB+cbfjNArkTFzc+fJLxKXyiB1PxMde+7KaAomqHHw/pLa1HYQ E/6r1Q6oOv8Bz+OgP9ZuX/91F3TUJXWai4PpnjNoxRD5XpraPqBLR/d6SAzAr6z/XClVUOFFmKJ Eu5PiR4RMnKmbG5+GKpFnlJ1eh5ROlq2C+VouUJFAIq3K6lXUuAgymFcOfs0Dn4487r46x6Xe0S 2319MO4M+tlyQShw6VuA5Nw3RRr8r8M8uvw== X-Received: by 2002:a05:600c:4f86:b0:4a7:669c:c988 with SMTP id 5b1f17b1804b1-4ac18b7df2cmr261711115e9.23.1793650713546; Mon, 02 Nov 2026 12:18:33 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Jason Wang , Akihiko Odaki , Dmitry Fleytman Subject: [PATCH 02/11] net/eth.c: In eth_parse_ipv6_hdr(), fix check of input size Date: Mon, 2 Nov 2026 20:18:19 +0000 Message-ID: <20261102201828.1879576-3-peter.maydell@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261102201828.1879576-1-peter.maydell@linaro.org> References: <20261102201828.1879576-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::333; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x333.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1793650763159158500 Content-Type: text/plain; charset="utf-8" In the eth_parse_ipv6_hdr() function, when parsing the extension headers we check if (input_size < ip6hdr_off + info->full_hdr_len) { return false; } This is checking that an extension header did not specify an extension header length that claims to extend off the end of the actual packet. However, we do it at the wrong end of the loop: * In the first iteration, full_hdr_len is sizeof(struct ipv6_header) (i.e. just the initial fixed IPv6 header); but this check is redundant because the initial part of the function did an iov_to_buf() of sizeof(ip6_hdr) bytes from offset ip6hdr_off, and checked that it read that many bytes. If input_size was small enough to fail the check here then the iov_to_buf() would have reported a short read * In the last iteration, we update full_hdr_len at the end of the loop, and then exit the loop without checking that that final extension header had a valid length Moving the length check to the end of the loop fixes this. This bug has no visible effects provided that all the callers validate accessses into the packet before doing them, but spotting the invalid headers at this level provides a defence in depth against bugs elsewhere; so it's cc'd to stable on that basis. Bugs #4138 and #4516 both note this mistake (in amongst a pile of other things). Cc: qemu-stable@nongnu.org Fixes: eb700029c78367 ("net_pkt: Extend packet abstraction as required by e= 1000e functionality") Signed-off-by: Peter Maydell --- net/eth.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/net/eth.c b/net/eth.c index 12ec316e240..bc26d38dc21 100644 --- a/net/eth.c +++ b/net/eth.c @@ -485,10 +485,6 @@ bool eth_parse_ipv6_hdr(const struct iovec *pkt, int p= kt_frags, info->has_ext_hdrs =3D true; =20 do { - if (input_size < ip6hdr_off + info->full_hdr_len) { - return false; - } - bytes_read =3D iov_to_buf(pkt, pkt_frags, ip6hdr_off + info->full_= hdr_len, &ext_hdr, sizeof(ext_hdr)); =20 @@ -514,6 +510,10 @@ bool eth_parse_ipv6_hdr(const struct iovec *pkt, int p= kt_frags, =20 info->full_hdr_len +=3D (ext_hdr.ip6r_len + 1) * IP6_EXT_GRANULARI= TY; curr_ext_hdr_type =3D ext_hdr.ip6r_nxt; + if (input_size < ip6hdr_off + info->full_hdr_len) { + /* This extension header's length field was bogus */ + return false; + } } while (eth_is_ip6_extension_header_type(curr_ext_hdr_type)); =20 info->l4proto =3D ext_hdr.ip6r_nxt; --=20 2.43.0 From nobody Mon Nov 23 04:26:37 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1793650750; cv=none; d=zohomail.com; s=zohoarc; b=liR1Hxt8/W5HgZrSxDlXGQciLPPHKQboACS/5VviP8u0X3WAjq5+XzhwBN27UpGCo69HYSLfIzAYxPFhEzwwF7Wzd4lC1aSKM4U2wkcUPwmLN6cXCF69bTlOY0FEfhcF+5q2p6KCH6h2mixbX5AXULajILhuGSZi1FcD7aq8VNY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793650750; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=vgCxVsbf3vC1/m6/qXQZLnDeOO+thIG1wJU6PgFSPWc=; b=TLMG3afPfEmzq8kSeRPi9gc4Ycpcmb8y+wpQa5O3WEMlUUKjy2lq4PiWZxZ7f2ITPQyrAH3u678iBeDrt49ZqjuKmJipDc8162CjfYsILcYNQ/Vmk5NFeCI8IDuyqAPfo5CR7pOdIlaSf2VlCvEjp1v0ACmoyneT4uHLWOLL9jw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793650750418467.46365238314877; Mon, 2 Nov 2026 12:19:10 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xNyUV-0006zX-EY; Mon, 02 Nov 2026 15:18:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xNyUI-0006yp-0A for qemu-devel@nongnu.org; Mon, 02 Nov 2026 15:18:38 -0500 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xNyUG-0006iQ-BX for qemu-devel@nongnu.org; Mon, 02 Nov 2026 15:18:37 -0500 Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-48e04773687so1036379f8f.2 for ; Mon, 02 Nov 2026 12:18:35 -0800 (PST) Received: from lanath.. (wildly.archaic.org.uk. [81.2.115.145]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e71b79059sm22152836f8f.30.2026.11.02.12.18.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2026 12:18:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1793650715; x=1794255515; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=vgCxVsbf3vC1/m6/qXQZLnDeOO+thIG1wJU6PgFSPWc=; b=C5zw9qc48BCI5kv5C+WwGaz/RMividM2kv/4PqkNaUBvhtNvB0C6jfk5RAZUUSsE1t PETxNoMI1P2/7Ztz6ZIIL3vGaMmMVOEVT3fGtYuegUW2IdZX7di4gLAoJRziJfKyf9y6 HowpA3uj1qfgbALb7Jnw242vSwkTvSznPtXmgi3oY1nhmro/slYbULxCZX6AJ85uWb3o wAqmumFgE6MMN+D8ibwZUM6t5brcvhrhCptTNYKHEjOiOFis/RPrvarAzPLN6SjfslVJ FG+X/q06+VZKTlDmqn0UxRF0jVIEF08zh4e8g7esMqFyeXLhFae2eABq3ay0omdFa9KQ L16w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793650715; x=1794255515; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=vgCxVsbf3vC1/m6/qXQZLnDeOO+thIG1wJU6PgFSPWc=; b=AbgSl1yHYmjGjgbTNPVeYELOvFFpiistcqv75XxpzlpWuISfKzRLC5spidLMb6XdIJ id15R2kD0eeIgcjwvGfCztCwe0jXvR0/lcy6ndCaBllFEd3QyQ4YqygUEfE6KBb1eCQy JRvbeXVsXqesB9RMbKZdtxD5Abtp9sH/+r2cd39ReKBNYZVOww246IezbmILyDGoEUq2 90naTkULZ4JmrGac36q817gMvA3zrN85bHagi456D2hHgtJuIpJ99DLa4NmWarD27U+0 FS/EgdyIqnNo0kYwJzWgJeWJHxtjUligOZBmxM6zoosSV3hR7z5RDS6T+GcAkB5zr8U3 zYLQ== X-Gm-Message-State: APuU4Z9lqmKcSvmsvuRRy3j4JLSzo5A17UbZ3sY3GnipHDq2z147M0YZ TLed6WDPhWQeBjuiOo59PJZxzacNEnr1UTZQWOgJZkKKHcWaGa9+ccn94S9cSuhDEWCxdFdyVk9 /5VUa8mw= X-Gm-Gg: AYBFou1fqJ5lXIA42VFqi4o0yXPi/Wh5oRXp1cmqP76IKMJ1yQdNNq8g/ak4h23zZH/ 4Lc94UfwLR8ERTAlTZ6kTryVeq+9lCdNeSbjVbe6aDapVKuJTfZWX+cnc+jCbO0p9Raoq4kDZK5 2kzaMdX4nGzIqWr7qDlgebfKZtS+7GXaSGY/BuixRmBWliOhKL5QaWf85yoi55oRn3yevowhbkw gvozz08KgK+Pyt7R1xwMAhBF08cm7omS8DzFxZfqUXuXPNs6AwUg1rPq0syGcGXQ8m87MlPXFu+ TJnC4rB9zH2h3Lv7fWHFPnzHcGPU5v81AVeELl7kam8mZpSgFol5xvJKNFrFR5WY2OGRai/2a+h WbguBx1aX7WSHwLtRtD+GZr8mH2MjaE5CcOl11H9V2lEY9Pqdueitz354MRzEhxtuVqSoGPYVDW Mpc1GcHH5ktXssrgbHnG8Zm/YFOVxQT4JlFXW/K/TkLV+M8UU/4pfC5Hlp8HCBa/7xnm5uswRQI 2V7BArQaABWbow3KtozuWPQ1kwMpvDBjD9UliFbKjQyFd1e2gbAnAHROKTcXWu6sbn4vh2YACLW L0oQQirEdup1b8/HvWpM63/RMwj2TsVHxCLBhY3FqOYkbETVIKBtJsQtefehSb40FfKDohnBtjR W5eQZ93kgRouIxFIDtmC++q2gUAognzczrQ== X-Received: by 2002:a05:6000:1603:b0:48d:f36e:ccc0 with SMTP id ffacd0b85a97d-48e6e262c42mr17940850f8f.0.1793650714856; Mon, 02 Nov 2026 12:18:34 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Jason Wang , Akihiko Odaki , Dmitry Fleytman Subject: [PATCH 03/11] net/eth.c: In eth_get_protocols(), don't report SCTP header off end of packet Date: Mon, 2 Nov 2026 20:18:20 +0000 Message-ID: <20261102201828.1879576-4-peter.maydell@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261102201828.1879576-1-peter.maydell@linaro.org> References: <20261102201828.1879576-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::434; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x434.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1793650752836158500 Content-Type: text/plain; charset="utf-8" eth_get_protocols() parses an ethernet packet and tells the caller about various offsets into it and other properties of the packet. For the L4 protocol, in both the IP_PROTO_TCP and IP_PROTO_UDP branches we implicitly check that the packet does contain a whole TCP or UDP header at the l4hdr_off offset, because _eth_copy_chunk() will fail if the input packet size isn't big enough for the whole header we are copying out of it. But for IP_PROTO_SCTP we don't copy the SCTP common header. In this case we should still do the length check, so we don't set l4hdr_info->proto to say there's an SCTP header present when there isn't. This shouldn't have any visible effects if the downstream consumers of the l4hdr_info are conservative about checking before they access into the packet, but checking here too adds defence in depth, hence the cc to stable. Cc: qemu-stable@nongnu.org Fixes: 907209e311 ("igb: Implement Rx SCTP CSO") Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/net/eth.h | 2 ++ net/eth.c | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/net/eth.h b/include/net/eth.h index 46dc9ed5acd..e10684ed923 100644 --- a/include/net/eth.h +++ b/include/net/eth.h @@ -394,6 +394,8 @@ typedef struct eth_l4_hdr_info_st { bool has_tcp_data; } eth_l4_hdr_info; =20 +#define SCTP_COMMON_HEADER_LEN 12 + void eth_get_protocols(const struct iovec *iov, size_t iovcnt, size_t iovo= ff, bool *hasip4, bool *hasip6, size_t *l3hdr_off, diff --git a/net/eth.c b/net/eth.c index bc26d38dc21..341d3bdf02b 100644 --- a/net/eth.c +++ b/net/eth.c @@ -213,7 +213,14 @@ void eth_get_protocols(const struct iovec *iov, size_t= iovcnt, size_t iovoff, break; =20 case IP_PROTO_SCTP: - l4hdr_info->proto =3D ETH_L4_HDR_PROTO_SCTP; + /* + * We don't copy the SCTP common header into l4hdr_info, but + * don't report SCTP as present if the packet isn't big enough + * to actually have an SCTP header. + */ + if (*l4hdr_off > input_size - SCTP_COMMON_HEADER_LEN) { + l4hdr_info->proto =3D ETH_L4_HDR_PROTO_SCTP; + } break; } } --=20 2.43.0 From nobody Mon Nov 23 04:26:37 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1793650819; cv=none; d=zohomail.com; s=zohoarc; b=lBqRox/hzMzbggWXq1d2/BMpu1C4i64bdMLfZ56AGru8D/2EihRUhNjecltT2S/TRQk3MMB6F6FIAOEvXDP5wXSvTJzmVDvN0Ak3A5gD4lbY/VHaSpJoLzFiDii9hNpoAfRmMACdpPeE1zOnRQjPYKLwqdzFowXaSycl66+KUVs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793650819; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ddMCYprMt6aDlaXCHhKy0OvuoupRq5tVuiWJqagyFAU=; b=ETedVCPtxqaVMusXHRAuST5G3DlJDuv4RkVeTyjlGvpYdyPW91EhAVRhRFyEFW+ktsodCPf7yE6nLEIvNCF8Meq3RmeGrLvEeG+IbFftsFKdm8QvqkYfmlKx5fiuB/1vVVBn4nRnWgKfeEFZghPHljn/ddH3jV84VK40pc4tfTQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793650819721424.6896063997966; Mon, 2 Nov 2026 12:20:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xNyUs-00076V-7d; Mon, 02 Nov 2026 15:19:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xNyUJ-0006yz-Es for qemu-devel@nongnu.org; Mon, 02 Nov 2026 15:18:39 -0500 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xNyUH-0006id-CO for qemu-devel@nongnu.org; Mon, 02 Nov 2026 15:18:38 -0500 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-48b001cd92bso1857745f8f.2 for ; Mon, 02 Nov 2026 12:18:37 -0800 (PST) Received: from lanath.. (wildly.archaic.org.uk. [81.2.115.145]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e71b79059sm22152836f8f.30.2026.11.02.12.18.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2026 12:18:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1793650716; x=1794255516; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=ddMCYprMt6aDlaXCHhKy0OvuoupRq5tVuiWJqagyFAU=; b=YDNOKmfFGb4NIaTbE/44IctQt6f4PZP+Rg96J5T6ZTzd9y6Ihk/cS+Q3J03GvOTYYL jYNrz+cFLCtNL2DHcQetnVmhQ+hfKfsD2E+87OYM7ASF1vb4LwFebB318rZTLx5RNZT9 av4Ax+Y6NNpOdXHNNFNAPQbUjIt7aTjR8SwxBRGKwyeJshx6GP3K96I/6WKQy5w4PFBw oYv5TEPi37/SkRzQPg7POmCuSG7QkveZ2MS79VQBKnM5NLE9VwGNc+S7U9mJUt0+WzUn hQg4KpsRZBT1X4nW249swX0b70n5wumStqQ6BZNyG1ixomuF0VFJxcBUSjQZg66qWV63 qWeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793650716; x=1794255516; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=ddMCYprMt6aDlaXCHhKy0OvuoupRq5tVuiWJqagyFAU=; b=dAUDF3318qktCHLuQe/4tPfJ+kizFN21LppqULXxjQoACI3IWiXA4xYkfiMVpYk5uh ALb/WJJ5ISZd/bvWKWwZQv8sgN63z2hOq39227kYI2nhgQdbTAHn8WuH6xZJE7ew6JG+ IY/+dG8HUHl1o5bjdHQ9zWFz3UR9GK8objmvfcTeFAxn9uJiupysaq0gq5J4JVRRgtVk e7+UL1LfSbIqu/PCl5533jVs6Y23U1jnVZFFrvNKghk5tfsi7KXyDXF1O/FG2NM1Soyc UuAO+iw6OmWTkF1GPUSopWY+Ye2W3P8H7v8lJpe7kfgoRj+Y98yzMdacvzSu5tVFemz2 Xk8w== X-Gm-Message-State: APuU4Z97jjKK8mwIgUrSkeAsDJLKZckDI4EHkwZ6tYl/iUCLn0jT36Hx GQMGIvpQLCJgMYFhifbisYKX5Ut1x51LZSlgWhJafFLyR0D2zC2yQdOljOkC89eqSCIp1tHYW9M 6hc5BsGI= X-Gm-Gg: AYBFou2dG21B/QWTQ2TiOIjFh9yOR9SpNsnNBAkIDuWK1hCvh3FACkVBib2QNmxmzr9 hXAnvNrEV4LhUaNU22Jc1jw4cqo8HEi72mK8e7BanaLhYcZ38/Tj09mrmmdNYcwjZ8M1cB4QQG3 LpBaePyi5GWKF5VBeBNEDyRetEKqjERZD26lRUWafO9T2KSsw5jll0OjzVi8A4OOtRH4svq5JvN i7JuPkVxFotsKRem/8+DD/4FJ4HgCcA4qwbfDHqt7pHxxi2wf6MZI6O9147Nqhtym2oAjzC34ac LZhUs/+ARdXcFdLZzQC8WWXtjxc9dpW0vTa4VYWnry2Ss6bwXQP20qRz0AIMr1kM1n83UYdXmdD PC1IDqfYfSUQHap1ldFqA6x7H6LpPNXf4sElq42+YFlkpbqjm9oxV6Rv3GjWZRlh09coWFmTcD2 O7EP5K0rug90l5vyMsbdj0sFtwnTUzaLTLvkW09AXisJISdSVLQdCRpci/hc9i+WdBvWQBkYwAm xtBsrcuOY5WYM68bPmmFRogyQ4Ngq+X8Au0depd1v5YlHv8fqBB8R223dr2PvW3RfWwIYJxuzki 2ynDjJGtrGe+3+YgERd3LXTZRONG8Ui6thsHMkoIHN1XuWj5l10q0uUfPhctn/5L+vYy9Q+RXov pU3rkmaUXBPfGeQL8mnU40M89amIr7MRQOA== X-Received: by 2002:a05:6000:2997:10b0:48e:5e63:bd23 with SMTP id ffacd0b85a97d-48e6e2ef96fmr18510820f8f.30.1793650715797; Mon, 02 Nov 2026 12:18:35 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Jason Wang , Akihiko Odaki , Dmitry Fleytman Subject: [PATCH 04/11] net/eth.c: Check for undersized IPv4 headers in eth_get_protocols() Date: Mon, 2 Nov 2026 20:18:21 +0000 Message-ID: <20261102201828.1879576-5-peter.maydell@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261102201828.1879576-1-peter.maydell@linaro.org> References: <20261102201828.1879576-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::430; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x430.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1793650822152158500 Content-Type: text/plain; charset="utf-8" In the IPv6 path of eth_get_protocols(), eth_parse_ipv6_hdr() does various sanity checks on the packet's IPv6 header, so we won't tell the caller we have an IPv6 header when we have a malformed one. However for IPv4 we only check the version and that we have at least the minimum header size. Harden this codepath by checking also that the header size declared in the packet's own headers is neither smaller than the minimum nor larger than the actual packet size. Missing these checks shouldn't cause problems if the caller is validating all offsets and lengths before use, but checking here too is defence-in-depth, hence the cc to stable. Cc: qemu-stable@nongnu.org Fixes: 69ff5ef847457555 ("net/eth: Report if headers are actually present") Signed-off-by: Peter Maydell --- net/eth.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/eth.c b/net/eth.c index 341d3bdf02b..e2c1e08ed28 100644 --- a/net/eth.c +++ b/net/eth.c @@ -156,6 +156,8 @@ void eth_get_protocols(const struct iovec *iov, size_t = iovcnt, size_t iovoff, =20 copied =3D iov_to_buf(iov, iovcnt, *l3hdr_off, iphdr, sizeof(*iphd= r)); if (copied < sizeof(*iphdr) || + IP_HDR_GET_LEN(iphdr) < sizeof(*iphdr) || + input_size - *l3hdr_off < IP_HDR_GET_LEN(iphdr) || IP_HEADER_VERSION(iphdr) !=3D IP_HEADER_VERSION_4) { return; } --=20 2.43.0 From nobody Mon Nov 23 04:26:37 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1793650878; cv=none; d=zohomail.com; s=zohoarc; b=iGubXTEg6lgfDLuqQzNpZ3nFm7bw+6YyLaeyWkBrPkm+LaRi0pD0KWnMnHGuonjD3jDccJBMXCZ2Rrm0hxW8C1jkvZmqVziYxgY+Ufra0BnqCrc5vLb3HgRfGOJNXznccWMb/Sanu6a0JyF3zl1PlKxMD9Y3MyZw8OBk9titsOs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793650878; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=MSHn6yE/T+6ZdS+CvwhmLlPfnMRXY7q3UBT+geptnSA=; b=gEaOEdFVGE5JTU8h/gpppi0Ndmj2r/s//b/xgPWwCUHcGNFnrusVKtZAu0Gku5rvQjxvt7RFRSD9AKMir/AH1TmiN10p4IG8LOOHHDGFzv/eIEbD3GsRrt8XKAMlT1n9vshaRnNmGV2+BNFrBdn72qRKm+R8J3FELXhezrMWjXM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 179365087811339.85397522175401; Mon, 2 Nov 2026 12:21:18 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xNyWe-00007j-84; Mon, 02 Nov 2026 15:21:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xNyUK-0006zD-LD for qemu-devel@nongnu.org; Mon, 02 Nov 2026 15:18:42 -0500 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xNyUI-0006il-Dv for qemu-devel@nongnu.org; Mon, 02 Nov 2026 15:18:40 -0500 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-4a5087a5348so27851795e9.0 for ; Mon, 02 Nov 2026 12:18:38 -0800 (PST) Received: from lanath.. (wildly.archaic.org.uk. [81.2.115.145]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e71b79059sm22152836f8f.30.2026.11.02.12.18.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2026 12:18:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1793650717; x=1794255517; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=MSHn6yE/T+6ZdS+CvwhmLlPfnMRXY7q3UBT+geptnSA=; b=RGtYLXNJxIP25idUOW4AOZ9sp6ixFpSHO9/y7956TtuTsgYAYsYWSfxf4J9ZiZ5mB1 NfIXPT3jYwAX+woKmfaH8HiqBCSRf+qHqYJGX2xO2X2567/Rso9UgYbp1Wx3ZUmjtJ0f Zj/I0xG5SDnFqylFZga+C561PxUiLbU+UZGr9KPfOJB257spw5JBAK/DVsiDNbgi0ll3 DECzraC8KDtQwiZ8ljh4TMRHnXTPjOHDtWQsMdla6fwYvgRxsvV9dCPKvdYi5jYAxMzZ G3yuzq+tHF8wZUS2O7l4yJvdYG43ZTLq9MxA6V4hnT4KdZO4NRfROD/rMkufUIk6i1h2 mj/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793650717; x=1794255517; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=MSHn6yE/T+6ZdS+CvwhmLlPfnMRXY7q3UBT+geptnSA=; b=XcXlIHHhoOFt+UEp8MNYKancCUiwjcDD5vk6pytonVtxhFCAQqtxtSW7MrVwwAp5KD WywrzOq3xmJU2+5MoJbdkktzZLAWTxoB0H36axVIdiBgtQ0DB8YOx8OLL3mdvBtZrjqg +YIq6BAuHkJzC2f4EzswdrmQSgd2n/oEE2zUeby2H/uvly1fA8ClkcQPo0qZFfhVG0T/ IypGcqHFyZQgmzHnO+c/rYpUrA/EF9u96KUYX36vtA7tZU7LjMtOdwrql5pp74BRn5uM Uzmg6iT44e0FV0jvh4lWVq6r1aYcqk4c2ncMJKN/IPHdmXHpzUxN7R0G3jI99VeN6kJW 7YvA== X-Gm-Message-State: APuU4Z8wW+a29n6RvNMDyprMZkIRJ+5vUtfEiztw4ZlMOrq8g+2b3FOT x33Hjux15h3MQZ9kNWTPE40A8JAU0RlcIK1rLdZ9wWEWHg7Cz5N9QeFltftM7Q8A/bERhMXmnMR /TIFULy0= X-Gm-Gg: AYBFou1evveCD5sscCmc1/9F3IFBaNype+iw9bAy58YzkgdFCumi1dZ8057m1aPymoq H2xYMr8HZrBhII5BgZ13oCYwtT4Pj5Fu0ft6FHhKw+xlTI0nJpDErUtOBjA1Vc6QW8EFcxQSwEd j+dbwhAETaVg/BriHBdargtfGMi30aQ7KThOs1caqqKMUEE1izA4EIlyzgUDbIQGLJzmWaGvKY+ NFxaneyhSycablYlh+INuox5+nDuTX3IMTbV2dh0c0YaQ5sKMyGbMlFAfogmkFQSVT0hbSZjmSb kOlrDD3DKIeae9Be2p9M5FGG0/Yb5UK4LmWJq3Latj94c80kezHUOVzwkG+ceCZ3AvRNfEOw8lv 8OMbRkp9ePiGNBxX1OfnHavyxO7jUnZlGWwEsp849LlaKBJOCnVQCH7ny1fa7jP2kJnI3S3Ycwn 8i8cvsJUnDGVoeOBO/CI4g4sJKKHfd81iTNmcTfdw4ZvI/VOjiz7bcmqtNegwjfUh5lhcr5eRF+ TDUnxLKCBbWpQbsIBRcORG1nyWYye+gSRLQoxfu7LroSMVvFeZowMd2SLbwUHZr3E/K9+gSPEB0 YcVwhBNZDUkluHjAPB5bjFqdLJpgS2xkXM2QC0wZ8y4UzsnG85/JMoONw6ejQ1ZBPQDUmUCJAQr AIQYgYwC641g8HLETReNvhX+qsLjdIKNqFQ== X-Received: by 2002:a5d:5f07:0:b0:48c:7caa:12cd with SMTP id ffacd0b85a97d-48e6e4faddbmr25942077f8f.22.1793650716689; Mon, 02 Nov 2026 12:18:36 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Jason Wang , Akihiko Odaki , Dmitry Fleytman Subject: [PATCH 05/11] net/eth.c: Harden _eth_tcp_has_data() against short lengths Date: Mon, 2 Nov 2026 20:18:22 +0000 Message-ID: <20261102201828.1879576-6-peter.maydell@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261102201828.1879576-1-peter.maydell@linaro.org> References: <20261102201828.1879576-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::332; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x332.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1793650879656154100 Content-Type: text/plain; charset="utf-8" In _eth_tcp_has_data() we calculate the length of the rest of the packet after the ipv4 header by subtracting the header offset from the packet length. If this subtraction underflows we'll return the wrong answer. This shouldn't cause any problems if other layers of the code are checking lengths and offsets, but defence-in-depth suggests doing a checked-subtraction and returning "has no data" if the subtraction underflows. Cc: qemu-stable@nongnu.org Fixes: eb700029c783 ("net_pkt: Extend packet abstraction as required by e10= 00e functionality") Signed-off-by: Peter Maydell --- net/eth.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/net/eth.c b/net/eth.c index e2c1e08ed28..955f2bff5e6 100644 --- a/net/eth.c +++ b/net/eth.c @@ -117,10 +117,20 @@ _eth_tcp_has_data(bool is_ip4, uint32_t l4len; =20 if (is_ip4) { - l4len =3D be16_to_cpu(ip4_hdr->ip_len) - IP_HDR_GET_LEN(ip4_hdr); + if (usub32_overflow(be16_to_cpu(ip4_hdr->ip_len), + IP_HDR_GET_LEN(ip4_hdr), &l4len)) { + /* packet too short for claimed IP header: no data */ + return false; + } } else { size_t opts_len =3D full_ip6hdr_len - sizeof(struct ip6_header); - l4len =3D be16_to_cpu(ip6_hdr->ip6_ctlun.ip6_un1.ip6_un1_plen) - o= pts_len; + uint64_t l4len_64; + if (usub64_overflow(be16_to_cpu(ip6_hdr->ip6_ctlun.ip6_un1.ip6_un1= _plen), + opts_len, &l4len_64)) { + /* packet too short for claimed IP header: no data */ + return false; + } + l4len =3D l4len_64; } =20 return l4len > TCP_HEADER_DATA_OFFSET(tcp); --=20 2.43.0 From nobody Mon Nov 23 04:26:37 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1793650768; cv=none; d=zohomail.com; s=zohoarc; b=G4zUM11HSXm+eUX+CYjUienM9ATl5xBQM02NrheqV5ZS8ARu6IZAjRp+UGb2/9jbxVT676pYF6IcN9JdP+w8J/ETbtvdGbnl24iBaDTszdaGpJ6BJgzR2vdbXXy6anallk9i5Teflo6S1DFAQx+hqRa+G1cyQ5xrVaJn8vKUgAU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793650768; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=zYP3UuQpxXa0Gmc41CzZ5nRNzgygyc8mQxZJvr2++LM=; b=gnVzCLot55gqAZ7VG73Iw9EsojXOi2EcG1yJa4GwMnFpoVT3rbUKoCKfpBPsuA2EJJhn39WWKyOyWBJ1qDnfCt83Yxmw+HbYmjhXMvKj+Isj2bSIke7BAXHZAstDE5nf+7eHJ1f1ht7Y1ztHGqugrTh0CJYZjjIV6nr7mtokOoI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793650768965737.2922233967837; Mon, 2 Nov 2026 12:19:28 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xNyUp-00075i-6B; Mon, 02 Nov 2026 15:19:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xNyUK-0006zE-Vx for qemu-devel@nongnu.org; Mon, 02 Nov 2026 15:18:42 -0500 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xNyUJ-0006ix-9H for qemu-devel@nongnu.org; Mon, 02 Nov 2026 15:18:40 -0500 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-4a5087a5348so27851895e9.0 for ; Mon, 02 Nov 2026 12:18:38 -0800 (PST) Received: from lanath.. (wildly.archaic.org.uk. [81.2.115.145]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e71b79059sm22152836f8f.30.2026.11.02.12.18.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2026 12:18:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1793650717; x=1794255517; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=zYP3UuQpxXa0Gmc41CzZ5nRNzgygyc8mQxZJvr2++LM=; b=HKzfpi1QCXq4smK2Jmd3knbZVKXTpfJuYhqkuMuTJ6DHoT6yMA89ThmScRgbKJo/7m o+Z3vIJMtUA/wety8f9FZUefXfZAKZhteZZ2Zj/zRmHwXL6ySCO+/na7c7cDNCSmPSz7 O8inIPmGyJQbr4+Bm9Xr0nRvygoH50bskmoAUDCU4U90z3HEr3Hjobn7JT509v1xFuOO NnNb/g7JtRF2JSd1ghTVSq9tfVeSvl3pgs4o2YHHEAj9IUNk5JKmd5PKNh/CK3a5IcnE OJvgLl5IT+StiL3qHPd7x+cuT5OwmbYmUwpbuqpg+MSBWDPeFe1VwWagAFCFoS/3o3w3 6Hbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793650717; x=1794255517; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=zYP3UuQpxXa0Gmc41CzZ5nRNzgygyc8mQxZJvr2++LM=; b=AfMA9tBtPi0QXkKuWbQC6snZgFGP6Bh1TWdiDyQ9IX6gb7l5Kf5U13nSVvR6DoTIoc Aw70BW98mviUDq8SEQ7Ly/JcSmL+B4CLSNO4T5x71AMsiwZN47mSEUhNV+oZiQ0L+1PR Q/7iZmFGbQg6v2BRMJ/fzKFhc1zEIvyGhuliuyzXrTWaXeT+5Ok8WkXuaVx3R4D/LXz2 Ip7kllwqoWML29wQs97qC2leTZ9vFzd0f7FuwX7hr2K0L6CXsE6MhprWb6UX2J+zfS0U UboM6bP6sf0zkAwiOFQvJwc1uDM3ZlnHzt/0D4UJ9DtxcIS+KOaCKDQfIWHnyfZK9Iit 3JIw== X-Gm-Message-State: AFq9FYIXajRSYHW5+G4ZyQflrQe8zECn1ruCLQ+cA3hW3oQSL/OzIJuI fFxsr9yXsRLVVH/bzggqM0PorznAmUJZrOJPq3/TdtEb0kVSwuPGW6ZpWC3/CJpY3kudqM3Xhcd 5FHNJgs8= X-Gm-Gg: AYBFou3at4kjDV9FaBqhu3K50l5uDEElP4wZwvjvxE8ArOGbFLn91/QkILZoe2Uj3hp vrImudB39DX3s1gkGnZBw9SCFz41lJtDBaNL4nlxxqiHIefnAwUHwTpPU2G4OT3IwnmInvixCIm dC5vnbXDwNHJMOw7Az5pDBo3o/m2gOnpvq4JIJ5V5fblxAwDUw1RbJLjSP9NqSgNlRzb4Fr4Sle pko1H7oNQxyJj7WAI+6dz4y9DPLCbqpCtKHkJGZkytjTxfdt6+xoEAu5YsIWM1S4D12Z6DRcvfq wOLObaIXt94H9Dnk4Hl9pnmPvfsNSWtEkquf5QENqk3SwgXBYxKVvXiGPDykiZ0WNLYCQSTLzhr pLhrTB5rZd8WTHtF3xhVLL1NK0Xfxdj8HKCl2WChxx0uWTRqYvFcQM5TaYPmIc9mqG2r8mw5g1U EXGVGt/zAcL8mYoWyAOYOmG1hQcbLuvg93G+c0vMSncSMODmlLijHDc+wzeD0+ukwhi8qf5ZR5e p1np01KQsvOI+yBf3rRXL2Z8QYK4gbKw1MS1KzF7J1Cttk1vFymQsOGtQDyewqG26mXtlLIlljt LXUCoUAlWqg0iCypohjrDt7m9Vx5WJWQdpzmbXRV+eagHTFqS1krSQuvP4vJAa/79ylIJZ6+qfG V/1gwjUqmtEL8bpAwQf4dSwRbOKJGvMaoYmcmjZZW8Q15yDI26T3UqKNr X-Received: by 2002:a05:600c:34cf:b0:4a1:dbdf:17a8 with SMTP id 5b1f17b1804b1-4ac150b3d01mr267974405e9.2.1793650717665; Mon, 02 Nov 2026 12:18:37 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Jason Wang , Akihiko Odaki , Dmitry Fleytman Subject: [PATCH 06/11] net/eth.c: Tighten size checks in eth_get_l3_proto() Date: Mon, 2 Nov 2026 20:18:23 +0000 Message-ID: <20261102201828.1879576-7-peter.maydell@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261102201828.1879576-1-peter.maydell@linaro.org> References: <20261102201828.1879576-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::334; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x334.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1793650772182154100 Content-Type: text/plain; charset="utf-8" Currently eth_get_l3_proto() has a check that the offset of the protocol field is not off the end of the iovec; this is actually unnecessary because iov_to_buf() guarantees to return 0 for offsets off the end of the iovec. On the other hand, it assumes that the l2hdr_len it is passed is not so small that the protocol offset calculation underflows and it doesn't check that the packet is actually big enough for the l2hdr_len. This shouldn't matter if other parts of the code are checking, but for defence in depth we tighten this check. Cc: qemu-stable@nongnu.org Fixes: eb700029c783 ("net_pkt: Extend packet abstraction as required by e10= 00e functionality") Signed-off-by: Peter Maydell --- net/eth.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/net/eth.c b/net/eth.c index 955f2bff5e6..d9113da58eb 100644 --- a/net/eth.c +++ b/net/eth.c @@ -74,11 +74,13 @@ eth_get_l3_proto(const struct iovec *l2hdr_iov, int iov= cnt, size_t l2hdr_len) uint16_t proto; size_t copied; size_t size =3D iov_size(l2hdr_iov, iovcnt); - size_t proto_offset =3D l2hdr_len - sizeof(proto); + size_t proto_offset; =20 - if (size < proto_offset) { + if (l2hdr_len < sizeof(struct eth_header) || size < l2hdr_len) { + /* We don't have a complete ethernet header */ return ETH_P_UNKNOWN; } + proto_offset =3D l2hdr_len - sizeof(proto); =20 copied =3D iov_to_buf(l2hdr_iov, iovcnt, proto_offset, &proto, sizeof(proto)); --=20 2.43.0 From nobody Mon Nov 23 04:26:37 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1793650866; cv=none; d=zohomail.com; s=zohoarc; b=l2kdndK+LSfi57N25MK1sz2CzoROlezBQ7SNR6kATOG5siuTXCq0M84/HVmnkEx5TY0X5i9oZ/CJKdp/O/x9xS2Xx4cPfWMXdwZocOqzi1Y1SdwU+xkGCinQGM9uThaJkzjGie99jZ+OtCwaC0IkbykRCMcImi6qawxwsmT3G+A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793650866; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=XJkZEXMXimgf/73tqNpqC4zidCU8t1qFKIc2RadN57c=; b=k/K0KSs6mfCsO6Xr6erv+NITsm+rycSgh+4ap419lpoZ9BfKj9AoU/8sNt1ehPG+Imgo0txrQLuztHJ6w5Uxd45v6HSUyaLOnw0Q/whcwGIR3YtoDxhQWPSE+CnbrmVcLq5Zk/oIbaKzOt4F9HpbUTr6kcNx2X0gs8U8qF9LRN0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793650866230424.72501173454714; Mon, 2 Nov 2026 12:21:06 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xNyWR-0008D2-Mz; Mon, 02 Nov 2026 15:20:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xNyUL-0006zL-Q7 for qemu-devel@nongnu.org; Mon, 02 Nov 2026 15:18:42 -0500 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xNyUK-0006j3-8R for qemu-devel@nongnu.org; Mon, 02 Nov 2026 15:18:41 -0500 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-48c4be28b82so3662285f8f.2 for ; Mon, 02 Nov 2026 12:18:39 -0800 (PST) Received: from lanath.. (wildly.archaic.org.uk. [81.2.115.145]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e71b79059sm22152836f8f.30.2026.11.02.12.18.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2026 12:18:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1793650719; x=1794255519; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=XJkZEXMXimgf/73tqNpqC4zidCU8t1qFKIc2RadN57c=; b=waD2LJEBVc3RZAeu1NJRF3+YfQZnRTbyuD5gBR548utg9rqNIRCEQsEJtkllfkIEDa 1EG2WUmUffWJ9HLfAkBb2jw6wjlaJRf6AOKkhsoRZAQA+GDhxpFsng00CQsglsPFJ18A UJbVjhQ6uuWNwogSKDKF8UpE903ZIGoFqrtLTe6s9Lv3pb7D06wmSUdBVhSLj28xiuOQ M2zzw+KPyNM75nP0Ny65yw3j6HAHDWx37z5qocLDK+BnfSYzVXskBgK+xT4laVNYp/FY mQhHliHUHdxg+lLSinkP11oOJpNdHxBvyLhqlWvZT4iQ9jyn2aZ8A1CO18P0yw/0z/qn xqAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793650719; x=1794255519; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=XJkZEXMXimgf/73tqNpqC4zidCU8t1qFKIc2RadN57c=; b=E8LyLqFcD8BHpuiND+Un9ATFYoldLNBnOP8uD10usW6w/AgOgr0ST3Jc8WOlVr9ZvC w1zFQ3yNAM83AJJLRdckYqdlgGeYrCtCUxy1GD/qzpnNEeiblXhZBCAMEmcEMRB2iMhr p7tzLP8dQftM8Ce7NqyVx2t6TDQpXZiI5M/xu+Nn9cznwcEuppWPCatfcjA1zAo/Xun+ 59AdK5txdBMTr+mZYXM5XRSYKyN698TrOvLmXcKCfr7D5s1qoJe0z+mR4n4kO7W6CgD2 +TGvSVhithPHEa20xQ2DtP7/mkT+4RpgN66gDFBr/a/jRkQ6X4zKDmu8LzBmu1rGXQlk mQbw== X-Gm-Message-State: APuU4Z/I0Tqi61IL9TaLfVOpPpOFE2EZ69AI/1/yei2GRHjsCHz5ZEff bSK3mVY9RC+QeI7CNaQv7Nln5ziyWXzyujCvIwxOYuXxdXCSKNKtVXLvyLQlH++WomOGyQvcXID JKqwSuDE= X-Gm-Gg: AYBFou2ImIr44CxMpWDkXmZ1WDjwIwcbUC+9l1wtkVM3B+0iVwpfxGTUpxOBQePAcy8 fCgPIa15YV5HcFALDYN3NOyEhsqe3vyG8zTwY4fK45R8ITw1OROfTWgHHfSHvckwc5qJrbjkpjW vuDIqG24HoGe2CU3MwkiDkoO+SVJzwr6fEjvjUwPRRkH+XWwhq/SpTcbj728r0l9Tbr0Z8PIbCz EEDzeQu2Rd+dw/hIlisPqIqOIF9b1lDcdle8mQ3QbYapCZDj8RLJbCqWxzIy2SXvR/cNgCC9qPb khCVLEgDRTnTP8B+xi1LSEMfL74hb1Qfnjv5rZWqRTwbmNiitCIP30dWpMU80RBdSutBMqfvuGO 1GJzCLhGwioKzDyMIaQd6+bkxkmQhd4BhiSWcEGWdSPA3iWgF0U+hP+lqlrpAtHBvdMQ5XJ0HKB W1KFfkTNw+f5SUU4A++SObAdrSI5AvZrMIi4snSxrsB/Qtj1oKl2z9uw5TvpcZ2UGA32b0ZoYGk pBLXFHycMs1o7Xt4EDaoX8wxDvUJhKWYzbkM/yBULOvygEV74EwkUSJAWHvEiyRcFEYiyZYsJn3 teNfQQf4B8QzMB5EChsxqHV5l9byMFWU6fBNzRlJq7bvDKE22WhcbIjHQgCooZtp9fWcQhWDY4E PZX3uPxLZFb8Xc/RP0VEQwI/ZXGnH77YIAg== X-Received: by 2002:a05:6000:40cf:b0:48d:c29e:40c3 with SMTP id ffacd0b85a97d-48e6e5008f5mr26250387f8f.33.1793650718717; Mon, 02 Nov 2026 12:18:38 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Jason Wang , Akihiko Odaki , Dmitry Fleytman Subject: [PATCH 07/11] include/net/eth.h: Make eth_get_l2_hdr_length_iov() check protocol Date: Mon, 2 Nov 2026 20:18:24 +0000 Message-ID: <20261102201828.1879576-8-peter.maydell@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261102201828.1879576-1-peter.maydell@linaro.org> References: <20261102201828.1879576-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::433; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x433.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1793650867224158500 Content-Type: text/plain; charset="utf-8" In eth_get_l2_hdr_length() we return sizeof(eth_header) for any protocol other than VLAN or DVLAN. However, in the iov version of this function, if the packet is larger than the ethernet header but not large enough for both the eth_header and the vlan_header we'll end up returning the actual packet size rather than the eth_header size. Fix the "not enough data" return case. This will only cause issues if the caller isn't already checking offsets and sizes, so this is defence-in-depth. It also in theory corrects the result for the hypothetical case of an ethernet-level protocol that allows a payload of less than 4 bytes. Cc: qemu-stable@nongnu.org Fixes: eb700029c783 ("net_pkt: Extend packet abstraction as required by e10= 00e functionality") Signed-off-by: Peter Maydell --- include/net/eth.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/net/eth.h b/include/net/eth.h index e10684ed923..3e83f5d68c0 100644 --- a/include/net/eth.h +++ b/include/net/eth.h @@ -321,7 +321,7 @@ eth_get_l2_hdr_length_iov(const struct iovec *iov, size= _t iovcnt, size_t iovoff) size_t copied =3D iov_to_buf(iov, iovcnt, iovoff, p, ARRAY_SIZE(p)); =20 if (copied < ARRAY_SIZE(p)) { - return copied; + return MIN(copied, sizeof(struct eth_header)); } =20 return eth_get_l2_hdr_length(p); --=20 2.43.0 From nobody Mon Nov 23 04:26:37 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1793650831; cv=none; d=zohomail.com; s=zohoarc; b=ECvIVpE5E8y9qGwszHQjYwkUDvkvtWJXwJwPj4/YaVZMBVkfHN9LB0PEsgnT34WZnBFB2FGg1xTwsvm3ybSrrx5TQcIt0g50nH15564JsBJbr+yrzQwbuPzpgmHihuCpuxZcSp6NyR01yu3oauahn6QN4y55wJpuzR/l4E9sDgY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793650831; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=JQxHT8XwDw2zxgMzF7vQ8+X3vrqCs1RSuRYRRucS740=; b=AlsCeBbL+UP2YZj5AlRXchDYCFqqAeMk6QD1fho7aLTu8nkn0DsTopUmB770Cy+SsnCnABh65oAStBMbrEdiU782+Nkzhf0YcTvkcq7tOEzEUyBREkauwchLKjIWaQ4n+eJ3a0hPOGm2lrNM12DRsTjHFh4YyVCTDAbJ5DUBd8Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793650831022393.1384770347148; Mon, 2 Nov 2026 12:20:31 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xNyUs-00076a-81; Mon, 02 Nov 2026 15:19:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xNyUO-0006zq-Ap for qemu-devel@nongnu.org; Mon, 02 Nov 2026 15:18:51 -0500 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xNyUL-0006jN-Sw for qemu-devel@nongnu.org; Mon, 02 Nov 2026 15:18:43 -0500 Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-48afbd2c386so2013827f8f.3 for ; Mon, 02 Nov 2026 12:18:41 -0800 (PST) Received: from lanath.. (wildly.archaic.org.uk. [81.2.115.145]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e71b79059sm22152836f8f.30.2026.11.02.12.18.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2026 12:18:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1793650720; x=1794255520; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=JQxHT8XwDw2zxgMzF7vQ8+X3vrqCs1RSuRYRRucS740=; b=LoKfOwdImgK0/R95Hn2UXA+aVPuYdDJgJKv03C+yNz1ObzXdma+zGVws9eRNxeiFU3 sCViWcGSJ6A+ee0KK3oHZ76KTGTYt81hOohP3D6deh5T54vDBMlXHNNzaWQo9OalaEk3 FbhSJlBS8/ZYZzB/gIzijKV3G646INN1kkU+HeikcMLhEMqbElZKLgCN+AA92J8jRSo8 77SrEfuJiCd3gfQpXTWLTmPmRLop/B1Nv7e5IiqLqVDu1MEHHN5+K/3r58FB+RHQ3gg2 k6lfNFpYSDHX3SACyzZzQsgC4p9yhEeD5irWzf+H+G6HauKYwiWvCdPd08VwDBD8Iooz JVZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793650720; x=1794255520; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=JQxHT8XwDw2zxgMzF7vQ8+X3vrqCs1RSuRYRRucS740=; b=ID85xg1QaRBz/tiq/b9ULhhIJMImS+hbCUaQhAJtFfKod/x4ymRMf43T4S2DYsTzDT npTIIuJ0XGCQBNWF/xlWm6Z3p8MJkjRGuxTn7JNlj7H/Zsok1LuG3eXzt86q7K4KTmU/ Ufyg/o6fFA9S0f6WzTI4Okjb2tZV0MWG5anDoSwhkANQb17qTz1buNewWo0kL3+xF5r/ +1msU94t/t6fEGlpxiQBGtC559v1vbp4rz5M3KDkVVPB70efTffARcr/cZZoIhY4Uw4j tYtL3gz52cEOgDblsz6joR+uArQqRmH36fIwv95qtOv7T36F+Aa31b1zWT5mxeYUVuQ8 nd8w== X-Gm-Message-State: APuU4Z8fV0mtqJdxhrjgfbCI25p3vBnRQfk5KZ3Lyi+1spvAS3J/Ckjr ulEYWYDC7pDmWUtxssXoxbt+Trzz6hrWMAOO79EdCwa3IRfgdN1VGKyWha5jt/oEO1VFLbWrK3B wXaSYhyw= X-Gm-Gg: AYBFou0fnuM+8581fr9B36Taq0yWl04x2gORIX2mbBroUc0Q5og/l2rcgiWB1dT4966 TblFsAolIja8oac42V9BjIZnBqiVMaaUszS2FStB8s/rGUuftjxfit+OyE61u+U1wge/0raNwLw jteE0Y0r5j7GqpfN/Co5Ag8ZEco/NMP16KS52UPmFh7G/BsQG3PPDA1pNXrE23/+wPxUmqEqtd+ TTylHGFwq6CThvW2e6PaKPF+ciun+KIHq/4fPImeO/gWBdbcRGPBKA2UO3gMyGiCHTFtm+j9bV9 Z9JA3VVeyOcTihAqEEzDG/VLD5CP1AHqg2F9gABULgTJnPuDWtSrsSweUGONhZUURHtOorUqS4V QRVkI+6Wq5GYhYNztHULWlWL5/omCIfsQclXkohWrHmHU8Z702AoEjxnLG0WT8ITmi72ECwtOB/ ndScOn9PERpvgbQEdov+BABxRyKqWNKMnT73QeZRo4XxoYrGQoXBP/TN5QIXWURYX2WNw0vPq16 0ma05dAgkod8de1LIScPA3sZaxXj60DYiH03Md4TmZdak4rMz8Ac7Dguuy8xCcrRjujc0C9pgOe 4RpoKeLio3ojaALzOG5ar40Wsylxad7w+FyhW3xX0b7LbLqg0flGdSxPLUI/oMOKgkpq6DCTnSB 5PiqUquz3frj4PzZwIL+mRFByiWUFOr2j82kg2IEK6vrYL6jRJFdjJLg= X-Received: by 2002:a05:6000:1aca:b0:48c:7037:aee9 with SMTP id ffacd0b85a97d-48e6e4fcfacmr24701591f8f.50.1793650720456; Mon, 02 Nov 2026 12:18:40 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Jason Wang , Akihiko Odaki , Dmitry Fleytman Subject: [PATCH 08/11] hw/net/net_tx_pkt: Sanity check GSO headers in net_tx_pkt_build_vheader() Date: Mon, 2 Nov 2026 20:18:25 +0000 Message-ID: <20261102201828.1879576-9-peter.maydell@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261102201828.1879576-1-peter.maydell@linaro.org> References: <20261102201828.1879576-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x431.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1793650833155154100 Content-Type: text/plain; charset="utf-8" In net_tx_pkt_build_vheader(), we are insufficiently cautious about headers from the packet from the guest. Add more checking: * that the segment offload payload gso_size isn't 0 * that the packet is not too small * that the TCP th_off is inside the payload * that we aren't going to overflow in our header length calculation Of these, the most significant extra check is in calculation of the virt_hdr length. We calculate this with pkt->virt_hdr.hdr_len =3D pkt->hdr_len + l4hdr.th_off * sizeof(uint32_t); The struct field is 16 bits, and so this can overflow if the guest hands us a packet of close to 64K in size and an appropriate l4hdr.th_off. The effect is that we record a bogus virt_hdr.hdr_len, and later on in net_tx_pkt_tcp_fragment_init() this will cause us to make a very large allocation that causes g_malloc() to abort. This is a hardening issue rather than a security issue, because the amount of guest control over the allocation size is such that it can only generate allocations very close to SIZE_MAX which always make g_malloc() abort, and so it's a guest self-denial-of-service only. Cc: qemu-stable@nongnu.org Fixes: e263cd49c73c595 ("Packet abstraction for VMWARE network devices") Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3648 Signed-off-by: Peter Maydell --- hw/net/net_tx_pkt.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/hw/net/net_tx_pkt.c b/hw/net/net_tx_pkt.c index b134348fe80..b2935900fe7 100644 --- a/hw/net/net_tx_pkt.c +++ b/hw/net/net_tx_pkt.c @@ -335,6 +335,11 @@ bool net_tx_pkt_build_vheader(struct NetTxPkt *pkt, bo= ol tso_enable, break; =20 case VIRTIO_NET_HDR_GSO_UDP: + if (IP_FRAG_ALIGN_SIZE(gso_size) =3D=3D 0 || + pkt->payload_len < sizeof(struct udp_header) || + pkt->hdr_len + sizeof(struct udp_header) > UINT16_MAX) { + return false; + } pkt->virt_hdr.gso_size =3D gso_size; pkt->virt_hdr.hdr_len =3D pkt->hdr_len + sizeof(struct udp_header); break; @@ -344,7 +349,10 @@ bool net_tx_pkt_build_vheader(struct NetTxPkt *pkt, bo= ol tso_enable, bytes_read =3D iov_to_buf(&pkt->vec[NET_TX_PKT_PL_START_FRAG], pkt->payload_frags, 0, &l4hdr, sizeof(l4hd= r)); if (bytes_read < sizeof(l4hdr) || - l4hdr.th_off * sizeof(uint32_t) < sizeof(l4hdr)) { + gso_size =3D=3D 0 || + l4hdr.th_off * sizeof(uint32_t) < sizeof(l4hdr) || + l4hdr.th_off * sizeof(uint32_t) > pkt->payload_len || + pkt->hdr_len + l4hdr.th_off * sizeof(uint32_t) > UINT16_MAX) { return false; } =20 --=20 2.43.0 From nobody Mon Nov 23 04:26:37 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1793650852; cv=none; d=zohomail.com; s=zohoarc; b=ZsR/2x6sPZKn0wfx+ljH4XysrRQpn9nvgudjRXR5rav6vJbmHX6uZ83eqy88iOiURo1+Ux3F0JW7ja1evfkpLNieG4QjzOm25Arm6GLzvNxH0DLbR7V7qJVxzSbh+VTNE5FwABGI68q5B75/zFMZ+aejQZWSq11LSPgEbYUT5KU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793650852; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=+TA3F9sqKJS4JB0mwiT1BxsREsozO0IhCycBI0psi5I=; b=BqA6tL4h9kBCwlMHOKP6w8G7/NzVvDBf6PMyN6s1Fm0sb1qxCvVKFy5FrfFKhtdU7qV4s7iWRsoi9xb18ufjmeocfLNIqZI9j0/v97OuR/VJGuEnDpwH4zN1uiQBhG/np80YbThoeQqLI81l59oaApA5ZyP4WN2sC9vNJFbnRZU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793650852915595.7254335187565; Mon, 2 Nov 2026 12:20:52 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xNyVe-0007Wz-Li; Mon, 02 Nov 2026 15:20:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xNyUP-0006zs-L7 for qemu-devel@nongnu.org; Mon, 02 Nov 2026 15:18:51 -0500 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xNyUN-0006jW-VZ for qemu-devel@nongnu.org; Mon, 02 Nov 2026 15:18:45 -0500 Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-48af4d4e61fso2106365f8f.2 for ; Mon, 02 Nov 2026 12:18:42 -0800 (PST) Received: from lanath.. (wildly.archaic.org.uk. [81.2.115.145]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e71b79059sm22152836f8f.30.2026.11.02.12.18.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2026 12:18:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1793650721; x=1794255521; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=+TA3F9sqKJS4JB0mwiT1BxsREsozO0IhCycBI0psi5I=; b=XmObYXjIKHpsTGe4r/rIRHdB9RiKm+RmCaNGxNDwT77o1+HP3nlEF1/8bkVu28yrqV KDYzNYaV7OZ3TakMWSGRHqvqslCLWXGEB1HfjkH8x8n7mRNIG0MWqSM5RmCCpK191ab6 ylxDhapAzPsehKi1WgBKdTNMSMKHppDG9tEoQJvZQgxyt4QhvQfgBFRXJuI0g6DhhFC8 6gnjT6+sBfyHGVwJOQjIKnBrtC4nZXYrVzgOQdj8otyhzjiwrUD4Cb81OJorbVrtcx6M MQsUb/rEzRXyaV3VmRtLc6gIbFSW6iDndfb2iXVIxdXcfqZnkATAyX/KejNa8iQQ89eL ixUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793650721; x=1794255521; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=+TA3F9sqKJS4JB0mwiT1BxsREsozO0IhCycBI0psi5I=; b=naMWWH7q4Knnxq8gBn4e3tRN32ZIjE/5o5jpnIltdzFJDzKujoGq3KFllpFTFfXAMu 3YqRk683319YjLAjt6xDI+7mFXLZkrAMxBNyvukYHzHE6mMZ2rc9leDBL2Ylh/e56VP1 nQOLSLYRGDPJ7sTQVL+wToGi9U9hTsGrVgbb6nNVLlotk882dxiZf/MZX/P2EAK4hFL+ qgGfgtl7HcC4Z2lltiiQVjacZNfFEUxG0f8zYvEqMiq9vX/pualZXMjGyFLXkBY0WfWd 9A+nGwPwsklwcCzdPQEyvPhfjxSsdC3aWcs5s41bgyeuTpjEbvhe5es/CJr9tMX1I9bu Befg== X-Gm-Message-State: APuU4Z8Ol8fmbVHHvuG55o2nux6upHrPgJBB376L+IA+TD84Pd4740eA obt5/wTTR/G6vJ2J74oW2A2PgJH+oz915bjRT8/O1w6HiDQUyAIaoi/icQt1PjsXAe9L1fZlafu f6HJ1iE4= X-Gm-Gg: AYBFou2euYfhdjurxbE6aiUZaMR/S69e+JZqfhnO9DnIcIAW/ox+84Rm9XsfaWGCSO2 eyeYfetslQ4o4MrE/z3gH1YGdO+GriENnAubY/1A2NUWHk25g1XpgW/wMEN7rtWVw9cqOR8L2hE Qx2wMqRU1bUbnUbKld0oqGWsy9XQnUuDjAXEPvbeQ8kJsrb9MTjOlMXXBmfkrwFSNiZooESx797 sFPqvOOy1CbmDwJwGf8Yi7Ay4R/0vlbN1yR9u2/eDNtkBh8W1lk3LdMN1XpSYaPlxV6dEL/Jfhg GcVsvounhCMB8+/CcOL8Kw+ilgKcD6jJHMOq63tUX0CCSzET+MtSauvHhBMjMVymLPQYC5dOFg4 4oS7BSKFiDkad+m0MsTmvP7PT31v1jcD9wTFIXO51aYaA81B/NDBfLTCaRUcBOgqtP3iWDsWsV2 CGjKlswQk/JdMgYEzK0Fy4VWy0150ZBRf//pgB983RzC47kaxYfG47tkR5/b9dyVrtQX1aIUPvq yxkpBfGh5f1beJ96i5wzCmd00sdxa2kkDYs5c0OzdAS7KuMFkfvm1auPwn7mVHgLt6XS07EcHDB 8jmTsHoL3Mnh5Dm2Y7b9eOg2RzPBfDhbT66kigNM9n5gR4Ty8tN626RNqE/Gw0dp3/aO/2l4M6U pA1w3/lCYbiLkRH7lU5YILMlrXqGidnVQBw== X-Received: by 2002:a05:6000:71b:b0:48e:68d5:81b1 with SMTP id ffacd0b85a97d-48e6e4fcfbbmr23956890f8f.48.1793650721629; Mon, 02 Nov 2026 12:18:41 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Jason Wang , Akihiko Odaki , Dmitry Fleytman Subject: [PATCH 09/11] hw/net/net_tx_pkt: Sanity check virt hdr len in net_tx_tcp_fragment_init Date: Mon, 2 Nov 2026 20:18:26 +0000 Message-ID: <20261102201828.1879576-10-peter.maydell@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261102201828.1879576-1-peter.maydell@linaro.org> References: <20261102201828.1879576-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::429; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x429.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1793650855371154100 Content-Type: text/plain; charset="utf-8" In net_tx_pkt_tcp_fragment_init() we calculate the l4 header size by subtracting the packet's virt_hdr.hdr_len from its overall length, and then we g_malloc() that many bytes. This shouldn't underflow if the caller has been sanity checking sizes and offsets, but as defence-in-depth, check again here before relying on it for the malloc size. This change would suffice to avoid the guest self-denial-of-service via overflowing the virt_hdr.hdr_len calculation in net_tx_pkt_tcp_fragment_init() which we fixed in the preceding commit. Cc: qemu-stable@nongnu.org Fixes: 02ef5fdc092bd4 ("hw/net/net_tx_pkt: Implement TCP segmentation") Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3648 Signed-off-by: Peter Maydell --- hw/net/net_tx_pkt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/net/net_tx_pkt.c b/hw/net/net_tx_pkt.c index b2935900fe7..dc2563721e8 100644 --- a/hw/net/net_tx_pkt.c +++ b/hw/net/net_tx_pkt.c @@ -604,7 +604,7 @@ static bool net_tx_pkt_tcp_fragment_init(struct NetTxPk= t *pkt, size_t bytes_read =3D 0; struct tcp_hdr *th; =20 - if (!pkt->payload_frags) { + if (!pkt->payload_frags || pkt->virt_hdr.hdr_len <=3D pkt->hdr_len) { return false; } =20 --=20 2.43.0 From nobody Mon Nov 23 04:26:37 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1793650800; cv=none; d=zohomail.com; s=zohoarc; b=Yyb2Oxo5+t9q2ZF/3169HXISOO4AHificpbsDL2QT8B4DPgsI2OZuaf5iZZsvOTQBTjNntHuiX/wNkLXJDRLIdbHAG6sMuAiQ2xBgH/sO2VIESBOxLKj4Xh34UEfRJdLALPsmjwW3dAdZuVJKhWDgU1hkWd+asiQzRX+XrHY+Uc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793650800; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=SC1qHyVrmkpxv/nh5NA1V78Ni3DKw4xU1LOHUvCRN5E=; b=h+w+Ephxlkx2v/qARR+kwp6iozCbKXgRwGRVY91XzhgxzkvXVeHgSMA+S0hOipT12pEc3ayBC10OAnnpjLrZHuTVp7rEZ+P3KOlzFOoCPRyks4v18kyqgMgtIw/dTyiFQN9R3B4UFQbJOfF6NjGW14Ne5UFOfWqhPLxF8htgqT0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 179365080002421.091880291803818; Mon, 2 Nov 2026 12:20:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xNyVG-0007K2-R2; Mon, 02 Nov 2026 15:19:42 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xNyUP-0006zu-V6 for qemu-devel@nongnu.org; Mon, 02 Nov 2026 15:18:51 -0500 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xNyUO-0006jc-BE for qemu-devel@nongnu.org; Mon, 02 Nov 2026 15:18:45 -0500 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-48afbd2c386so2013845f8f.3 for ; Mon, 02 Nov 2026 12:18:43 -0800 (PST) Received: from lanath.. (wildly.archaic.org.uk. [81.2.115.145]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e71b79059sm22152836f8f.30.2026.11.02.12.18.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2026 12:18:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1793650723; x=1794255523; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=SC1qHyVrmkpxv/nh5NA1V78Ni3DKw4xU1LOHUvCRN5E=; b=RNphCN/DAOA5Bw2asc1hS1bNVkoJOgMr394NuBzBsYT3hFOUVPAXd5c4p6opAu/Ced rFoKrHlBmZyDOleLxctfvs9m1JNmcYMCF/Ba3wbeYiZek6zhhApw8WJy3L1wBgS8v1rF mezfSux/4myAvSVnZBSrBqf9kE9WQo+FoVbzbRlSDZd1fTZtnrq+LEzpKEA9njFhpGc0 IUqxiHEn0YCjF4OTeB6cvhF3tbBUhG//UtlnWXc35jh4Zf9WTgHFo0pBWgwCx/QLd0e0 clmzUc2zjzSxDHc1ER8Ki/fpDbX+yg4AH6YOp/rMccTv2G7k95KnwftUl27tKl0kyrUc w22Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793650723; x=1794255523; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=SC1qHyVrmkpxv/nh5NA1V78Ni3DKw4xU1LOHUvCRN5E=; b=WT25LsLs/HgXx8KiPWKTvh4KQQN2lcI3kFN6+0WJ9nNE5ZpFIVLLZvmIGa03344Byr aIGnhIIi5MXuBWodzTsEiM8K4l2A4XTr0UnM4HiY8JxjfVUBFdqEh80WrvhBj5q3Awgh DQI8xqzSSR9az3VLgn9kNBqp5kznWCzG6X2ZjI9i6qXAbxaJGAEPuHfnYoxMCYuG3be5 OeqcGX58T5HIf+YE/33x02iEtWH6+htMavPBgnyBCz6jXJmHSrTdfxZPOJ30r6IUM6wD JY4NQDii9CFjMiTWOt7C1SlSLuPQD+WWZO8JE1m1+8tJoJfcGoe/eXA2mcXYNHb77gRP Yp3w== X-Gm-Message-State: APuU4Z8kXdstcFtGWc+vQ8DYmymCJ+SqiceBLRT5ObMn7WhFHv86x++Z pF/MI5NeslIrauN/FIcKAip/IFkSw4hH945XTsIiFjkQCuTWuXPTDUclgH0SmlvcYI3x2vrVXLy hkZeDx94= X-Gm-Gg: AYBFou0w15GCH0ufBP/xCd4WslfzLHgZJ3FcUVHWg69aoWO5OJXkYPEam9BCE2/ioXK 7rnUiOP0h7zmyXPUncTUfLBsdVq+0WOtuBivvbrUGgUykZDk015bixzs12Tg9W/Ji4arq6pIlPy tLZTAddamjbAzbh6YJPFwmJQW9TGXd181g/rOkiXP7uvqZI+oSwc0xSO/gRXsVpY1ulxAg+c9Ai cvUtgy/xBCu6vH9sM9dCic2zr/MsMuZ6+WOrHkPRvWzYCgY8VwOL6b+GujTmCue2/CsYKI0/tHE pN21Yk9hoQxUJK2f4rvykS2kI2x/3noYKd1KrLK3FYWDU9r9HcDiPIGtuaKVMpG458KTYY/FVq8 yH7vdNdl8xVD7SY+vCqGrH2x552ZCkkm0cscp6diteeJbN8/7tKfIgYzZ+WRFaaeWfBek17OLFs VfT9HPbFMz52n9A/r8ZAOdTzlAu+5CLA/YjgBRhaVvUgtqzJ9ozAN9VhXYQEbM1zhtJGRdE93aM HMHwT5FTdx7JrnMEy5EtwlFCId44718o57Bq2f6P8DVIWE/6Nu6k5Rhmr56Cx310SmJTaaTo1Vt u8AE7eo28IW0FtqS+ZLabKNBb7dLz/9WYgEFaeu5SaVs73UW7UKJsn+BoGEVz9QU1VpNAEi/Piy 5WgANujmYlDLUA7p0FAQWJv1CGu7LmwLZsTjoJ6mMT/cORyeEJNPaTEM= X-Received: by 2002:a05:6000:2407:b0:48c:54c0:4cf3 with SMTP id ffacd0b85a97d-48e6e2ffc51mr26185603f8f.28.1793650722868; Mon, 02 Nov 2026 12:18:42 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Jason Wang , Akihiko Odaki , Dmitry Fleytman Subject: [PATCH 10/11] hw/net/net_tx_pkt: Sanity check L2+L3 header len in net_tx_pkt_parse_headers() Date: Mon, 2 Nov 2026 20:18:27 +0000 Message-ID: <20261102201828.1879576-11-peter.maydell@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261102201828.1879576-1-peter.maydell@linaro.org> References: <20261102201828.1879576-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1793650801920158500 Content-Type: text/plain; charset="utf-8" In net_tx_pkt_parse_headers() we examine the L2 and L3 headers one after the other. Add a sanity check that the two together don't exceed the packet length or the maximum IP packet size. This shouldn't happen if the L3 parsing was done right, but is worth doing for defence-in-depth. Cc: qemu-stable@nongnu.org Fixes: e263cd49c73c595 ("Packet abstraction for VMWARE network devices") Signed-off-by: Peter Maydell --- hw/net/net_tx_pkt.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/hw/net/net_tx_pkt.c b/hw/net/net_tx_pkt.c index dc2563721e8..c331628134e 100644 --- a/hw/net/net_tx_pkt.c +++ b/hw/net/net_tx_pkt.c @@ -267,6 +267,14 @@ static bool net_tx_pkt_parse_headers(struct NetTxPkt *= pkt) break; } =20 + if (l2_hdr->iov_len + l3_hdr->iov_len > ETH_MAX_IP_DGRAM_LEN || + l2_hdr->iov_len + l3_hdr->iov_len > + iov_size(pkt->raw, pkt->raw_frags)) { + l2_hdr->iov_len =3D 0; + l3_hdr->iov_len =3D 0; + return false; + } + net_tx_pkt_calculate_hdr_len(pkt); return true; } --=20 2.43.0 From nobody Mon Nov 23 04:26:37 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1793650882; cv=none; d=zohomail.com; s=zohoarc; b=LrdvxdyL2xalM2cSNP3HlKk78WkCVOE8QejMDzfsw5DQ4IwM4X6rNJaHohIJrq7pWUtvhpj2JVWKD7FfQ3etSToLmeGc4+tY/LO3K/nggsO1ff/c7dc2ZUIaV/KWKU3URPEy3G/Z/JgDI4O9fDkXE5qSOtXA/eyRxZC3hJtBmx0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793650882; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ESBM2k8065RGhx8nl7Bk7sbL5CPU/3J5jANQgKuufpU=; b=nTvo6o0dueODj66PyNBlGKaHcCoyD6QGYBNvZmPlcxVwcsoI8j8Km2u9JhX41ZFro4SSximrRQsXPs6vnB7ek60iiFicGG//qgDg5kUFTM0kjPmxM7bZhK8JdnOZSpOERB0gzpK/9tgZsABZe4H/krKCzv+F8npgPNtYNaTui9c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793650882266541.5091530499595; Mon, 2 Nov 2026 12:21:22 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xNyWr-0000cW-Se; Mon, 02 Nov 2026 15:21:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xNyUR-000703-AZ for qemu-devel@nongnu.org; Mon, 02 Nov 2026 15:18:51 -0500 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xNyUP-0006kG-GZ for qemu-devel@nongnu.org; Mon, 02 Nov 2026 15:18:46 -0500 Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-48b060ec084so2032287f8f.0 for ; Mon, 02 Nov 2026 12:18:45 -0800 (PST) Received: from lanath.. (wildly.archaic.org.uk. [81.2.115.145]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e71b79059sm22152836f8f.30.2026.11.02.12.18.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2026 12:18:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1793650724; x=1794255524; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=ESBM2k8065RGhx8nl7Bk7sbL5CPU/3J5jANQgKuufpU=; b=sbLsISTk41dDfpFkdFVTEpKtCseu59smAi80L1HpVef2XfHBaqtkot7bqOzqLWGd1A 9i5C2TW08wL9jatHLSl35Rs45ClsZoxVnBOHLyQBTRqckOa/NqNgyW05cVUUYzlhAO/n Lq9RyjHs8q16EbycfiQfbaJJ5Csju5IzV/2dLbX3DQCiO3hZnnaSV2XN/o2IUy7SiIHX 3JLA3RuMdqWKwmUF7I+lcAXYlRfdK+G/ZQ6ls6FRkPK6ga5kTA3sSTJ517/+E5oNATRV KCWgHAeHN5Tg+ZmILKJ11kzHJr8/9AUULm9iPetL5D+Ym8LKHCF6c7Sj9kd0yFNCR/Bf X27A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793650724; x=1794255524; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=ESBM2k8065RGhx8nl7Bk7sbL5CPU/3J5jANQgKuufpU=; b=nmIQpFatz7wL1m4quvPHV2FJ6EFVbZrdK6HCaFeF0/70VCJH5diTyDYZ752cyPghRx O1sNKJtUGMpEg+/+410YKpyBP/MRUVGuKH6ljNGezeM+2TBw6y899RFI7YYrbiLk7a2v MKAW6D7fUViM5KgjjIH7KbD7/C/LI2Vv0aF7r4skO9QiVp1G+hDBTIaZTZWeK1mz4wgl GX5sF5NzWmxcQkvGx3EZ3VJ+jySdpYgks2cV5BjoU3xNC9piF0LJfiwEOjvoxzIinSDJ +hOyfMX84Id9af2NpXPuP5YrAvtYbUcC9s8VkkmK11VxOX7gGrmdV96NhHox84pK6Euv ZB5g== X-Gm-Message-State: APuU4Z/gsN/OL/OV3LTB7S4EuIlbnkqgSZUQNIeXl7eu5x9/1uDcPlSF z9zphvpcivyQsMA3AzrqQVSLR6GQ+CMT28zvKcbU4GxTIsKjfeeJFgz0V01ZZDvDm/UirlNb4YK aME4eNP4= X-Gm-Gg: AYBFou0Ev9XOyJIg3iX2ZMgd41L5HbYM4Az6xenHmEGr/19OrF3Ln7oDrl39pRmC3c6 G26ZJpjVqBFpfxRIP4Ycwrc3QtYdrQuhzLBWZ97w7YwHHTKyKuFF4ROIYaVbEILh9ZjIy64qslE h2kpMydP8kpEk0xDXtQBWj+Bd++7dD9vzKsvXnnyGotPDZUOuR9JtWbHv5NH49HlunvOBIgfnMl 3ZtW95kCGS1XGh8k2lamp2ozpo+P0tYm48oZC7JXc9kNMPNL+mDB5qiU2Sbhycrg5kVHLRRXyKZ g0VRLsygk8bkEeqBd4lHo1BS1raM4c9yQZoBjpjY+6tSoRXuLeNoWn4zCtZveqS/KK/biLMwrdh wsAwqZ12gLkh4SSX+R9Y3FpNQS3JxYszEaZP/SeQX9QwK9r6UuPpzXzTCAqHZESUJSxrG/2C4R4 0LCX3cwNlSIAXaoezVhFYiFZfywVKRKLWCYv8Os2f4edcIE7J1oU6HiYgXaCkdHoAmxBhz6jBwA D1oLMWPkzS2agMbXgnSecqmaNIiJ7HQBeeSvyGb10wZIWR8kVZhA6S+1COMBBL8MHRKaWjxyQDE IvrBOhoHTqWcu3k4+FDtNXIEh0AYMViHFH7sVyOAAXFscqGXpFxHgDO4NoZioQKN0Z0WMuZFNbB PLB6269n9ZFawXrUvve9qtIW8RY7Ie5Mk7w== X-Received: by 2002:a05:6000:250a:b0:48d:b650:69aa with SMTP id ffacd0b85a97d-48e6e309fb9mr24441735f8f.50.1793650724181; Mon, 02 Nov 2026 12:18:44 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Jason Wang , Akihiko Odaki , Dmitry Fleytman Subject: [PATCH 11/11] hw/net/net_rx_pkt: Check for overflow in _net_rx_pkt_calc_l4_csum() Date: Mon, 2 Nov 2026 20:18:28 +0000 Message-ID: <20261102201828.1879576-12-peter.maydell@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261102201828.1879576-1-peter.maydell@linaro.org> References: <20261102201828.1879576-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::429; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x429.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1793650883694154100 Content-Type: text/plain; charset="utf-8" In _net_rx_pkt_calc_l4_csum() we calculate the number of bytes to run the checksum over by subtracting the IP header length from the total IP packet size. This shouldn't underflow if other parts of the code have been correctly checking and calculating sizes and offsets, but for defence in depth check here, and don't checksum any bytes if we would otherwise underflow. Cc: qemu-stable@nongnu.org Fixes: eb700029c783 ("net_pkt: Extend packet abstraction as required by e10= 00e functionality") Signed-off-by: Peter Maydell --- hw/net/net_rx_pkt.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/hw/net/net_rx_pkt.c b/hw/net/net_rx_pkt.c index 03a35f03154..110496e9c81 100644 --- a/hw/net/net_rx_pkt.c +++ b/hw/net/net_rx_pkt.c @@ -501,8 +501,10 @@ _net_rx_pkt_calc_l4_csum(struct NetRxPkt *pkt) csl =3D be16_to_cpu(pkt->l4hdr_info.hdr.udp.uh_ulen); trace_net_rx_pkt_l4_csum_calc_ip4_udp(); } else { - csl =3D be16_to_cpu(pkt->ip4hdr_info.ip4_hdr.ip_len) - - IP_HDR_GET_LEN(&pkt->ip4hdr_info.ip4_hdr); + uint16_t iplen =3D be16_to_cpu(pkt->ip4hdr_info.ip4_hdr.ip_len= ); + uint16_t iphdr_len =3D IP_HDR_GET_LEN(&pkt->ip4hdr_info.ip4_hd= r); + + csl =3D (iplen >=3D iphdr_len) ? (iplen - iphdr_len) : 0; trace_net_rx_pkt_l4_csum_calc_ip4_tcp(); } =20 @@ -517,9 +519,9 @@ _net_rx_pkt_calc_l4_csum(struct NetRxPkt *pkt) struct ip6_header *ip6hdr =3D &pkt->ip6hdr_info.ip6_hdr; size_t full_ip6hdr_len =3D pkt->l4hdr_off - pkt->l3hdr_off; size_t ip6opts_len =3D full_ip6hdr_len - sizeof(struct ip6_hea= der); + uint16_t plen =3D be16_to_cpu(ip6hdr->ip6_ctlun.ip6_un1.ip6_un= 1_plen); =20 - csl =3D be16_to_cpu(ip6hdr->ip6_ctlun.ip6_un1.ip6_un1_plen) - - ip6opts_len; + csl =3D (plen >=3D ip6opts_len) ? (plen - ip6opts_len) : 0; trace_net_rx_pkt_l4_csum_calc_ip6_tcp(); } =20 --=20 2.43.0