* [PATCH net-next] af_packet: avoid a false positive warning in packet_setsockopt()
@ 2024-04-05 11:49 Eric Dumazet
2024-04-05 15:34 ` Kees Cook
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Eric Dumazet @ 2024-04-05 11:49 UTC (permalink / raw)
To: David S . Miller, Jakub Kicinski, Paolo Abeni
Cc: netdev, eric.dumazet, Eric Dumazet, syzbot, Kees Cook,
Willem de Bruijn
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 <syzkaller@googlegroups.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
---
net/packet/af_packet.c | 26 ++++++++++++++------------
1 file changed, 14 insertions(+), 12 deletions(-)
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 18f616f487eaad0f7b31fb074e194c0479f30d77..8c6d3fbb4ed87f17c2e365810106a05fe9b8ff0c 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -3800,28 +3800,30 @@ packet_setsockopt(struct socket *sock, int level, int optname, sockptr_t optval,
case PACKET_TX_RING:
{
union tpacket_req_u req_u;
- int len;
+ ret = -EINVAL;
lock_sock(sk);
switch (po->tp_version) {
case TPACKET_V1:
case TPACKET_V2:
- len = sizeof(req_u.req);
+ if (optlen < sizeof(req_u.req))
+ break;
+ ret = copy_from_sockptr(&req_u.req, optval,
+ sizeof(req_u.req)) ?
+ -EINVAL : 0;
break;
case TPACKET_V3:
default:
- len = sizeof(req_u.req3);
+ if (optlen < sizeof(req_u.req3))
+ break;
+ ret = copy_from_sockptr(&req_u.req3, optval,
+ sizeof(req_u.req3)) ?
+ -EINVAL : 0;
break;
}
- if (optlen < len) {
- ret = -EINVAL;
- } else {
- if (copy_from_sockptr(&req_u.req, optval, len))
- ret = -EFAULT;
- else
- ret = packet_set_ring(sk, &req_u, 0,
- optname == PACKET_TX_RING);
- }
+ if (!ret)
+ ret = packet_set_ring(sk, &req_u, 0,
+ optname == PACKET_TX_RING);
release_sock(sk);
return ret;
}
--
2.44.0.478.gd926399ef9-goog
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH net-next] af_packet: avoid a false positive warning in packet_setsockopt()
2024-04-05 11:49 [PATCH net-next] af_packet: avoid a false positive warning in packet_setsockopt() Eric Dumazet
@ 2024-04-05 15:34 ` Kees Cook
2024-04-06 14:07 ` Willem de Bruijn
2024-04-08 12:21 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Kees Cook @ 2024-04-05 15:34 UTC (permalink / raw)
To: Eric Dumazet
Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, netdev,
eric.dumazet, syzbot, Willem de Bruijn
On Fri, Apr 05, 2024 at 11:49:39AM +0000, Eric Dumazet wrote:
> 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 <syzkaller@googlegroups.com>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
Looks good; thanks for making this more clear for the compiler. :)
Reviewed-by: Kees Cook <keescook@chromium.org>
--
Kees Cook
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net-next] af_packet: avoid a false positive warning in packet_setsockopt()
2024-04-05 11:49 [PATCH net-next] af_packet: avoid a false positive warning in packet_setsockopt() Eric Dumazet
2024-04-05 15:34 ` Kees Cook
@ 2024-04-06 14:07 ` Willem de Bruijn
2024-04-08 12:21 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Willem de Bruijn @ 2024-04-06 14:07 UTC (permalink / raw)
To: Eric Dumazet, David S . Miller, Jakub Kicinski, Paolo Abeni
Cc: netdev, eric.dumazet, Eric Dumazet, syzbot, Kees Cook,
Willem de Bruijn
Eric Dumazet wrote:
> 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 <syzkaller@googlegroups.com>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: Kees Cook <keescook@chromium.org>
> Cc: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Reviewed-by: Willem de Bruijn <willemb@google.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net-next] af_packet: avoid a false positive warning in packet_setsockopt()
2024-04-05 11:49 [PATCH net-next] af_packet: avoid a false positive warning in packet_setsockopt() Eric Dumazet
2024-04-05 15:34 ` Kees Cook
2024-04-06 14:07 ` Willem de Bruijn
@ 2024-04-08 12:21 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-04-08 12:21 UTC (permalink / raw)
To: Eric Dumazet
Cc: davem, kuba, pabeni, netdev, eric.dumazet, syzkaller, keescook,
willemdebruijn.kernel
Hello:
This patch was applied to netdev/net-next.git (main)
by David S. Miller <davem@davemloft.net>:
On Fri, 5 Apr 2024 11:49:39 +0000 you wrote:
> 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)
>
> [...]
Here is the summary with links:
- [net-next] af_packet: avoid a false positive warning in packet_setsockopt()
https://git.kernel.org/netdev/net-next/c/86d43e2bf93c
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-04-08 12:21 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-05 11:49 [PATCH net-next] af_packet: avoid a false positive warning in packet_setsockopt() Eric Dumazet
2024-04-05 15:34 ` Kees Cook
2024-04-06 14:07 ` Willem de Bruijn
2024-04-08 12:21 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).