diff options
author | Björn Töpel <bjorn.topel@intel.com> | 2019-09-04 07:49:11 -0400 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2019-09-05 08:11:52 -0400 |
commit | 9764f4b301c3e7eb3b75eec85b73cad449cdbb0d (patch) | |
tree | 31b08153807248a101bd3d1c5018c3d9b5fd45ab | |
parent | 94a997637c5b562fa0ca44fca1d2cd02ec08236f (diff) |
xsk: avoid store-tearing when assigning umem
The umem member of struct xdp_sock is read outside of the control
mutex, in the mmap implementation, and needs a WRITE_ONCE to avoid
potential store-tearing.
Acked-by: Jonathan Lemon <jonathan.lemon@gmail.com>
Fixes: 423f38329d26 ("xsk: add umem fill queue support and mmap")
Signed-off-by: Björn Töpel <bjorn.topel@intel.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
-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 271d8d3fb11e..8c9056f06989 100644 --- a/net/xdp/xsk.c +++ b/net/xdp/xsk.c | |||
@@ -644,7 +644,7 @@ static int xsk_bind(struct socket *sock, struct sockaddr *addr, int addr_len) | |||
644 | } | 644 | } |
645 | 645 | ||
646 | xdp_get_umem(umem_xs->umem); | 646 | xdp_get_umem(umem_xs->umem); |
647 | xs->umem = umem_xs->umem; | 647 | WRITE_ONCE(xs->umem, umem_xs->umem); |
648 | sockfd_put(sock); | 648 | sockfd_put(sock); |
649 | } else if (!xs->umem || !xdp_umem_validate_queues(xs->umem)) { | 649 | } else if (!xs->umem || !xdp_umem_validate_queues(xs->umem)) { |
650 | err = -EINVAL; | 650 | err = -EINVAL; |
@@ -751,7 +751,7 @@ static int xsk_setsockopt(struct socket *sock, int level, int optname, | |||
751 | 751 | ||
752 | /* Make sure umem is ready before it can be seen by others */ | 752 | /* Make sure umem is ready before it can be seen by others */ |
753 | smp_wmb(); | 753 | smp_wmb(); |
754 | xs->umem = umem; | 754 | WRITE_ONCE(xs->umem, umem); |
755 | mutex_unlock(&xs->mutex); | 755 | mutex_unlock(&xs->mutex); |
756 | return 0; | 756 | return 0; |
757 | } | 757 | } |