mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-05 10:31:46 +09:00
netfilter: complete validation of user input
[ Upstream commit 65acf6e0501ac8880a4f73980d01b5d27648b956 ]
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: 0c83842df40f ("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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
9d42f37339
commit
c760089aa9
@@ -966,6 +966,8 @@ static int do_replace(struct net *net, sockptr_t arg, unsigned int len)
|
|||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
if (tmp.num_counters == 0)
|
if (tmp.num_counters == 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
if ((u64)len < (u64)tmp.size + sizeof(tmp))
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
tmp.name[sizeof(tmp.name)-1] = 0;
|
tmp.name[sizeof(tmp.name)-1] = 0;
|
||||||
|
|
||||||
@@ -1266,6 +1268,8 @@ static int compat_do_replace(struct net *net, sockptr_t arg, unsigned int len)
|
|||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
if (tmp.num_counters == 0)
|
if (tmp.num_counters == 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
if ((u64)len < (u64)tmp.size + sizeof(tmp))
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
tmp.name[sizeof(tmp.name)-1] = 0;
|
tmp.name[sizeof(tmp.name)-1] = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -1120,6 +1120,8 @@ do_replace(struct net *net, sockptr_t arg, unsigned int len)
|
|||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
if (tmp.num_counters == 0)
|
if (tmp.num_counters == 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
if ((u64)len < (u64)tmp.size + sizeof(tmp))
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
tmp.name[sizeof(tmp.name)-1] = 0;
|
tmp.name[sizeof(tmp.name)-1] = 0;
|
||||||
|
|
||||||
@@ -1506,6 +1508,8 @@ compat_do_replace(struct net *net, sockptr_t arg, unsigned int len)
|
|||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
if (tmp.num_counters == 0)
|
if (tmp.num_counters == 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
if ((u64)len < (u64)tmp.size + sizeof(tmp))
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
tmp.name[sizeof(tmp.name)-1] = 0;
|
tmp.name[sizeof(tmp.name)-1] = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -1137,6 +1137,8 @@ do_replace(struct net *net, sockptr_t arg, unsigned int len)
|
|||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
if (tmp.num_counters == 0)
|
if (tmp.num_counters == 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
if ((u64)len < (u64)tmp.size + sizeof(tmp))
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
tmp.name[sizeof(tmp.name)-1] = 0;
|
tmp.name[sizeof(tmp.name)-1] = 0;
|
||||||
|
|
||||||
@@ -1515,6 +1517,8 @@ compat_do_replace(struct net *net, sockptr_t arg, unsigned int len)
|
|||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
if (tmp.num_counters == 0)
|
if (tmp.num_counters == 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
if ((u64)len < (u64)tmp.size + sizeof(tmp))
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
tmp.name[sizeof(tmp.name)-1] = 0;
|
tmp.name[sizeof(tmp.name)-1] = 0;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user