aboutsummaryrefslogtreecommitdiff
path: root/net/packet
diff options
context:
space:
mode:
authorAlexander Potapenko <glider@google.com>2017-04-25 18:51:46 +0200
committerMoyster <oysterized@gmail.com>2017-11-06 15:29:45 +0100
commitb1c8389f8bb6563ec2d8e518b17eeaec937c63fd (patch)
treec774486d966246775ca870e7f118e1ca36c82a14 /net/packet
parent03691822a5914225161bfffcea41349c281571c1 (diff)
net/packet: check length in getsockopt() called with PACKET_HDRLEN
commit fd2c83b35752f0a8236b976978ad4658df14a59f upstream. 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 <glider@google.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Willy Tarreau <w@1wt.eu>
Diffstat (limited to 'net/packet')
-rw-r--r--net/packet/af_packet.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 00a61d683..3ef5361a8 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -3364,6 +3364,8 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
case PACKET_HDRLEN:
if (len > sizeof(int))
len = sizeof(int);
+ if (len < sizeof(int))
+ return -EINVAL;
if (copy_from_user(&val, optval, len))
return -EFAULT;
switch (val) {