Skip to content

Commit 9764f4b

Browse files
Björn Töpelborkmann
authored andcommitted
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: 423f383 ("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>
1 parent 94a9976 commit 9764f4b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

net/xdp/xsk.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ static int xsk_bind(struct socket *sock, struct sockaddr *addr, int addr_len)
644644
}
645645

646646
xdp_get_umem(umem_xs->umem);
647-
xs->umem = umem_xs->umem;
647+
WRITE_ONCE(xs->umem, umem_xs->umem);
648648
sockfd_put(sock);
649649
} else if (!xs->umem || !xdp_umem_validate_queues(xs->umem)) {
650650
err = -EINVAL;
@@ -751,7 +751,7 @@ static int xsk_setsockopt(struct socket *sock, int level, int optname,
751751

752752
/* Make sure umem is ready before it can be seen by others */
753753
smp_wmb();
754-
xs->umem = umem;
754+
WRITE_ONCE(xs->umem, umem);
755755
mutex_unlock(&xs->mutex);
756756
return 0;
757757
}

0 commit comments

Comments
 (0)