Skip to content

Commit 5c04da5

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: ebtables: reject bogus getopt len value
syzkaller reports splat: ------------[ cut here ]------------ Buffer overflow detected (80 < 137)! Call Trace: do_ebt_get_ctl+0x2b4/0x790 net/bridge/netfilter/ebtables.c:2317 nf_getsockopt+0x72/0xd0 net/netfilter/nf_sockopt.c:116 ip_getsockopt net/ipv4/ip_sockglue.c:1778 [inline] caused by a copy-to-user with a too-large "*len" value. This adds a argument check on *len just like in the non-compat version of the handler. Before the "Fixes" commit, the reproducer fails with -EINVAL as expected: 1. core calls the "compat" getsockopt version 2. compat getsockopt version detects the *len value is possibly in 64-bit layout (*len != compat_len) 3. compat getsockopt version delegates everything to native getsockopt version 4. native getsockopt rejects invalid *len -> compat handler only sees len == sizeof(compat_struct) for GET_ENTRIES. After the refactor, event sequence is: 1. getsockopt calls "compat" version (len != native_len) 2. compat version attempts to copy *len bytes, where *len is random value from userspace Fixes: fc66de8 ("netfilter/ebtables: clean up compat {get, set}sockopt handling") Reported-by: [email protected] Signed-off-by: Florian Westphal <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent d8bb9ab commit 5c04da5

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

net/bridge/netfilter/ebtables.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2238,6 +2238,10 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
22382238
struct ebt_table *t;
22392239
struct net *net = sock_net(sk);
22402240

2241+
if ((cmd == EBT_SO_GET_INFO || cmd == EBT_SO_GET_INIT_INFO) &&
2242+
*len != sizeof(struct compat_ebt_replace))
2243+
return -EINVAL;
2244+
22412245
if (copy_from_user(&tmp, user, sizeof(tmp)))
22422246
return -EFAULT;
22432247

0 commit comments

Comments
 (0)