Skip to content

Commit cfe7702

Browse files
AtomicElectronCreatesFlorian Westphal
authored andcommitted
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: 2e4e6a1 ("[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>
1 parent d6d8cd2 commit cfe7702

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

net/netfilter/xt_dccp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ dccp_find_option(u_int8_t option,
6262
return true;
6363
}
6464

65-
if (op[i] < 2)
65+
if (op[i] < 2 || i == optlen - 1)
6666
i++;
6767
else
68-
i += op[i+1]?:1;
68+
i += op[i + 1] ? : 1;
6969
}
7070

7171
spin_unlock_bh(&dccp_buflock);

net/netfilter/xt_tcpudp.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,10 @@ tcp_find_option(u_int8_t option,
5959

6060
for (i = 0; i < optlen; ) {
6161
if (op[i] == option) return !invert;
62-
if (op[i] < 2) i++;
63-
else i += op[i+1]?:1;
62+
if (op[i] < 2 || i == optlen - 1)
63+
i++;
64+
else
65+
i += op[i + 1] ? : 1;
6466
}
6567

6668
return invert;

0 commit comments

Comments
 (0)