Skip to content

Commit

Permalink
netfilter: complete validation of user input
Browse files Browse the repository at this point in the history
In my recent commit, I missed that do_replace() handlers
use copy_from_sockptr() (which I fixed), followed
by unsafe copy_from_sockptr_offset() calls.

In all functions, we can perform the @optlen validation
before even calling xt_alloc_table_info() with the following
check:

if ((u64)optlen < (u64)tmp.size + sizeof(tmp))
        return -EINVAL;

Fixes: 0c83842 ("netfilter: validate user input for expected length")
Reported-by: syzbot <syzkaller@googlegroups.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Pablo Neira Ayuso <pablo@netfilter.org>
Link: https://lore.kernel.org/r/20240409120741.3538135-1-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Eric Dumazet authored and kuba-moo committed Apr 11, 2024
1 parent 97e176f commit 65acf6e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions net/ipv4/netfilter/arp_tables.c
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,8 @@ static int do_replace(struct net *net, sockptr_t arg, unsigned int len)
return -ENOMEM;
if (tmp.num_counters == 0)
return -EINVAL;
if ((u64)len < (u64)tmp.size + sizeof(tmp))
return -EINVAL;

tmp.name[sizeof(tmp.name)-1] = 0;

Expand Down Expand Up @@ -1266,6 +1268,8 @@ static int compat_do_replace(struct net *net, sockptr_t arg, unsigned int len)
return -ENOMEM;
if (tmp.num_counters == 0)
return -EINVAL;
if ((u64)len < (u64)tmp.size + sizeof(tmp))
return -EINVAL;

tmp.name[sizeof(tmp.name)-1] = 0;

Expand Down
4 changes: 4 additions & 0 deletions net/ipv4/netfilter/ip_tables.c
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,8 @@ do_replace(struct net *net, sockptr_t arg, unsigned int len)
return -ENOMEM;
if (tmp.num_counters == 0)
return -EINVAL;
if ((u64)len < (u64)tmp.size + sizeof(tmp))
return -EINVAL;

tmp.name[sizeof(tmp.name)-1] = 0;

Expand Down Expand Up @@ -1504,6 +1506,8 @@ compat_do_replace(struct net *net, sockptr_t arg, unsigned int len)
return -ENOMEM;
if (tmp.num_counters == 0)
return -EINVAL;
if ((u64)len < (u64)tmp.size + sizeof(tmp))
return -EINVAL;

tmp.name[sizeof(tmp.name)-1] = 0;

Expand Down
4 changes: 4 additions & 0 deletions net/ipv6/netfilter/ip6_tables.c
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,8 @@ do_replace(struct net *net, sockptr_t arg, unsigned int len)
return -ENOMEM;
if (tmp.num_counters == 0)
return -EINVAL;
if ((u64)len < (u64)tmp.size + sizeof(tmp))
return -EINVAL;

tmp.name[sizeof(tmp.name)-1] = 0;

Expand Down Expand Up @@ -1513,6 +1515,8 @@ compat_do_replace(struct net *net, sockptr_t arg, unsigned int len)
return -ENOMEM;
if (tmp.num_counters == 0)
return -EINVAL;
if ((u64)len < (u64)tmp.size + sizeof(tmp))
return -EINVAL;

tmp.name[sizeof(tmp.name)-1] = 0;

Expand Down

0 comments on commit 65acf6e

Please sign in to comment.