diff mbox series

[net-next,v2,2/4] net: skb: check the boundrary of drop reason in kfree_skb_reason()

Message ID 20220512123313.218063-3-imagedong@tencent.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series net: skb: check the boundrary of skb drop reason | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 2 this patch: 2
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/build_clang success Errors and warnings before: 9 this patch: 9
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 2 this patch: 2
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 11 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Menglong Dong May 12, 2022, 12:33 p.m. UTC
From: Menglong Dong <imagedong@tencent.com>

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() and reset it
to NOT_SPECIFIED and print a warning with DEBUG_NET_WARN_ON_ONCE() if it
is invalid.

Signed-off-by: Menglong Dong <imagedong@tencent.com>
---
 net/core/skbuff.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Jakub Kicinski May 12, 2022, 4:15 p.m. UTC | #1
On Thu, 12 May 2022 20:33:11 +0800 menglong8.dong@gmail.com wrote:
> +	if (unlikely(reason <= 0 || reason >= SKB_DROP_REASON_MAX)) {
> +		DEBUG_NET_WARN_ON_ONCE(1);
> +		reason = SKB_DROP_REASON_NOT_SPECIFIED;
> +	}

With drop_monitor fixes sending an invalid reason to the tracepoint
should be a minor bug, right?

Can we just have a:

	DEBUG_NET_WARN_ON_ONCE(reason <= 0 || reason >= SKB_DROP_REASON_MAX);

and avoid having this branch on non-debug builds?
Eric Dumazet May 12, 2022, 4:16 p.m. UTC | #2
On Thu, May 12, 2022 at 9:16 AM Jakub Kicinski <kuba@kernel.org> wrote:
>
> On Thu, 12 May 2022 20:33:11 +0800 menglong8.dong@gmail.com wrote:
> > +     if (unlikely(reason <= 0 || reason >= SKB_DROP_REASON_MAX)) {
> > +             DEBUG_NET_WARN_ON_ONCE(1);
> > +             reason = SKB_DROP_REASON_NOT_SPECIFIED;
> > +     }
>
> With drop_monitor fixes sending an invalid reason to the tracepoint
> should be a minor bug, right?
>
> Can we just have a:
>
>         DEBUG_NET_WARN_ON_ONCE(reason <= 0 || reason >= SKB_DROP_REASON_MAX);
>
> and avoid having this branch on non-debug builds?

Exactly what I was going to say.
Menglong Dong May 13, 2022, 2:41 a.m. UTC | #3
On Fri, May 13, 2022 at 12:16 AM Jakub Kicinski <kuba@kernel.org> wrote:
>
> On Thu, 12 May 2022 20:33:11 +0800 menglong8.dong@gmail.com wrote:
> > +     if (unlikely(reason <= 0 || reason >= SKB_DROP_REASON_MAX)) {
> > +             DEBUG_NET_WARN_ON_ONCE(1);
> > +             reason = SKB_DROP_REASON_NOT_SPECIFIED;
> > +     }
>
> With drop_monitor fixes sending an invalid reason to the tracepoint
> should be a minor bug, right?
>
> Can we just have a:
>
>         DEBUG_NET_WARN_ON_ONCE(reason <= 0 || reason >= SKB_DROP_REASON_MAX);
>
> and avoid having this branch on non-debug builds?

Yeah, it seems this way is more logical. I'll change it in the V3.
diff mbox series

Patch

diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 15f7b6f99a8f..e49e43d4c34d 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -771,6 +771,11 @@  void kfree_skb_reason(struct sk_buff *skb, enum skb_drop_reason reason)
 	if (!skb_unref(skb))
 		return;
 
+	if (unlikely(reason <= 0 || reason >= SKB_DROP_REASON_MAX)) {
+		DEBUG_NET_WARN_ON_ONCE(1);
+		reason = SKB_DROP_REASON_NOT_SPECIFIED;
+	}
+
 	trace_kfree_skb(skb, __builtin_return_address(0), reason);
 	__kfree_skb(skb);
 }