netfilter: x_tables: guard option walkers against 1-byte tail reads

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: 2e4e6a17af ("[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>
This commit is contained in:
David Dull
2026-03-07 20:26:21 +02:00
committed by Florian Westphal
parent d6d8cd2db2
commit cfe770220a
2 changed files with 6 additions and 4 deletions

View 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);

View 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;