From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7ACE53AE6EE; Mon, 23 Mar 2026 14:15:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774275341; cv=none; b=b2niGUkprDlOtaaBhTZAfkq0AKTU6/c5BUHIsTjR2CAc71CU0Pe11+vZE9a84qku8o4o/Wwgy2ooH46iCkjQzfGk6c6mp83/Q+5nnDy/Y7ImiUnKBmq1xWJ/8Zlom1Nnv2lFoCS9qNMHjVPyjVV5GLN8U0xEG3L30570aNcbhmE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774275341; c=relaxed/simple; bh=LoXjb8cYQSYLH01wRFN4n/6HMOLJg6REJ3qWVFX/PNw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AYKkQ9AYhAl0cxuSM+b+mVY0Mb/X3fhaR008GdqcL92A6bKo1lDvoV9fAR1ehkWDaF+iwAQ3m+B1f/q6N5wr282JFPdJQdNlcq27RET2qjJNz5UY+h5G185eh2fD/koUY+933zBKeDxlfMRYFL235P6J7G1gIRscJ/JucYI/+rw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=a5wKom56; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="a5wKom56" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0DC8DC4CEF7; Mon, 23 Mar 2026 14:15:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1774275341; bh=LoXjb8cYQSYLH01wRFN4n/6HMOLJg6REJ3qWVFX/PNw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a5wKom569D1HkyOxZP36FjMWYpAWofRJ887/vDf8M0El9saE4PLZ5FJpwTWSj5I73 BxxRfhA4gbLZ3yEjXHlJlpPaBt/R9/nO0AbktUj+gaa0nBak3O7KSPdr0KjJeXcDTi 6TwUN6XifOes43QDa+oCE2v2NPVV3k+OdM/ZR3GA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, David Dull , Florian Westphal , Sasha Levin Subject: [PATCH 6.12 064/460] netfilter: x_tables: guard option walkers against 1-byte tail reads Date: Mon, 23 Mar 2026 14:41:00 +0100 Message-ID: <20260323134528.281183349@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260323134526.647552166@linuxfoundation.org> References: <20260323134526.647552166@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: David Dull [ Upstream commit cfe770220ac2dbd3e104c6b45094037455da81d4 ] When the last byte of options is a non-single-byte option kind, walkers that advance with i += op[i + 1] ? : 1 can read op[i + 1] past the end of the option area. Add an explicit i == optlen - 1 check before dereferencing op[i + 1] in xt_tcpudp and xt_dccp option walkers. Fixes: 2e4e6a17af35 ("[NETFILTER] x_tables: Abstraction layer for {ip,ip6,arp}_tables") Signed-off-by: David Dull Signed-off-by: Florian Westphal Signed-off-by: Sasha Levin --- net/netfilter/xt_dccp.c | 4 ++-- net/netfilter/xt_tcpudp.c | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/net/netfilter/xt_dccp.c b/net/netfilter/xt_dccp.c index e5a13ecbe67a0..037ab93e25d0a 100644 --- a/net/netfilter/xt_dccp.c +++ b/net/netfilter/xt_dccp.c @@ -62,10 +62,10 @@ dccp_find_option(u_int8_t option, return true; } - if (op[i] < 2) + if (op[i] < 2 || i == optlen - 1) i++; else - i += op[i+1]?:1; + i += op[i + 1] ? : 1; } spin_unlock_bh(&dccp_buflock); diff --git a/net/netfilter/xt_tcpudp.c b/net/netfilter/xt_tcpudp.c index e8991130a3de0..f76cf18f1a244 100644 --- a/net/netfilter/xt_tcpudp.c +++ b/net/netfilter/xt_tcpudp.c @@ -59,8 +59,10 @@ tcp_find_option(u_int8_t option, for (i = 0; i < optlen; ) { if (op[i] == option) return !invert; - if (op[i] < 2) i++; - else i += op[i+1]?:1; + if (op[i] < 2 || i == optlen - 1) + i++; + else + i += op[i + 1] ? : 1; } return invert; -- 2.51.0