πŸš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #10645

Re: [PATCH bpf v2 09/15] bpf, sockmap: Check the TCP state in recvmsg()

#10645
From: netdev-bot+sashiko
Date: Tue, 03 Nov 2026 21:38
130 lines
12658 bytes
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] Concern (commit message accuracy): the concern says the commit
  message wrongly claims icsk_ack.rcv_mss "can be 0 in TCP_CLOSE",…

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but psock data
  from an old connection still advances tp->copied_seq of the next…

--

bpf, sockmap: Check the TCP state in recvmsg()

This commit makes tcp_bpf_recvmsg_parser() call __tcp_cleanup_rbuf() only
when tcp_can_send_ack() returns true. The reason is that psock data can
outlive the connection it arrived on, for example after tcp_disconnect().
tcp_can_send_ack() moves from net/mptcp/protocol.c to include/net/tcp.h so
both users can share it.

> __tcp_select_window() divides by icsk_ack.rcv_mss, which can be 0 in
> TCP_CLOSE.

[Severity: Low]
This isn't a bug, and the statement looks accurate. Still, a reader may
wonder how rcv_mss gets to 0 in TCP_CLOSE, because tcp_disconnect()
explicitly guards against it:

net/ipv4/tcp.c:tcp_disconnect() {
    ...
	inet_csk_delack_init(sk);
	/* Initialize rcv_mss to TCP_MIN_MSS to avoid division by 0
	 * issue in __tcp_select_window()
	 */
	icsk->icsk_ack.rcv_mss = TCP_MIN_MSS;
    ...
}

It seems to happen when a later listen() on the disconnected socket fails.
inet_csk_listen_start() calls inet_csk_delack_init(), which zeroes rcv_mss.
If get_port() or hash() then fails, the socket returns to TCP_CLOSE with
rcv_mss still 0:

net/ipv4/inet_connection_sock.c:inet_csk_listen_start() {
    ...
	inet_csk_delack_init(sk);
    ...
	err = sk->sk_prot->get_port(sk, inet->inet_num);
    ...
	inet_sk_set_state(sk, TCP_CLOSE);
	return err;
}

Would it help to mention this path, and that TCP_LISTEN is covered as
well, in the commit message?

> diff --git a/net/ipv4/tcp_bpf.c b/net/ipv4/tcp_bpf.c
> index ef2e15de0fe3b..3d703f1517d88 100644
> --- a/net/ipv4/tcp_bpf.c
> +++ b/net/ipv4/tcp_bpf.c
> @@ -343,7 +343,8 @@ static int tcp_bpf_recvmsg_parser(struct sock *sk,
>  	if (!peek)
>  		WRITE_ONCE(tcp->copied_seq, seq);
>  	tcp_rcv_space_adjust(sk);
> -	if (copied > 0)
> +	/* Data on the psock outlives the connection that it came in on */
> +	if (copied > 0 && tcp_can_send_ack(sk))
>  		__tcp_cleanup_rbuf(sk, copied);

[Severity: High]
This is a pre-existing issue and was not introduced by this patch, but the
new comment points at it. If psock data outlives the connection, do the
copied_seq and tcp_rcv_space_adjust() updates just above the new check
still charge bytes from the old connection to the new one?

SK_PASS data is tagged as self-originated in sk_psock_skb_ingress_self():

	msg->sk = sk;

tcp_read_skb() does not advance copied_seq for these skbs. Instead,
tcp_bpf_recvmsg_parser() adds them later:

	seq += copied_from_self;
    ...
	if (!peek)
		WRITE_ONCE(tcp->copied_seq, seq);

tcp_disconnect() purges sk_receive_queue and sets copied_seq to rcv_nxt.
It leaves psock->ingress_msg alone, and the socket stays in the sockmap.
A later connect() resets copied_seq to the new rcv_nxt.

Here is a possible sequence:

  socket in a sockmap with an sk_skb stream_verdict prog returning SK_PASS
  data is received but not read (D bytes in psock->ingress_msg)
  connect(AF_UNSPEC) -> tcp_disconnect()
  connect() to a new peer, reaches ESTABLISHED
  recvmsg() -> tcp_bpf_recvmsg_parser() reads the D stale bytes

After this, copied_seq is new rcv_nxt + D and stays D bytes ahead for the
rest of the connection.

tcp_rcv_space_adjust() then computes inq = rcv_nxt - copied_seq = -D. That
inflates copied on every measurement and grows sk_rcvbuf and window_clamp
through tcp_rcvbuf_grow() for no reason.

If the socket later leaves the sockmap and falls back to
tcp_recvmsg_locked(), offset = *seq - TCP_SKB_CB(skb)->seq starts at D.
Wouldn't that silently skip the first D bytes of the new connection's
data? Or, when D is not less than skb->len, wouldn't it trigger the
"TCP recvmsg seq # bug 2" WARN in tcp_recvmsg_locked() or the
"cleanup rbuf bug" WARN in tcp_cleanup_rbuf()?

No later patch in the series seems to change how copied_seq is updated
here.

Should data that arrived on an earlier connection be kept out of the
copied_seq update too, and not only out of __tcp_cleanup_rbuf()?

>  
>  unlock:

[ ... ]

-- 
Sashiko AI review Β· https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261102072112.4160195-1-alexei.starovoitov%40gmail.com
Technical Details
Message-ID: <179374188255.488855.9131092470801455035@kernel.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-355989-linux-kernel-netdev=dewy.ru
References: <20261102072112.4160195-10-alexei.starovoitov@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-355989-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH bpf v2 09/15] bpf, sockmap: Check the TCP state in recvmsg()
Date: Tue, 03 Nov 2026 21:38:02 +0000
Organization: Usenet Network
Message-ID: <179374188255.488855.9131092470801455035@kernel.org>
References: <20261102072112.4160195-10-alexei.starovoitov@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3266479"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:5OIo2XiN0HE/ylVxV7cOyQoyW+g= sha256:xv5MLZq6SW671/NNjRn1GB/VxmovhJMDeKzfV14+ByU=
	sha1:rmytt23cPFdcYxe66oGn74hbf+4= sha256:biicRc4w3qosJANiWuriChVc7c2lTApVm76dpCFFuYc=
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 4834E112A1E; Wed,  4 Nov 2026 00:38:28 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 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] 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 9oFcQUy4CKfQ;
	Wed,  4 Nov 2026 00:38:25 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-355989-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 sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
	by mail.dewy.ru (Postfix) with ESMTPS id 5B756112032; Wed,  4 Nov 2026 00:38:14 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sin.lore.kernel.org (Postfix) with ESMTP id 1BBD826ACF; Tue,  3 Nov 2026 21:38:06 +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=1793741885;
	b=OBTJ5Z+Aos6yLF88oMyzd36B25a8X43l2I0U8mgr3LphUbOGByKwE3KDHLVgnxce8fB9
	 er7mnAJuXFxyuPgVG0LaueXAczMi1H3pT36g2nrgnjBPJ3vnfFeVnJPWktAd1hjNJW/yN
	 cvJAau9jPWNE4rtFma0on2YYR00GZbU4whxYYJadpTIH2uG+GIbq2bkoSGAdx4ccKx5og
	 Q2P354rfpHSRyYyjZXJkxfaxV/LFX7FZ4lZZZ9K3rp3dU4VU6QW+oMpzwyDdK7olUQE2R
	 B0KUOLhU93jVqbeMQE1ue6kXbh1Sr8c5Y+yxv1ycBwc0TV3BgPjfr2BmupNoBXeuCUw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793741885;
	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=et4jFj+lepmfD4AHQKMWafbOpDrJ6bouMC1wng41lQ4=;
	b=1JCWwlsRW+OpVdQaaDcyHiUqDgAJT2jvDoKFLd5gNbSYAhpSJYIYJX5tkd+Sf8yIKIAJ
	 iESQ4z1h5dtyasE9IR385OvHf53VjuEgeNEjx4nnS82+Sb1Cx8qOYT4Kc42ckKW68WtoV
	 SaHzSYo/rLlcPaAF/peba7M9pUuGbvVlaEgv11uapYCxKyqZii7y/cdlasJumSChhP1Ba
	 6D+DfLOxs31XSN6uxNe7pOwJXoGHG/bl4t+txdc8pV/X03Ke3rxl/6dok2MBwQX8DM70X
	 63VFi0yYqMxbjvZf09r/87JLZV6bLED4Xo3RsI9NTFI15BLCTAh2AOHwq2kKFeG/5aw==
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=KfJezgtP;
	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 7AE26606A33B;
	Tue,  3 Nov 2026 21:38:05 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=KfJezgtP
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=1793741884;
	b=5IhDQiXF14919KXjnsIQ2GQ0Hv7I63x6ld5dy9f9hK1IXSyL7NhzsM8W/fdvELc4VpJ6
	 z/BwQ8TEv+IaSTQJ5BZgvPckT/WPjDmBXL8DVIQitN3WHDWUaV+G2xqyvYviMiuUaHhlR
	 wojutnu2z1y/ncrZ9EtEA5gQQ89YG0ui0zQ0tITDIoCJ5iZJ/PPhLHvRwCVTlJLhA00f9
	 t9NJIDpqjKJvikZvpKZCA5ifvTkaNfjV1vv2eQJtH/dduoZhj6IserFvBZWkCAmMs5xSZ
	 CDYkgkOPlOlilFu+bVMn3XgBkuwZMIeL6ACsgIz5GU8P8i1bmcfJzLLheZLZWXyRlcQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793741884;
	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=et4jFj+lepmfD4AHQKMWafbOpDrJ6bouMC1wng41lQ4=;
	b=TmjIlTdWFEesIzXBu8eeuDHuFh299UKLjkZ3Xf/nRKSkxlky2FzUFVaJ4/PnjsUGVZ8j
	 z2RAzWhGz4ySPsi91bKM28PUMuICZccbyKcaUVwHaBzDu/Ka1CeMBmBgxChDgyw95PT4H
	 bQcf8ajn99CM/yvCm0g9t4NLE0301xo/Gvg+ZbwAXirJhA4STzsfNSrAUp9ZgHCiSSPhb
	 LvfybR+f1BUFjmhsKDqaNiMd0L6FzSVHCKwEkTyJOxlL3GZFOFJcJlptAcLM161qlunU/
	 Ij5RDKSGja+2qbFR77bEmJ84pa6THsdsUgpZruD2X3+yPdxr7lawnba/lQrRul/L5mA==
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=KfJezgtP;
	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 56457606A32C;
	Tue,  3 Nov 2026 21:38:04 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id ED56B1F000C1;
	Tue,  3 Nov 2026 21:38:02 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1793741884;
	bh=et4jFj+lepmfD4AHQKMWafbOpDrJ6bouMC1wng41lQ4=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=KfJezgtPeJuhdphudtslfqfLb5Hj1S4cf34NMIx8XJLv2ZXVgiIFzMiT7s1WL4mco
	 8s9UjPUifC69RcESghSDGjKDcGEJ3cyZThSPnFJn2LHU9O15gELOTtWfok35lHeRfe
	 PFOMSfiOIi59Ug5/v2x0pQDYrYJTIeSkgxV8WNMrhHsI2L5rhUrcO1KpPOzgvyUn/N
	 K08MCds7UqE9IlGONzne6uFN7KvznmFyTchVqTPqvv6wuYpCrU9YD/vqMZPXr0eYLv
	 ubMmqC+B7KAZP2au7uOSjJhZ6itCXevTw82/TscMzNmX4SzNQU42Ka5oTvC52+OwJS
	 ltY4VhUK+6ygg==
X-Cc: bpf@vger.kernel.org, netdev@vger.kernel.org, daniel@iogearbox.net,
 andrii@kernel.org, eddyz87@gmail.com, memxor@gmail.com,
 john.fastabend@gmail.com, jakub@cloudflare.com, jiayuan.chen@linux.dev,
 davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
 horms@kernel.org, kuniyu@google.com, willemb@google.com, matttbe@kernel.org,
 mptcp@lists.linux.dev, mason@kernel.org, josef@toxicpanda.com
X-In-Reply-To: <20261102072112.4160195-10-alexei.starovoitov@gmail.com>
X-sashiko-severity: Low
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