]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
netfilter: x_tables: guard option walkers against 1-byte tail reads
authorDavid Dull <monderasdor@gmail.com>
Sat, 7 Mar 2026 18:26:21 +0000 (20:26 +0200)
committerFlorian Westphal <fw@strlen.de>
Tue, 10 Mar 2026 13:10:42 +0000 (14:10 +0100)
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 <monderasdor@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
net/netfilter/xt_dccp.c
net/netfilter/xt_tcpudp.c

index e5a13ecbe67a01e2ebe5be8b6f8300cdcde7a83c..037ab93e25d0afff2e643922ba98bbda9cb719ea 100644 (file)
@@ -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);
index e8991130a3de0cd87fd64949e70734c38ba52358..f76cf18f1a244599b54374f4585c6465807a8f7d 100644 (file)
@@ -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;