Article View: linux.kernel.netdev
Article #23994Re: [PATCH net] tcp: avoid NULL skb dereference in zerocopy receive with sockmap
From: netdev-bot+sashiko
Date: Sat, 28 Nov 2026 23:20
Date: Sat, 28 Nov 2026 23:20
168 lines
14149 bytes
14149 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] The patch fixes only the NULL return from tcp_recv_skb().
- [Medium] On the page-sized path of tcp_zerocopy_receive(), the new `if
(!skb) break;` turns the crash into a result with no progress and…
--
tcp: avoid NULL skb dereference in zerocopy receive with sockmap
This adds NULL checks on the tcp_recv_skb() results in
tcp_zc_handle_leftover() and tcp_zerocopy_receive(). It also stops the
mapping loop from advancing past the last skb in sk_receive_queue. The
NULL dereference it fixes happens when a sockmap SK_SKB verdict consumes
receive skbs without advancing tp->copied_seq, so tcp_inq() is non-zero
while the native receive queue is empty.
> diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
> index 418842a2dfd98..fa3b4bcbc726a 100644
> --- a/net/ipv4/tcp.c
> +++ b/net/ipv4/tcp.c
> @@ -2072,6 +2072,8 @@ static int tcp_zc_handle_leftover(struct tcp_zerocopy_receive *zc,
> offset = *seq - TCP_SKB_CB(skb)->seq;
> } else {
> skb = tcp_recv_skb(sk, *seq, &offset);
> + if (!skb)
> + return 0;
[Severity: High]
This catches the NULL return. Can tcp_recv_skb() still return a non-NULL
skb with a wrapped offset when copied_seq is out of sync like this?
The map-delete variant from the commit message is one way to get there.
After the sockmap entry is deleted, tp->copied_seq stays behind. New
segments are queued in sk_receive_queue with TCP_SKB_CB(skb)->seq greater
than copied_seq. tcp_recv_skb() then does this:
net/ipv4/tcp.c:tcp_recv_skb() {
...
offset = seq - TCP_SKB_CB(skb)->seq;
...
if (offset < skb->len || (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN)) {
*off = offset;
return skb;
}
...
tcp_eat_recv_skb(sk, skb);
}
The u32 offset wraps and every non-FIN skb is eaten. The first skb that
carries a FIN is returned with *off set to the wrapped value, and that
skb passes the new !skb check.
tcp_copy_straggler_data() then calls:
err = skb_copy_datagram_msg(skb, *offset, &msg, copylen);
The offset parameter of skb_copy_datagram_msg() is an int, so the value
becomes -gap. In __skb_datagram_iter(), copy = start - offset is positive.
The copy then reads from skb->data + offset, which is before the skb's
linear data, and writes the result to zc->copybuf_address.
Would this leak up to copybuf_len bytes of kernel memory to userspace? For
slab-backed heads, hardened usercopy could instead hit usercopy_abort().
copied_seq then advances by copylen, so it looks like this can be repeated
until copied_seq reaches the FIN skb.
The page-sized path seems to end up in the same place:
- tcp_recv_skb() in the mapping loop returns the FIN skb.
- recv_skip_hint becomes skb->len + gap.
- skb_advance_to_frag() fails and the loop breaks with skb still set.
- tcp_zc_handle_leftover() recomputes the same wrapped offset:
if (skb) {
offset = *seq - TCP_SKB_CB(skb)->seq;
tcp_recvmsg_locked() already guards against this state:
if (WARN(before(*seq, TCP_SKB_CB(skb)->seq),
"TCP recvmsg seq # bug: copied %X, seq %X, rcvnxt %X, fl %X\n",
*seq, TCP_SKB_CB(skb)->seq, tp->rcv_nxt,
flags))
break;
Should the zerocopy paths also reject before(seq, TCP_SKB_CB(skb)->seq),
or offset >= skb->len for non-FIN data, before copying? Or should the
copied_seq accounting be repaired instead?
> if (TCP_SKB_CB(skb)->has_rxtstamp) {
> tcp_update_recv_tstamps(skb, tss);
> zc->msg_flags |= TCP_CMSG_TS;
> @@ -2274,10 +2276,14 @@ static int tcp_zerocopy_receive(struct sock *sk,
> if (skb) {
> if (zc->recv_skip_hint > 0)
> break;
> + if (skb_queue_is_last(&sk->sk_receive_queue, skb))
> + break;
> skb = skb->next;
> offset = seq - TCP_SKB_CB(skb)->seq;
> } else {
> skb = tcp_recv_skb(sk, seq, &offset);
> + if (!skb)
> + break;
[Severity: Medium]
What does userspace see when this break fires on a page-sized request?
This is the in-map sockmap state the commit targets: tcp_inq() is at
least PAGE_SIZE, sk_receive_queue is empty, and the data sits in
psock->ingress_msg.
Earlier in tcp_zerocopy_receive():
if (total_bytes_to_map) {
...
zc->length = total_bytes_to_map;
zc->recv_skip_hint = 0;
After the break, tcp_zc_handle_leftover() computes copylen as
min(copybuf_len, 0) and returns 0. With length + copylen == 0 the call
returns success with zc->length == 0 and zc->recv_skip_hint == 0. At the
same time, do_tcp_getsockopt() still reports zc.inq > 0.
If a FIN has been received, SOCK_DONE is set, because tcp_fin() runs at
queue time even though the skb went to the psock. In that case this check
returns -EIO, even though read() could still return data through
tcp_bpf_recvmsg():
} else {
if (!zc->recv_skip_hint && sock_flag(sk, SOCK_DONE))
ret = -EIO;
}
For a small request in the same state, recv_skip_hint stays at avail_len,
so the caller gets a fallback hint it can use.
tools/testing/selftests/net/tcp_mmap.c only falls back to read() when
zc.recv_skip_hint != 0. With a large zc.length it would seem to retry
forever, or abort on -EIO after a FIN.
Should a NULL return here set recv_skip_hint to something like
inq/avail_len, or report an explicit error?
There is also the map-delete state. There, tcp_recv_skb() has already
freed every non-FIN skb whose seq is past copied_seq, via
tcp_eat_recv_skb(), before it returns NULL. With the new early return in
tcp_zc_handle_leftover(), is that already-ACKed data now dropped
silently? The commit message only says the checks do not consume data in
the sockmap ingress queue.
> }
>
> if (!skb_frags_readable(skb))
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124230228.3868519-1-graypanda.inzag%40gmail.com
Technical Details
Message-ID:
<179590803936.3135.2220127989487378712@kernel.org>Path:
mbox-mo1.pugleaf.net!news-can.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373289-linux-kernel-netdev=dewy.ruReferences:
<20261124230228.3868519-1-graypanda.inzag@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373289-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net] tcp: avoid NULL skb dereference in zerocopy receive with sockmap Date: Sat, 28 Nov 2026 23:20:39 +0000 Organization: Usenet Network Message-ID: <179590803936.3135.2220127989487378712@kernel.org> References: <20261124230228.3868519-1-graypanda.inzag@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="1057152"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:Cv8wEAhStrKNnCCr74P4KP/sqH4= sha256:ATcQU+YTAnuK+kacfj6scghZqWbLBaFx+cQ0cLI6DYA= sha1:ZzAtC+VTpqGECERUKsMNvpwl8eY= sha256:SHaXMDuqio1ANce/eLS8o3H+Oj0woyIsNHogC8/kfao= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 21DA1125F8A; Sun, 29 Nov 2026 02:21:05 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.4 X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1--e5jzF-32a; Sun, 29 Nov 2026 02:21:00 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-373289-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id DF63F125F88; Sun, 29 Nov 2026 02:20:49 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 91EFC274D7; Sat, 28 Nov 2026 23:20:47 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795908047; b=fXFJ4ysnRdWlpzGR3LexI1cpYCbVF1RFwhOQ025bhvOB7dK/xRx/8qLfoI3nuraTOO0t QdQteY+QpyzYSPNL6Un7g+mapJB4mSZhZOhKdzkqrL2czohBHmL27ENUeZh11SE+8pcG4 xGZmqMYQpehwavcSrMN+JxuY3TduaNBf59SM/7ZSoy7yaVzcON2FvnFZmjgvgkMxTKYPI mw4ivcvWbg3yIAYIou95n1QGmysHVzjFcVG7lekblQcJ8RLr0sEdX/xFCt8UaRjODxxYg 5WGFanYbS1H8GYzJ40fsVzR59rZ7/7F6lpfuK/VQ3/3+M9SmOX1piX6PsTEe+Ts7HUg== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795908047; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=wQOaNt/XodDD9Gl4ajo4DcUjoJSvHqs6eG7ibV/Pbtk=; b=z0BVgE00mswOI+Zm7F1qUavhf277QrDUikRDxcdvPTi3CTZ/D0g6w/2dQVowh6wPtJe1 FZAk0dUHFZ+rOyPZoIhLbVIDt9+Q+yOUfxGLiUWpyMeEyuqFoublTSwKccTLBtFT3lrnn qip03M169Lx03foroebr/0YMmLsPqMTGenmxKK1n6MI3cCWYNmLcXQEMO54l8Gliz+kg+ IeOT8QsGhiEZzAfJhu1wojn0dNS41PSPSuEKnK7rmyg6BCCmzKTjq+efPt/dpnSFe9kcd GLtaP1YKTH9SK0jY+l/6nk2T0+dYjz+o+IvCtRg6jGkx/kIbltEClpOlTYsxCwEyG7A== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Bqd6XT0Z; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 628EF606A32C; Sat, 28 Nov 2026 23:20:47 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Bqd6XT0Z X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795908041; b=1FZliQvTgTIIeJGL+6H5F9vxlgSOxY+3GjoCEWrNBiv+uAaTt6wzSMAB450j1gDVhZO9 tX+S8VVnCDijVJnZS8NYQoZQ4KSidVc87tl0nA96PJ38/7PSb3JGhWcmKN45KhQcHrAib 3ZUFSx3DJYsJ+2t/1vs48FQvbHK3xn95SGkf6UDxD9Q1+b3tiK3kL4xBl34wZrczMNUn3 uWe/JDjkFy+JbwXXnP6hJ+A+lv8dhUfPS7Qcy1Azyp8j/1xEt5ICRiKkYvFY9cbRqfmyd EvxOTElXeCNlHceVZoqRAKz8Sdyb6G9/k46TezfO5sosX1flZYDn0UcK5augVqUT0qQ== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795908041; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=wQOaNt/XodDD9Gl4ajo4DcUjoJSvHqs6eG7ibV/Pbtk=; b=IBlGPP5/vmmfTuj9gS/UEMlDhQckYWYMiRTsqhumHLzxlZQ5hjKK+thR8MTx9lmfhpzn oEPWtee2pqXtdPnnxGX9ZspSPZsp3bldNSptWxvZeIrqoC8dGUrvjkva7P5FL7qtzB3mY 4f+i1M29G4HzQG+l8zl55KL8KRgtDXdgc32IGBPuvUT82M1TjwfcTTqxd3Q863UOmKtW3 v9jz1IAa4Ac8GV0Q9XGfmGzB8vD5vOXFGk60fA2r3Py7XcMgbZCjdg3oq1EvDjjFK0GIi aAsxVBgAQNuYnW4HIR1TwOyRy23yABTymNLaHEapUsJohlooPkE9bIKz+mJUjMUBg5w== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Bqd6XT0Z; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2422F606A321; Sat, 28 Nov 2026 23:20:40 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id D08891F000C1; Sat, 28 Nov 2026 23:20:39 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795908040; bh=wQOaNt/XodDD9Gl4ajo4DcUjoJSvHqs6eG7ibV/Pbtk=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=Bqd6XT0Zm6ZJWwsAka11Mt+9Sw9xE99d+SvuZhwpSdfwnY4OaHgqL9Z3myTLOiQb0 eBAbMAX9K7x+AGI67IwXzvdF8yfzw7GnBvKj43Hg8xmDu5DeG/1Fh+gtFLmlmqr2NQ LtJvoAF+L7/8jFuXUqd6t6CiU55+m7yX2BkHueibCn0C2vTl7fdlmtojp7IEW3FcxI BL55YBrN9kVw0aw4RdZgzJcphc8i4aSl4Rj9edXKjmbory+xxt62173s9Fan6sqqWL Z/vlD1E1X28J2RxM+r22y8mhageqeoqCoiJSdJfgK80932aIhnAPN3WpuAnqHGOTAL gz6YTZmkuT9Og== X-Cc: edumazet@kernel.org, ncardwell@google.com, gwanhyunlee@gmail.com, kuniyu@google.com, davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, john.fastabend@gmail.com, jakub@cloudflare.com, jiayuan.chen@linux.dev, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org X-In-Reply-To: <20261124230228.3868519-1-graypanda.inzag@gmail.com> X-sashiko-severity: High X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list