Skip to content

Commit

Permalink
net: add debug checks in napi_consume_skb and __napi_alloc_skb()
Browse files Browse the repository at this point in the history
Commit 6454eca ("net: Use lockdep_assert_in_softirq()
in napi_consume_skb()") added a check in napi_consume_skb()
which is a bit weak.

napi_consume_skb() and __napi_alloc_skb() should only
be used from BH context, not from hard irq or nmi context,
otherwise we could have races.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Eric Dumazet authored and kuba-moo committed Jun 10, 2022
1 parent 7890e2f commit ee2640d
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion net/core/skbuff.c
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ struct sk_buff *__napi_alloc_skb(struct napi_struct *napi, unsigned int len,
struct sk_buff *skb;
void *data;

DEBUG_NET_WARN_ON_ONCE(!in_softirq());
len += NET_SKB_PAD + NET_IP_ALIGN;

/* If requested length is either too small or too big,
Expand Down Expand Up @@ -981,7 +982,7 @@ void napi_consume_skb(struct sk_buff *skb, int budget)
return;
}

lockdep_assert_in_softirq();
DEBUG_NET_WARN_ON_ONCE(!in_softirq());

if (!skb_unref(skb))
return;
Expand Down

0 comments on commit ee2640d

Please sign in to comment.