From: Vadim Fedorenko <vadim.fedorenko@linux.dev>
To: Lena Wang <lena.wang@mediatek.com>,
edumazet@google.com, davem@davemloft.net, dsahern@kernel.org,
pabeni@redhat.com, kuba@kernel.org
Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org
Subject: Re: [PATCH net] tcp: check if skb is true to avoid crash
Date: Thu, 26 Sep 2024 10:06:21 +0100 [thread overview]
Message-ID: <abbe18b1-b372-4044-8490-82e6c0b4ec36@linux.dev> (raw)
In-Reply-To: <20240926075646.15592-1-lena.wang@mediatek.com>
On 26/09/2024 08:56, Lena Wang wrote:
> A kernel NULL pointer dereference reported.
> Backtrace:
> vmlinux tcp_can_coalesce_send_queue_head(sk=0xFFFFFF80316D9400, len=755)
> + 28 </alps/OfficialRelease/Of/alps/kernel-6.6/net/ipv4/tcp_output.c:2315>
> vmlinux tcp_mtu_probe(sk=0xFFFFFF80316D9400) + 3196
> </alps/OfficialRelease/Of/alps/kernel-6.6/net/ipv4/tcp_output.c:2452>
> vmlinux tcp_write_xmit(sk=0xFFFFFF80316D9400, mss_now=128,
> nonagle=-2145862684, push_one=0, gfp=2080) + 3296
> </alps/OfficialRelease/Of/alps/kernel-6.6/net/ipv4/tcp_output.c:2689>
> vmlinux tcp_tsq_write() + 172
> </alps/OfficialRelease/Of/alps/kernel-6.6/net/ipv4/tcp_output.c:1033>
> vmlinux tcp_tsq_handler() + 104
> </alps/OfficialRelease/Of/alps/kernel-6.6/net/ipv4/tcp_output.c:1042>
> vmlinux tcp_tasklet_func() + 208
>
> When there is no pending skb in sk->sk_write_queue, tcp_send_head
> returns NULL. Directly dereference of skb->len will result crash.
> So it is necessary to evaluate the skb to be true here.
>
> Fixes: 808cf9e38cd7 ("tcp: Honor the eor bit in tcp_mtu_probe")
> Signed-off-by: Lena Wang <lena.wang@mediatek.com>
> ---
> net/ipv4/tcp_output.c | 20 +++++++++++---------
> 1 file changed, 11 insertions(+), 9 deletions(-)
>
> diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
> index 4fd746bd4d54..12cde5d879c5 100644
> --- a/net/ipv4/tcp_output.c
> +++ b/net/ipv4/tcp_output.c
> @@ -2338,17 +2338,19 @@ static bool tcp_can_coalesce_send_queue_head(struct sock *sk, int len)
> struct sk_buff *skb, *next;
>
> skb = tcp_send_head(sk);
> - tcp_for_write_queue_from_safe(skb, next, sk) {
> - if (len <= skb->len)
> - break;
> + if (skb) {
Thinking more of this, I don't really understand how is it possible to
reach tcp_can_coalesce_send_queue_head() with empty send queue, but
anyway, this patch will move NULL dereference further to tcp_mtu_probe()
where new skb is build with the same tcp_send_head() call.
I believe the proper way is to return false here in case of missing skb:
if (!skb)
return false;
This will prevent tcp_mtu_probe() to continue execution and avoid
possible NULL dereference.
> + tcp_for_write_queue_from_safe(skb, next, sk) {
> + if (len <= skb->len)
> + break;
>
> - if (unlikely(TCP_SKB_CB(skb)->eor) ||
> - tcp_has_tx_tstamp(skb) ||
> - !skb_pure_zcopy_same(skb, next) ||
> - skb_frags_readable(skb) != skb_frags_readable(next))
> - return false;
> + if (unlikely(TCP_SKB_CB(skb)->eor) ||
> + tcp_has_tx_tstamp(skb) ||
> + !skb_pure_zcopy_same(skb, next) ||
> + skb_frags_readable(skb) != skb_frags_readable(next))
> + return false;
>
> - len -= skb->len;
> + len -= skb->len;
> + }
> }
>
> return true;
next prev parent reply other threads:[~2024-09-26 9:06 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-26 7:56 [PATCH net] tcp: check if skb is true to avoid crash Lena Wang
2024-09-26 8:50 ` Vadim Fedorenko
2024-09-26 9:06 ` Vadim Fedorenko [this message]
2024-09-26 9:07 ` Eric Dumazet
2024-09-26 14:04 ` Lena Wang (王娜)
2024-09-26 14:21 ` Eric Dumazet
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=abbe18b1-b372-4044-8490-82e6c0b4ec36@linux.dev \
--to=vadim.fedorenko@linux.dev \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=lena.wang@mediatek.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/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).