Article View: linux.kernel.netdev
Article #9480[PATCH bpf v2 03/15] bpf, sockmap: Don't let an SK_PASS verdict cover the next message
From: Alexei Starovoitov
Date: Mon, 02 Nov 2026 07:21
Date: Mon, 02 Nov 2026 07:21
59 lines
13556 bytes
13556 bytes
From: Alexei Starovoitov <ast@kernel.org>
tcp_bpf_send_verdict() keeps the verdict of the sk_msg prog in psock->eval
and runs the prog only when eval is __SK_NONE. For __SK_PASS it resets eval
only after tcp_bpf_push() returns 0. But the push can release the socket
lock in sk_stream_wait_memory(), and it can fail. Then another
tcp_bpf_sendmsg() sends its message and does not run the prog.
With bpf_msg_apply_bytes() the verdict covers apply_bytes bytes. After a
failed push, apply_bytes still includes the sent bytes. Thus the verdict
covers more bytes than the prog requested.
Reset eval before the push when apply_bytes is 0. If this push fails, the
prog now runs for the rest of the message. The same already occurs when a
message does not fit into one sk_msg.
When the push fails, subtract the sent bytes from apply_bytes. When
apply_bytes is not 0, eval stays __SK_PASS during the push, and the prog
does not run for another message, as today. The verdict must still cover
the bytes that a failed push does not send. But such a message also lowers
apply_bytes. Thus, if apply_bytes is 0 after the subtraction, end the
verdict, as after a push that returns 0.
Fixes: 4f738adba30a ("bpf: create tcp_bpf_ulp allowing BPF to monitor socket TX/RX data")
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
---
net/ipv4/tcp_bpf.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/net/ipv4/tcp_bpf.c b/net/ipv4/tcp_bpf.c
index d90bcc911b36..b016aa419fb2 100644
--- a/net/ipv4/tcp_bpf.c
+++ b/net/ipv4/tcp_bpf.c
@@ -457,8 +457,22 @@ static int tcp_bpf_send_verdict(struct sock *sk, struct sk_psock *psock,
switch (psock->eval) {
case __SK_PASS:
+ /* The push may sleep without the socket lock, and it may fail */
+ if (!psock->apply_bytes)
+ psock->eval = __SK_NONE;
+ origsize = msg->sg.size;
ret = tcp_bpf_push(sk, msg, tosend, flags, true);
if (unlikely(ret)) {
+ /* A part of it may have gone out */
+ sk_msg_apply_bytes(psock, origsize - msg->sg.size);
+ /* Another sender can use up the rest during the push */
+ if (!psock->apply_bytes) {
+ psock->eval = __SK_NONE;
+ if (psock->sk_redir) {
+ sock_put(psock->sk_redir);
+ psock->sk_redir = NULL;
+ }
+ }
*copied -= sk_msg_free(sk, msg);
break;
}
--
2.55.0
Technical Details
Message-ID:
<20261102072112.4160195-4-alexei.starovoitov@gmail.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-354479-linux-kernel-netdev=dewy.ruReferences:
<20261102072112.4160195-1-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-354479-linux-kernel-netdev=dewy.ru
From: alexei.starovoitov@gmail.com (Alexei Starovoitov)
Newsgroups: linux.kernel.netdev
Subject: [PATCH bpf v2 03/15] bpf, sockmap: Don't let an SK_PASS verdict cover the next message
Date: Mon, 2 Nov 2026 07:21:00 +0000
Organization: Usenet Network
Message-ID: <20261102072112.4160195-4-alexei.starovoitov@gmail.com>
References: <20261102072112.4160195-1-alexei.starovoitov@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="2869501"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:F3K+7OlrC/BvLiRTI5m1H69oPg8= sha256:Ug5Hirfr4ayr+A9dEwJKf0RhLcFkmgKmVr90ORJA1yo=
sha1:1XFWz9oMoLknKkaY5YjfhrfOzSQ= sha256:RLUjEHQyVeX0unIZHgQiwVaFBoZWNyvh4jv5tjPdhd4=
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 B405E125CC7; Mon, 2 Nov 2026 10:22:29 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.048
X-Spam-Status: No, score=-3.048 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25,
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=gmail.com
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 oVFb8K1aFI9p;
Mon, 2 Nov 2026 10:22:27 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-354479-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
by mail.dewy.ru (Postfix) with ESMTPS id 28803125CC6; Mon, 2 Nov 2026 10:22:19 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by tor.lore.kernel.org (Postfix) with ESMTP id C606B2D62E; Mon, 2 Nov 2026 07:21:40 +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=1793604098;
b=iPABCbh6WWQiG+GLVoNXi2GtSRwbk7X7n5+TeytUj2GngriJI1RvlpRgT8R8jytLZ87i
IAbpDqkZK/uTc71zkli7J/p7Nu5vgFeW4+fwXq0BnDq8rRsizzJm3yuDoKMe79xI2/2ij
lEwaDMqNdJkAtWGvKkWf9KgY376FVs6asVEjoDq/xsmNqEJhcUx4hWiNsIc+pwUMxxzrU
WHjKfXThkPvhEEAZOOiM6Ey5bgxiZnbr4zua1P42JxmhXXMNzMBNDV6bR5yO77l1ZYJS/
RnGF8Zdey0d2XRKQ/kM7GKRa0mn1R0hs6M6izqaFhxsCctQ8wf2asasd8LcGYdv6NUA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793604098;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Forwarded-Encrypted:X-Gm-Message-State:
X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:Date:Message-ID:
X-Mailer:In-Reply-To:References:X-Mailing-List:List-Id:List-Post:
List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence:
MIME-Version:Content-Transfer-Encoding;
bh=Z7Peb9UAgZRQMeYI4B90l1wzrMCTNfd6vqfD72GCEUg=;
b=Ywqjr6+IF5JVu1p+nSw36aBJ3XVd2qe4St7K9tZG4qIexJ6IrifsVeaPObPM5U4WfeIr
2+sGY20+w9Ygm9h88KCRNJ0sczdy9vRkrNzAgJxmvoqDjbUHgCec9ijVjClEqnQ+eZUCd
/5cS+Ap6lJT0wZ0R55Xa6B/7N8UoZJcny0swlnCSl8hUjjkVsOoMSYsq2vOzTia6vaqYa
+821KmIQfKiTsKtYL3b4C2tclS38BClcaWYpI0C98srazuDTZ0J+nBwdijC9+Nhu7i/jQ
zOpl9vBPaQwhXznky/c2Q/n5iYE2+kcixvT5aE56J9dZm3L2uxxQgzBiVaAoJ+6ZE8Q==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=0iMfdFa2;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
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 C1C57606A338;
Mon, 2 Nov 2026 07:21:38 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=0iMfdFa2
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.178
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1793604097;
b=NoN44kmbE/gh93xjL1C9vdjFDcj6dnpVikf1ogOvE7TtRW5nh7zAnrBQV6fz1RLXNA1o
wXI8ipE1irIVkFGgOMt+Xim+feZk0JvEPfzyPDGWjp4XB775QzxgHE4Z38MRoDzLEHaVQ
Kzq4yEBu/NPQopmW1iV2Dd45hLVE6GKtHYxcuVT8skSJPDXsXNXOKeDu/k9dvjyVsbpiF
EIHDtw3K4RWpf0fos+bJpcuS2uycPi6eQVTX/x90C76X21CQ8Dx2etF0ebY4qGYxonIVd
hWMzpXg+cys24nQlYMWl3H8OOy6EvuxhCWPkCiGH+CAeY5nV5s+CPd4St2BYjax0cGA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793604097;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received:
From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:
MIME-Version:Content-Transfer-Encoding;
bh=Z7Peb9UAgZRQMeYI4B90l1wzrMCTNfd6vqfD72GCEUg=;
b=s2ryvo4XJfSVzejvSiLkXOHlV0vJ2SqpU3LhB7tn9ep/YbtmXX2ThUXYzYrebekpIuiM
zyAKPqcHi3yRIdHzHPa0W+d2/5Hv1huJyFpPtN4ixV2xWAXw3VtSx7i96pBgOcmZeccbM
PfsAymRf0+HosZ43OwT0K/vRzOEjh/QrJ8iifK+mU+j/S0wCelA+hlbC0ZC/sNLCgmZ9L
xiATiIOpli1VDLimdgNzvGZtuD1UYL1OqbRglWaKDmRH0BMf9tHOc/c4cnhSmjkhUTUDR
relILVKzSh4F0nX8AhDoIfqyEVQJTWdLUuhcXaC85YOXWv6ZZA7RPIdtCOVhBS02BGg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=0iMfdFa2;
arc=none smtp.remote-ip=209.85.214.178
X-Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178])
(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 92858606A32C
for <netdev@vger.kernel.org>; Mon, 2 Nov 2026 07:21:37 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 92858606A32C
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-2e8fe8e343fso17596035ad.2
for <netdev@vger.kernel.org>; Sun, 01 Nov 2026 23:21:37 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1793604097; x=1794208897; darn=vger.kernel.org;
h=content-transfer-encoding:mime-version:references:in-reply-to
:message-id:date:subject:cc:to:from:from:to:cc:subject:date
:message-id:reply-to:content-type;
bh=Z7Peb9UAgZRQMeYI4B90l1wzrMCTNfd6vqfD72GCEUg=;
b=0iMfdFa2E4giR6+L/RbyruUN4ugedAklyuqkewA7kWBIFjtADNmDS7ohqIWv+A18g8
Vr5JUv+UxVJ7/BaA9BooLtpJi69L2LS22ew2/4UPxWh+tJQ2RJFAqcRcLrAaPb3kSeAB
QyrHU2T/s1Os9GDCrrkN1864+RxS/qYCSiHUshnroVOxbeZwcGW6QeP278+pw8CkbKQF
etkP4hJtYvFs+8GoeloS9+bmU4UvMTIroZ7/v/ajesGA2xkkKOSzegcZxgSHJ/jV3LZJ
POWRp3Vmx+EjHThxTpb7S8LBtQ6j4JmOZ1scqou4VLy/S9IPVWD5+IWhvG5iO6f+zmHf
fXag==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1793604097; x=1794208897;
h=content-transfer-encoding:mime-version:references:in-reply-to
:message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from
:to:cc:subject:date:message-id:reply-to:content-type;
bh=Z7Peb9UAgZRQMeYI4B90l1wzrMCTNfd6vqfD72GCEUg=;
b=r1tCFGEZgRlWyf+7vy5zX+z+hs2dGkDLrV4HCmnCsO+xj1vTeAqmDR+MmfvQbhSlfX
6GvW5zufGC+XkDp7+HPIDEvoMHy5O0uXbfum8CP+IpBZz1Fz4NHjYBa5bzuLXPtTvIA1
VCZ4XS/4bAQOs6lwEXRuCamNotcIzDMOUw+GT95WsAlZxNBJSFnxl9lE4xgnOTMnlz1T
pQtXeQqvfmPBK0il2lQEuZIIgL41Jmrhjp+czjLp7nD4XZdy/gZMm7R9XDQxN4rcJfry
4cIxixHAq7LYjroiATmWlTe0V07KqJL9x8rHsS6QgtetJ6xRvhEiZ7CfomD6tPaVskh/
R8Rg==
X-Forwarded-Encrypted: i=1; AKwUvBwZVb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23:21:36 -0800 (PST)
X-Received: from coder-ast-ast-dev-ml-0.tail2dda0.ts.net ([153.61.198.247])
by smtp.gmail.com with ESMTPSA id d9443c01a7336-2eb3924c858sm24478145ad.35.2026.11.01.23.21.35
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Sun, 01 Nov 2026 23:21:35 -0800 (PST)
X-Cc: 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-Mailer: git-send-email 2.55.0
X-In-Reply-To: <20261102072112.4160195-1-alexei.starovoitov@gmail.com>
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