[Devel] [PATCH RHEL9 COMMIT] net: skb: check the boundrary of drop reason in kfree_skb_reason()

Konstantin Khorenko khorenko at virtuozzo.com
Mon Jan 16 20:56:54 MSK 2023


The commit is pushed to "branch-rh9-5.14.0-162.6.1.vz9.18.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh9-5.14.0-162.6.1.vz9.18.2
------>
commit 139963820d564ff70963308a3ca50082e5b7bd89
Author: Menglong Dong <imagedong at tencent.com>
Date:   Tue Jan 3 17:39:42 2023 +0200

    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 <benbjiang at tencent.com>
    Reviewed-by: Hao Peng <flyingpeng at tencent.com>
    Signed-off-by: Menglong Dong <imagedong at tencent.com>
    Signed-off-by: David S. Miller <davem at davemloft.net>
    Acked-by: Nikolay Borisov <nborisov at suse.com>
    Signed-off-by: Nikolay Borisov <nikolay.borisov at virtuozzo.com>
    
    ======
    Patchset description:
    ms/net: Annotate skb free sites with reason
    
    This series backports most of the patches that add a reason to skb free sites.
    
    https://jira.sw.ru/browse/PSBM-143302
    
    Feature: net: improve verbosity of dropped packets reporting
---
 net/core/skbuff.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 9d45ad819ea7..2e067ec51ec6 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -774,6 +774,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);
 }


More information about the Devel mailing list