Skip to content

Commit fd2c83b

Browse files
ramosian-gliderdavem330
authored andcommitted
net/packet: check length in getsockopt() called with PACKET_HDRLEN
In the case getsockopt() is called with PACKET_HDRLEN and optlen < 4 |val| remains uninitialized and the syscall may behave differently depending on its value, and even copy garbage to userspace on certain architectures. To fix this we now return -EINVAL if optlen is too small. This bug has been detected with KMSAN. Signed-off-by: Alexander Potapenko <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 8048ced commit fd2c83b

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

net/packet/af_packet.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3836,6 +3836,8 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
38363836
case PACKET_HDRLEN:
38373837
if (len > sizeof(int))
38383838
len = sizeof(int);
3839+
if (len < sizeof(int))
3840+
return -EINVAL;
38393841
if (copy_from_user(&val, optval, len))
38403842
return -EFAULT;
38413843
switch (val) {

0 commit comments

Comments
 (0)