🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #20117

Re: [PATCH bpf 09/11] bpf, sockmap: Fix apply_bytes when a redirect sends only a part

#20117
From: bot+bpf-ci
Date: Sat, 21 Nov 2026 11:11
99 lines
12157 bytes
--===============1453606125876828301==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit

> bpf, sockmap: Fix apply_bytes when a redirect sends only a part

TL;DR: The apply_bytes give-back in tcp_bpf_send_verdict() may leave a source
socket permanently failing sendmsg() with -EPIPE after its redirect target
closes, since the restored redirect verdict is never cleared.

> diff --git a/net/ipv4/tcp_bpf.c b/net/ipv4/tcp_bpf.c
> --- a/net/ipv4/tcp_bpf.c
> +++ b/net/ipv4/tcp_bpf.c

[ ... ]

> @@ -566,6 +563,21 @@ static int tcp_bpf_send_verdict(struct sock *sk, struct sk_psock *psock,
>  			msg = NULL;
>  			ret = 0;
>  		}
> +		/*
> +		 * Bytes that were not sent and come back, in msg or in the
> +		 * next sendmsg(), are still covered by the verdict.
> +		 */
> +		if (apply && sent < tosend && !cork) {
> +			psock->apply_bytes += tosend - sent;
> +			if (eval == __SK_REDIRECT) {
> +				psock->eval = eval;
> +				psock->sk_redir = sk_redir;
> +				eval = __SK_NONE;
> +			}
> +		}
> +		if (eval == __SK_REDIRECT)
> +			sock_put(sk_redir);
> +		sock_put(sk_redir);
>  		break;

Can this give-back leave the source socket unable to send after the redirect
target goes away?

The give-back runs for every short redirect, whatever the error.  Some
errors from tcp_bpf_sendmsg_redir() are permanent and send nothing
(sent == 0):

    if (!READ_ONCE(sk->sk_socket))
        return sock_flag(sk, SOCK_DEAD) ? -EPIPE : -EINVAL;
    psock = sk_psock_get(sk);
    if (unlikely(!psock))
        return -EPIPE;

They happen when the target was closed (__tcp_close() -> sock_orphan()) or
removed from the sockmap.  The same goes for an egress target whose
connection was reset, where tcp_sendmsg_locked() returns -EPIPE.

In those cases sk_msg_apply_bytes(psock, tosend) takes off tosend bytes and
the new code adds tosend - 0 back, so psock->apply_bytes ends up at its old
value.  When apply_bytes had reached 0, the code also puts back
psock->eval = __SK_REDIRECT and psock->sk_redir = <dead target>.

Nothing else clears that state.  The only writers of psock->eval,
apply_bytes and sk_redir are this function, sk_psock_msg_verdict() (which
runs only when psock->eval == __SK_NONE), the cork_bytes reset in
tcp_bpf_sendmsg(), and sk_psock_destroy().  So every later sendmsg() on the
source socket follows the same path:

    tcp_bpf_sendmsg() -> tcp_bpf_send_verdict()
      psock->eval == __SK_REDIRECT, prog not run
      tcp_bpf_sendmsg_redir(dead target) -> -EPIPE, sent = 0
      apply_bytes restored, verdict restored
    -> sk_stream_error() -> -EPIPE (plus SIGPIPE unless MSG_NOSIGNAL)

The source socket's own connection is healthy, but it can no longer send
while it is in the sockmap.  The sk_msg program never runs again, so it
cannot pick a new target or drop.  The dead target's struct sock also stays
pinned by psock->sk_redir until the psock is destroyed.

Before this patch the verdict always used up tosend bytes, even on failure.
A redirect to a dead target failed at most about apply_bytes / tosend times.
Then psock->eval went back to __SK_NONE, the prog ran again, and with the
closed target gone from the map the lookup failed and the prog returned
SK_DROP (or chose another target).

The give-back is right for short sends the user is expected to retry
(-EAGAIN, -ENOMEM from bpf_tcp_ingress(), a partial ret == 0).  Should it be
skipped, or should the verdict be cleared, when the target cannot take data
any more (for example -EPIPE)?

No later commit in the series changes net/ipv4/tcp_bpf.c; the rest of the
series only adds selftests.


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/44896626218
--===============1453606125876828301==--
Technical Details
Message-ID: <10c5af49a70a8f40bbcf3afaddefa15089060a8d1d1aac01d5810c5b088adc47@mail.kernel.org>
Path: mbox-mo1.pugleaf.net!news-lon.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368324-linux-kernel-netdev=dewy.ru
References: <20261121103222.88209-10-jiayuan.chen@linux.dev>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lon.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368324-linux-kernel-netdev=dewy.ru
From: bot+bpf-ci@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH bpf 09/11] bpf, sockmap: Fix apply_bytes when a redirect sends only a part
Date: Sat, 21 Nov 2026 11:11:11 +0000 (UTC)
Organization: Usenet Network
Message-ID: <10c5af49a70a8f40bbcf3afaddefa15089060a8d1d1aac01d5810c5b088adc47@mail.kernel.org>
References: <20261121103222.88209-10-jiayuan.chen@linux.dev>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="===============1453606125876828301=="
Injection-Info: usenet.network;
	logging-data="3397134"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:54A3WoaoWzffSvIzrxG0auWZfTc= sha256:QPNkeJ33tzb2B2QUbU6NsN0Gu4rYEvl6MERLiB7/cks=
	sha1:ib1PXY/jBemYButYa5K2cOYcEGQ= sha256:P1ojoq8qyzsQ6Jjv1AinpG9dmXbEKpzQHJFahLYrNgk=
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 B097B115B55; Sat, 21 Nov 2026 14:11:36 +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 Piv3Ln2Tz1Ub;
	Sat, 21 Nov 2026 14:11:33 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-368324-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 60369115B54; Sat, 21 Nov 2026 14:11:22 +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 882CD2ADDA; Sat, 21 Nov 2026 11:11:20 +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=1795259476;
	b=zYDXU3bJ368KHgAlRsK2vOWO0CY9+Afj5kUtMcVp6HsByKg2FkMKYYXIXYclCtqUGLEE
	 Ta00fS9GDVutsV5aeV1agSY1G1drizlhsiqvZWXcl5ZGioEcOnvjLNw2iT4s4xxBZ/N0/
	 bfRYzGlecuT9hNoMU/l7MsSXZcI1O/3JUxGktZXAWbh//gu5rco8Vog1DbgkAu+hNyjoy
	 FlXev+faLd57wTcBpINBgzekeINFzZhUQTls9DP4yzI4SfGzanrOuejrNvSbG8ZSJO6kv
	 vRTA81jYCWHhzBDQ4J7MsCOYv13jIJsqzyRQ/aWOvO2e0K2FpQacnxgpqIVVTbTPfqw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795259476;
	h=X-Original-To:Received:Received:DKIM-Signature:Content-Type:
	 X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:Message-Id:
	 In-Reply-To:References:Subject:From:To:Cc:Date;
	bh=pc3/8eaz2R7en0wB3IVJjUSju2aIpRoh8x5NratlNNQ=;
	b=N2eNGK8DZO8QtzKPZprboxFIE84QLhUJuJeDJs7p97QShGqqNxFjOW9l70Lbj+R8swTw
	 /yBUjbhjj6V321B141pfS/mMEUJR23FcUDoZ2vuSPk+3KAXKycfU3wb9QOL7BL5KvX0gy
	 EkDoslsSniG4FAi8dql/92lc9FC8YQX64/NRZiXtjiHelr4BjZWWuqTdQkMZmSKAahKB0
	 z/TksVFwBJ6Da59pfUf3nx+/pUhEi9IHeE8BgAQj0v2ACAE8kxFP1ODh7dqiIHImYNSIv
	 CQ62vo2XUuekVDjwIso/rPBnj6u8s/k1VIbdHGLJKuBns7eRsfbFuchXUz0GX4TgvmA==
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=eRyesDRR;
	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 7E7E7606A688;
	Sat, 21 Nov 2026 11:11:16 +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=eRyesDRR
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=1795259475;
	b=h+xUjQlm6ByUyw1jQ4J3aLWHScetUtDsH5i1Ptuk/ZFFvjgkyEtcU7L4+usL7MZYrwcf
	 gpSLCzDssUaKuOh+2pCyTBFmjx42U+T5K4QfTyCAg+PsggIBsVtZICK3X0hVzYjxy5PJT
	 zuWaPKMABg5cYwInZF54ieZcap/W2gKBTyt/Q/xznrwXpZGvACrHAYvPeKdMizpVWBmw/
	 VK8HCAx+bZZs0tYXbx017mZMNM8SKmqTSegItsvuQgB4lzlg0UxkgtFiTmV9LKPoae9ob
	 0OFWTIMfx56AF+KgQ9OrP3urH9mr4vENXZNiJP5dJqrYBoYkvtFZvq7QYfgExVjgg2A==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795259475;
	h=Received:DKIM-Signature:Content-Type:MIME-Version:Message-Id:
	 In-Reply-To:References:Subject:From:To:Cc:Date;
	bh=pc3/8eaz2R7en0wB3IVJjUSju2aIpRoh8x5NratlNNQ=;
	b=ivgBx978G15BT/2XDBPx1mUgjFinUVRbZ9jEDbc74LQku9zYaNiRlzUNqi3qVrUEiKPv
	 PfIE2xgu485jMx00wPKG4LTzgawQlVWbpgxZq29RKlX5OJKFiFzJSUDffJhmSJ6AU1PkI
	 1z8zkboIRtL7jgdr6hKxc8u4e9eZuy7qr43qC20uouI43v4IizDpRp3fEuWnb+TnnLXYn
	 0CIFT7vVB33st/eZ25sxEeJoIizsAsJzUmej0dnC3oeUrntYy1sO3OuwF7KxjAM/td9Up
	 H84a8CkRNienIbS/g5LGjEBWlKsPjkfXP8dEJWJUOl4JzJjpP1kmw562DxSFUd8F+Iw==
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=eRyesDRR;
	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 9CB60606A32C;
	Sat, 21 Nov 2026 11:11:15 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id E71D01F000C0;
	Sat, 21 Nov 2026 11:11:11 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795259475;
	bh=pc3/8eaz2R7en0wB3IVJjUSju2aIpRoh8x5NratlNNQ=;
	h=In-Reply-To:References:Subject:From:To:Cc:Date;
	b=eRyesDRRrnGA4qkWPsWNmEDPNX5cBFgK5rTNvgPH6WFIOjDoJZkAZrjzjyaKM0Srx
	 x2vUqChiO26jFcj8M6OJ36RuMsuXigPD0i6Sak/zkqhH+nI/gbHHsrCU+mDqMyNnnS
	 nR2TOxKuV+kkV5qcjOoPlvf2GgRpQggIJlH6Mi8sqoIUj5TeRxoBcjr7zCgUO85Z7L
	 axTWJG1XCiGpQNI9yu1Qf21umDXXMARk4d3LudGhP4knmkZoKvXOJS5VCKN0gxpPYM
	 mg5JLjdFzQSomX2c8UWAuyl3CjRBpyuuMvZnBp77LdDCCtSmwe2YtiuNT5NDqMdCvJ
	 LhMJt96dx5zGQ==
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
X-In-Reply-To: <20261121103222.88209-10-jiayuan.chen@linux.dev>
X-Cc: jiayuan.chen@linux.dev,john.fastabend@gmail.com,jakub@cloudflare.com,davem@davemloft.net,edumazet@kernel.org,kuba@kernel.org,pabeni@redhat.com,horms@kernel.org,kuniyu@google.com,willemb@google.com,ncardwell@google.com,andrii@kernel.org,eddyz87@gmail.com,ihor.solodrai@linux.dev,daniel@iogearbox.net,memxor@gmail.com,martin.lau@linux.dev,song@kernel.org,yonghong.song@linux.dev,jolsa@kernel.org,emil@etsalapatis.com,shuah@kernel.org,rhkrqnwk98@gmail.com,mattia.meleleo@coralogix.com,mhal@rbox.co,linux-kernel@vger.kernel.org,netdev@vger.kernel.org,linux-kselftest@vger.kernel.org,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,mason@kernel.org,ihor.solodrai@linux.dev