Skip to content

Commit fb7bc92

Browse files
tamirdkuba-moo
authored andcommitted
ipv6: raw: check passed optlen before reading
Add a check that the user-provided option is at least as long as the number of bytes we intend to read. Before this patch we would blindly read sizeof(int) bytes even in cases where the user passed optlen<sizeof(int), which would potentially read garbage or fault. Discovered by new tests in google/gvisor#6957 . The original get_user call predates history in the git repo. Signed-off-by: Tamir Duberstein <[email protected]> Signed-off-by: Willem de Bruijn <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 5bec7ca commit fb7bc92

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

net/ipv6/raw.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,9 @@ static int do_rawv6_setsockopt(struct sock *sk, int level, int optname,
10201020
struct raw6_sock *rp = raw6_sk(sk);
10211021
int val;
10221022

1023+
if (optlen < sizeof(val))
1024+
return -EINVAL;
1025+
10231026
if (copy_from_sockptr(&val, optval, sizeof(val)))
10241027
return -EFAULT;
10251028

0 commit comments

Comments
 (0)