Skip to content

Commit 2afd23f

Browse files
magnus-karlssonAlexei Starovoitov
authored andcommitted
xsk: Fix registration of Rx-only sockets
Having Rx-only AF_XDP sockets can potentially lead to a crash in the system by a NULL pointer dereference in xsk_umem_consume_tx(). This function iterates through a list of all sockets tied to a umem and checks if there are any packets to send on the Tx ring. Rx-only sockets do not have a Tx ring, so this will cause a NULL pointer dereference. This will happen if you have registered one or more Rx-only sockets to a umem and the driver is checking the Tx ring even on Rx, or if the XDP_SHARED_UMEM mode is used and there is a mix of Rx-only and other sockets tied to the same umem. Fixed by only putting sockets with a Tx component on the list that xsk_umem_consume_tx() iterates over. Fixes: ac98d8a ("xsk: wire upp Tx zero-copy functions") Reported-by: Kal Cutter Conley <[email protected]> Signed-off-by: Magnus Karlsson <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Acked-by: Jonathan Lemon <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 3b4d9eb commit 2afd23f

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

net/xdp/xdp_umem.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ void xdp_add_sk_umem(struct xdp_umem *umem, struct xdp_sock *xs)
2727
{
2828
unsigned long flags;
2929

30+
if (!xs->tx)
31+
return;
32+
3033
spin_lock_irqsave(&umem->xsk_list_lock, flags);
3134
list_add_rcu(&xs->list, &umem->xsk_list);
3235
spin_unlock_irqrestore(&umem->xsk_list_lock, flags);
@@ -36,6 +39,9 @@ void xdp_del_sk_umem(struct xdp_umem *umem, struct xdp_sock *xs)
3639
{
3740
unsigned long flags;
3841

42+
if (!xs->tx)
43+
return;
44+
3945
spin_lock_irqsave(&umem->xsk_list_lock, flags);
4046
list_del_rcu(&xs->list);
4147
spin_unlock_irqrestore(&umem->xsk_list_lock, flags);

0 commit comments

Comments
 (0)