Skip to content

Commit 61beb4c

Browse files
edumazetroxanan1996
authored andcommitted
af_packet: avoid a false positive warning in packet_setsockopt()
BugLink: https://bugs.launchpad.net/bugs/2073765 [ Upstream commit 86d43e2 ] Although the code is correct, the following line copy_from_sockptr(&req_u.req, optval, len)); triggers this warning : memcpy: detected field-spanning write (size 28) of single field "dst" at include/linux/sockptr.h:49 (size 16) Refactor the code to be more explicit. Reported-by: syzbot <[email protected]> Signed-off-by: Eric Dumazet <[email protected]> Cc: Kees Cook <[email protected]> Cc: Willem de Bruijn <[email protected]> Reviewed-by: Kees Cook <[email protected]> Reviewed-by: Willem de Bruijn <[email protected]> Signed-off-by: David S. Miller <[email protected]> Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Portia Stephens <[email protected]> Signed-off-by: Roxana Nicolescu <[email protected]>
1 parent fba0d4d commit 61beb4c

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

net/packet/af_packet.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3757,28 +3757,30 @@ packet_setsockopt(struct socket *sock, int level, int optname, sockptr_t optval,
37573757
case PACKET_TX_RING:
37583758
{
37593759
union tpacket_req_u req_u;
3760-
int len;
37613760

3761+
ret = -EINVAL;
37623762
lock_sock(sk);
37633763
switch (po->tp_version) {
37643764
case TPACKET_V1:
37653765
case TPACKET_V2:
3766-
len = sizeof(req_u.req);
3766+
if (optlen < sizeof(req_u.req))
3767+
break;
3768+
ret = copy_from_sockptr(&req_u.req, optval,
3769+
sizeof(req_u.req)) ?
3770+
-EINVAL : 0;
37673771
break;
37683772
case TPACKET_V3:
37693773
default:
3770-
len = sizeof(req_u.req3);
3774+
if (optlen < sizeof(req_u.req3))
3775+
break;
3776+
ret = copy_from_sockptr(&req_u.req3, optval,
3777+
sizeof(req_u.req3)) ?
3778+
-EINVAL : 0;
37713779
break;
37723780
}
3773-
if (optlen < len) {
3774-
ret = -EINVAL;
3775-
} else {
3776-
if (copy_from_sockptr(&req_u.req, optval, len))
3777-
ret = -EFAULT;
3778-
else
3779-
ret = packet_set_ring(sk, &req_u, 0,
3780-
optname == PACKET_TX_RING);
3781-
}
3781+
if (!ret)
3782+
ret = packet_set_ring(sk, &req_u, 0,
3783+
optname == PACKET_TX_RING);
37823784
release_sock(sk);
37833785
return ret;
37843786
}

0 commit comments

Comments
 (0)