From: Menglong Dong Date: Fri, 13 May 2022 03:03:37 +0000 (+0800) Subject: net: skb: check the boundrary of drop reason in kfree_skb_reason() X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=20bbcd0a94c6686c2692e6f7081163c233d7ce40;p=linux.git net: skb: check the boundrary of drop reason in kfree_skb_reason() Sometimes, we may forget to reset skb drop reason to NOT_SPECIFIED after we make it the return value of the functions with return type of enum skb_drop_reason, such as tcp_inbound_md5_hash. Therefore, its value can be SKB_NOT_DROPPED_YET(0), which is invalid for kfree_skb_reason(). So we check the range of drop reason in kfree_skb_reason() with DEBUG_NET_WARN_ON_ONCE(). Reviewed-by: Jiang Biao Reviewed-by: Hao Peng Signed-off-by: Menglong Dong Signed-off-by: David S. Miller --- diff --git a/net/core/skbuff.c b/net/core/skbuff.c index bd16e158b3668..2fea964f09d80 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -771,6 +771,8 @@ void kfree_skb_reason(struct sk_buff *skb, enum skb_drop_reason reason) if (!skb_unref(skb)) return; + DEBUG_NET_WARN_ON_ONCE(reason <= 0 || reason >= SKB_DROP_REASON_MAX); + trace_kfree_skb(skb, __builtin_return_address(0), reason); __kfree_skb(skb); }