linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: menglong8.dong@gmail.com
To: kuba@kernel.org
Cc: nhorman@tuxdriver.com, davem@davemloft.net, edumazet@google.com,
	pabeni@redhat.com, yoshfuji@linux-ipv6.org, dsahern@kernel.org,
	imagedong@tencent.com, kafai@fb.com, talalahmad@google.com,
	keescook@chromium.org, asml.silence@gmail.com,
	willemb@google.com, vasily.averin@linux.dev,
	ilias.apalodimas@linaro.org, luiz.von.dentz@intel.com,
	linux-kernel@vger.kernel.org, netdev@vger.kernel.org
Subject: [PATCH net-next v2 2/4] net: skb: check the boundrary of drop reason in kfree_skb_reason()
Date: Thu, 12 May 2022 20:33:11 +0800	[thread overview]
Message-ID: <20220512123313.218063-3-imagedong@tencent.com> (raw)
In-Reply-To: <20220512123313.218063-1-imagedong@tencent.com>

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(+)

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);
 }
-- 
2.36.1


  parent reply	other threads:[~2022-05-12 12:34 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-12 12:33 [PATCH net-next v2 0/4] net: skb: check the boundrary of skb drop reason menglong8.dong
2022-05-12 12:33 ` [PATCH net-next v2 1/4] net: dm: check the boundary of skb drop reasons menglong8.dong
2022-05-12 12:33 ` menglong8.dong [this message]
2022-05-12 16:15   ` [PATCH net-next v2 2/4] net: skb: check the boundrary of drop reason in kfree_skb_reason() Jakub Kicinski
2022-05-12 16:16     ` Eric Dumazet
2022-05-13  2:41     ` Menglong Dong
2022-05-12 12:33 ` [PATCH net-next v2 3/4] net: skb: change the definition SKB_DR_SET() menglong8.dong
2022-05-12 12:33 ` [PATCH net-next v2 4/4] net: tcp: reset 'drop_reason' to NOT_SPCIFIED in tcp_v{4,6}_rcv() menglong8.dong
2022-05-12 16:16   ` Jakub Kicinski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220512123313.218063-3-imagedong@tencent.com \
    --to=menglong8.dong@gmail.com \
    --cc=asml.silence@gmail.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=ilias.apalodimas@linaro.org \
    --cc=imagedong@tencent.com \
    --cc=kafai@fb.com \
    --cc=keescook@chromium.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luiz.von.dentz@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=nhorman@tuxdriver.com \
    --cc=pabeni@redhat.com \
    --cc=talalahmad@google.com \
    --cc=vasily.averin@linux.dev \
    --cc=willemb@google.com \
    --cc=yoshfuji@linux-ipv6.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).