Skip to contentSkip to conversation

xsk: Validate socket state in xsk_recvmsg, prior touching socket members

PATCH Applied Björn Töpel 3 participants 3 messages Dec 7, 2020 – Dec 8, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xsk: Validate socket state in xsk_recvmsg, prior touching socket members

From: Björn Töpel <[email protected]>

In AF_XDP the socket state needs to be checked, prior touching the members of the socket. This was not the case for the recvmsg implementation. Fix that by moving the xsk_is_bound() call.

Fixes 45a86681844e ("xsk: Add support for recvmsg()")
---
 net/xdp/xsk.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/xdp/xsk.c +2 -2
index 56c46e5f57bc..e28c6825e089 100644
@@ -554,12 +554,12 @@ static int xsk_recvmsg(struct socket *sock, struct msghdr *m, size_t len, int fl
 	struct sock *sk = sock->sk;
 	struct xdp_sock *xs = xdp_sk(sk);
 
+	if (unlikely(!xsk_is_bound(xs)))
+		return -ENXIO;
 	if (unlikely(!(xs->dev->flags & IFF_UP)))
 		return -ENETDOWN;
 	if (unlikely(!xs->rx))
 		return -ENOBUFS;
-	if (unlikely(!xsk_is_bound(xs)))
-		return -ENXIO;
 	if (unlikely(need_wait))
 		return -EOPNOTSUPP;
 

base-commit: 34da87213d3ddd26643aa83deff7ffc6463da0fc

Signature · 1 line
2.27.0
Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Björn Töpel

From: Björn Töpel <[email protected]>

In AF_XDP the socket state needs to be checked, prior touching the members of the socket. This was not the case for the recvmsg implementation. Fix that by moving the xsk_is_bound() call.

Quoted 6 lines
Fixes 45a86681844e ("xsk: Add support for recvmsg()")
---
 net/xdp/xsk.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 24 lines
net/xdp/xsk.c +2 -2
index 56c46e5f57bc..e28c6825e089 100644
@@ -554,12 +554,12 @@ static int xsk_recvmsg(struct socket *sock, struct msghdr *m, size_t len, int fl
        struct sock *sk = sock->sk;
        struct xdp_sock *xs = xdp_sk(sk);
 
+       if (unlikely(!xsk_is_bound(xs)))
+               return -ENXIO;
        if (unlikely(!(xs->dev->flags & IFF_UP)))
                return -ENETDOWN;
        if (unlikely(!xs->rx))
                return -ENOBUFS;
-       if (unlikely(!xsk_is_bound(xs)))
-               return -ENXIO;
        if (unlikely(need_wait))
                return -EOPNOTSUPP;
 

base-commit: 34da87213d3ddd26643aa83deff7ffc6463da0fc --
2.27.0

#2 lore raw
In reply to Björn Töpel
This patch was applied to bpf/bpf-next.git (refs/heads/master):

Hello:

This patch was applied to bpf/bpf-next.git (refs/heads/master):

Quoted 11 lines · On Mon, 7 Dec 2020 09:20:08 +0100 you wrote:

From: Björn Töpel <[email protected]>

In AF_XDP the socket state needs to be checked, prior touching the members of the socket. This was not the case for the recvmsg implementation. Fix that by moving the xsk_is_bound() call.

Fixes 45a86681844e ("xsk: Add support for recvmsg()")

[...]

Here is the summary with links:
- [bpf-next] xsk: Validate socket state in xsk_recvmsg, prior touching socket members

    https://git.kernel.org/bpf/bpf-next/c/3546b9b8eced

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html