Skip to content

Commit

Permalink
xdp: fix possible cq entry leak
Browse files Browse the repository at this point in the history
Completion queue address reservation could not be undone.
In case of bad 'queue_id' or skb allocation failure, reserved entry
will be leaked reducing the total capacity of completion queue.

Fix that by moving reservation to the point where failure is not
possible. Additionally, 'queue_id' checking moved out from the loop
since there is no point to check it there.

Fixes: 35fcde7 ("xsk: support for Tx")
Signed-off-by: Ilya Maximets <[email protected]>
Acked-by: Björn Töpel <[email protected]>
Tested-by: William Tu <[email protected]>
Signed-off-by: Daniel Borkmann <[email protected]>
  • Loading branch information
igsilya authored and borkmann committed Jul 12, 2019
1 parent 36db2a9 commit 6757164
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions net/xdp/xsk.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ static int xsk_generic_xmit(struct sock *sk, struct msghdr *m,

mutex_lock(&xs->mutex);

if (xs->queue_id >= xs->dev->real_num_tx_queues)
goto out;

while (xskq_peek_desc(xs->tx, &desc)) {
char *buffer;
u64 addr;
Expand All @@ -250,12 +253,6 @@ static int xsk_generic_xmit(struct sock *sk, struct msghdr *m,
goto out;
}

if (xskq_reserve_addr(xs->umem->cq))
goto out;

if (xs->queue_id >= xs->dev->real_num_tx_queues)
goto out;

len = desc.len;
skb = sock_alloc_send_skb(sk, len, 1, &err);
if (unlikely(!skb)) {
Expand All @@ -267,7 +264,7 @@ static int xsk_generic_xmit(struct sock *sk, struct msghdr *m,
addr = desc.addr;
buffer = xdp_umem_get_data(xs->umem, addr);
err = skb_store_bits(skb, 0, buffer, len);
if (unlikely(err)) {
if (unlikely(err) || xskq_reserve_addr(xs->umem->cq)) {
kfree_skb(skb);
goto out;
}
Expand Down

0 comments on commit 6757164

Please sign in to comment.