diff options
author | Björn Töpel <bjorn.topel@intel.com> | 2020-12-07 09:20:08 +0100 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2020-12-08 17:11:58 +0100 |
commit | 3546b9b8eced9799b35ef953f766a0973b17fda2 (patch) | |
tree | 7e54c3cfa6e6645d09938f6b368cc391597f2710 /net/xdp | |
parent | 2f4b03195fe8ed3b1e213f4a6cfe14cfc109d829 (diff) | |
download | linux-stable-3546b9b8eced9799b35ef953f766a0973b17fda2.tar.gz linux-stable-3546b9b8eced9799b35ef953f766a0973b17fda2.tar.bz2 linux-stable-3546b9b8eced9799b35ef953f766a0973b17fda2.zip |
xsk: Validate socket state in xsk_recvmsg, prior touching socket members
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()")
Reported-by: kernel test robot <oliver.sang@intel.com>
Signed-off-by: Björn Töpel <bjorn.topel@intel.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Magnus Karlsson <magnus.karlsson@intel.com>
Link: https://lore.kernel.org/bpf/20201207082008.132263-1-bjorn.topel@gmail.com
Diffstat (limited to 'net/xdp')
-rw-r--r-- | net/xdp/xsk.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c index 56c46e5f57bc..e28c6825e089 100644 --- a/net/xdp/xsk.c +++ b/net/xdp/xsk.c @@ -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; |