public inbox for netfilter-devel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] netfilter: guard option walkers against 1-byte tail reads
@ 2026-03-07 18:26 David Dull
  2026-03-07 18:34 ` Florian Westphal
  2026-03-07 18:45 ` [PATCH v2] " David Dull
  0 siblings, 2 replies; 6+ messages in thread
From: David Dull @ 2026-03-07 18:26 UTC (permalink / raw)
  To: netfilter-devel; +Cc: fw, David Dull

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.

Cc: fw@strlen.de
Cc: stable@vger.kernel.org
Signed-off-by: David Dull <monderasdor@gmail.com>
---
 net/netfilter/xt_dccp.c   | 4 ++--
 net/netfilter/xt_tcpudp.c | 6 ++++--
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/net/netfilter/xt_dccp.c b/net/netfilter/xt_dccp.c
index e5a13ecbe6..037ab93e25 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 e8991130a3..f76cf18f1a 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.43.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-03-08 17:05 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-07 18:26 [PATCH] netfilter: guard option walkers against 1-byte tail reads David Dull
2026-03-07 18:34 ` Florian Westphal
2026-03-07 18:45 ` [PATCH v2] " David Dull
2026-03-08 11:11   ` Pablo Neira Ayuso
2026-03-08 15:52   ` [PATCH v3] " David Dull
2026-03-08 17:05     ` Pablo Neira Ayuso

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox