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,
	Jiang Biao <benbjiang@tencent.com>,
	Hao Peng <flyingpeng@tencent.com>
Subject: [PATCH net-next v3 4/4] net: tcp: reset 'drop_reason' to NOT_SPCIFIED in tcp_v{4,6}_rcv()
Date: Fri, 13 May 2022 11:03:39 +0800	[thread overview]
Message-ID: <20220513030339.336580-5-imagedong@tencent.com> (raw)
In-Reply-To: <20220513030339.336580-1-imagedong@tencent.com>

From: Menglong Dong <imagedong@tencent.com>

The 'drop_reason' that passed to kfree_skb_reason() in tcp_v4_rcv()
and tcp_v6_rcv() can be SKB_NOT_DROPPED_YET(0), as it is used as the
return value of tcp_inbound_md5_hash().

And it can panic the kernel with NULL pointer in
net_dm_packet_report_size() if the reason is 0, as drop_reasons[0]
is NULL.

Fixes: 1330b6ef3313 ("skb: make drop reason booleanable")
Reviewed-by: Jiang Biao <benbjiang@tencent.com>
Reviewed-by: Hao Peng <flyingpeng@tencent.com>
Signed-off-by: Menglong Dong <imagedong@tencent.com>
---
v3:
- remove new lines between tags
v2:
- consider tcp_v6_rcv()
---
 net/ipv4/tcp_ipv4.c | 1 +
 net/ipv6/tcp_ipv6.c | 1 +
 2 files changed, 2 insertions(+)

diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 918816ec5dd4..24eb42497a71 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -2101,6 +2101,7 @@ int tcp_v4_rcv(struct sk_buff *skb)
 	}
 
 discard_it:
+	SKB_DR_OR(drop_reason, NOT_SPECIFIED);
 	/* Discard frame. */
 	kfree_skb_reason(skb, drop_reason);
 	return 0;
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index 60bdec257ba7..636ed23d9af0 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -1509,6 +1509,7 @@ int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
 discard:
 	if (opt_skb)
 		__kfree_skb(opt_skb);
+	SKB_DR_OR(reason, NOT_SPECIFIED);
 	kfree_skb_reason(skb, reason);
 	return 0;
 csum_err:
-- 
2.36.1


  parent reply	other threads:[~2022-05-13  3:05 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-13  3:03 [PATCH net-next v3 0/4] net: skb: check the boundrary of skb drop reason menglong8.dong
2022-05-13  3:03 ` [PATCH net-next v3 1/4] net: dm: check the boundary of skb drop reasons menglong8.dong
2022-05-13  3:03 ` [PATCH net-next v3 2/4] net: skb: check the boundrary of drop reason in kfree_skb_reason() menglong8.dong
2022-05-13  3:03 ` [PATCH net-next v3 3/4] net: skb: change the definition SKB_DR_SET() menglong8.dong
2022-05-13  3:03 ` menglong8.dong [this message]
2022-05-19 15:48   ` [PATCH net-next v3 4/4] net: tcp: reset 'drop_reason' to NOT_SPCIFIED in tcp_v{4,6}_rcv() Jakub Kicinski
2022-05-20  1:46     ` Menglong Dong
2022-05-20  2:09       ` Jakub Kicinski
2022-05-20  2:18         ` Jakub Kicinski
2022-05-20  2:39           ` Menglong Dong
2022-05-16 10:00 ` [PATCH net-next v3 0/4] net: skb: check the boundrary of skb drop reason patchwork-bot+netdevbpf

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=20220513030339.336580-5-imagedong@tencent.com \
    --to=menglong8.dong@gmail.com \
    --cc=asml.silence@gmail.com \
    --cc=benbjiang@tencent.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=flyingpeng@tencent.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).