All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
From: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
To: khorenko@virtuozzo.com, vladimir.riabchun@virtuozzo.com
Cc: devel@openvz.org
Subject: [Devel] [PATCH hci-8.2 v2 02/15] ms/tcp: Skip cond_resched() in inet_csk_listen_stop() under BPF context
Date: Tue,  1 Dec 2026 14:10:17 +0200	[thread overview]
Message-ID: <20261201153749.2872789-3-eva.kurchatova@virtuozzo.com> (raw)
In-Reply-To: <20261201153749.2872789-1-eva.kurchatova@virtuozzo.com>

From: Jiayuan Chen <jiayuan.chen@linux.dev>

[ Upstream commit eaab8cab451b9502ce224cd202550375b894a467 ]

bpf_sock_destroy() runs from the tcp iterator, under rcu_read_lock(). If
the sock is a listener that still has children in its accept queue,
tcp_abort() ends up in inet_csk_listen_stop() and the cond_resched()
there trips the debug check:

BUG: sleeping function called from invalid context at net/ipv4/inet_connection_sock.c:1523
in_atomic(): 0, irqs_disabled(): 0, non_block: 0, pid: 628, name: test_progs
preempt_count: 0, expected: 0
RCU nest depth: 1, expected: 0
locks held by test_progs/628: 3, last CPU#3:
 #0: ffff8881158cee18 (&p->lock){+.+.}-{4:4}, at: bpf_seq_read+0x56/0x1210
 #1: ffff8881106bb858 (sk_lock-AF_INET6){+.+.}-{0:0}, at: bpf_iter_tcp_seq_show+0x32b/0x4b0
 #2: ffffffffb435af20 (rcu_read_lock){....}-{1:3}, at: bpf_iter_run_prog+0x46b/0xde0
CPU: 3 UID: 0 PID: 628 Comm: test_progs Tainted: G        W           7.2.0+ #65 PREEMPT
Tainted: [W]=WARN
Call Trace:
 <TASK>
 dump_stack_lvl+0xc1/0xf0
 dump_stack+0x10/0x20
 __might_resched+0x3d2/0x610
 inet_csk_listen_stop+0x7b/0xbf0
 tcp_abort+0x23b/0x3b0
 bpf_sock_destroy+0xfc/0x140
 bpf_prog_448133d24601754f_iter_tcp6_server+0x81/0x8a
 bpf_iter_run_prog+0x538/0xde0
 bpf_iter_tcp_seq_show+0x26b/0x4b0
 bpf_seq_read+0x424/0x1210
 vfs_read+0x197/0xe40
 ksys_read+0x119/0x240
 __x64_sys_read+0x72/0xc0
 x64_sys_call+0x647/0x27e0
 do_syscall_64+0xe5/0x610
 entry_SYSCALL_64_after_hwframe+0x76/0x7e
RIP: 0033:0x7fad39b28aca
RSP: 002b:00007ffc381c61c0 EFLAGS: 00000246 ORIG_RAX: 0000000000000000
RAX: ffffffffffffffda RBX: 00007ffc381c6a88 RCX: 00007fad39b28aca
RDX: 0000000000000032 RSI: 00007ffc381c6250 RDI: 0000000000000014
RBP: 00007ffc381c61e0 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000003
R13: 0000000000000000 R14: 000055f077c1bbb0 R15: 00007fad3a0f3000
 </TASK>

The commit that added the kfunc already guards lock_sock() in tcp_abort()
and udp_abort() with has_current_bpf_ctx(), but missed the listener path.
Do the same for the cond_resched(). The loop runs inside the iterator's
rcu_read_lock(), it must not reschedule or report a quiescent state there.

Fixes: 4ddbcb886268 ("bpf: Add bpf_sock_destroy kfunc")
Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
Link: https://lore.kernel.org/r/20260910112736.153710-1-jiayuan.chen@linux.dev
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
(cherry picked from commit 5b52417c6196e05618a3b5d9753dbed9adef0166)

https://virtuozzo.atlassian.net/browse/VSTOR-157577
Feature: fix ms/net

Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
Reviewed-by: Sashiko <no-reply@sashiko.virtuozzo.com>
---
 net/ipv4/inet_connection_sock.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
index 21334e0c015e..e8c2070ad7f0 100644
--- a/net/ipv4/inet_connection_sock.c
+++ b/net/ipv4/inet_connection_sock.c
@@ -1520,7 +1520,8 @@ void inet_csk_listen_stop(struct sock *sk)
 		local_bh_enable();
 		sock_put(child);
 
-		cond_resched();
+		if (!has_current_bpf_ctx())
+			cond_resched();
 	}
 	if (queue->fastopenq.rskq_rst_head) {
 		/* Free all the reqs queued in rskq_rst_head. */
-- 
2.56.1

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

  parent reply	other threads:[~2026-12-01 15:39 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 12:10 [Devel] [PATCH hci-8.2 v2 00/15] ms: backport additional TFO and CALIPSO fixes Eva Kurchatova
2026-12-01 12:10 ` [Devel] [PATCH hci-8.2 v2 01/15] ms/tcp: clear sock_ops cb flags before force-closing a child socket Eva Kurchatova
2026-12-01 12:10 ` Eva Kurchatova [this message]
2026-12-01 12:10 ` [Devel] [PATCH hci-8.2 v2 03/15] ms/net/ipv6: Introduce payload_len helpers Eva Kurchatova
2026-12-01 12:10 ` [Devel] [PATCH hci-8.2 v2 04/15] ms/calipso: keep BIG TCP payload_len in calipso_skbuff_setattr() Eva Kurchatova
2026-12-01 12:10 ` [Devel] [PATCH hci-8.2 v2 05/15] ms/calipso: hash the cache key, not the option start, in calipso_cache_add() Eva Kurchatova
2026-12-01 12:10 ` [Devel] [PATCH hci-8.2 v2 06/15] ms/calipso: update payload_len when removing the CALIPSO option Eva Kurchatova
2026-12-01 12:10 ` [Devel] [PATCH hci-8.2 v2 07/15] ms/tcp: fix NULL pointer dereference when restarting a Fast Open listener Eva Kurchatova
2026-12-01 12:10 ` [Devel] [PATCH hci-8.2 v2 08/15] ms/tcp: purge Fast Open RST queue when listen() fails Eva Kurchatova
2026-12-01 12:10 ` [Devel] [PATCH hci-8.2 v2 09/15] ms/netlabel: fix IPv6 unlabeled address add error handling Eva Kurchatova
2026-12-01 15:42   ` no-reply
2026-12-01 12:10 ` [Devel] [PATCH hci-8.2 v2 10/15] ms/netlabel: validate unlabeled address and mask attribute lengths Eva Kurchatova
2026-12-01 15:42   ` no-reply
2026-12-01 12:10 ` [Devel] [PATCH hci-8.2 v2 11/15] ms/bpf: Fix out-of-bounds read of sk_protocol in bpf_sock_destroy() Eva Kurchatova
2026-12-01 15:43   ` no-reply
2026-12-01 12:10 ` [Devel] [PATCH hci-8.2 v2 12/15] ms/selftests/bpf: Test bpf_sock_destroy() on TIME_WAIT and listener socks Eva Kurchatova
2026-12-01 15:43   ` no-reply
2026-12-01 12:10 ` [Devel] [PATCH hci-8.2 v2 13/15] ms/tcp: initialize send sequence numbers before deferring TFO Eva Kurchatova
2026-12-01 15:44   ` no-reply
2026-12-01 12:10 ` [Devel] [PATCH hci-8.2 v2 14/15] ms/cipso: fix optlen corruption in cipso_v4_delopt() Eva Kurchatova
2026-12-01 15:45   ` no-reply
2026-12-01 12:10 ` [Devel] [PATCH hci-8.2 v2 15/15] ms/cipso: stop modifying live ip_options_rcu Eva Kurchatova
2026-12-01 15:45   ` no-reply

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=20261201153749.2872789-3-eva.kurchatova@virtuozzo.com \
    --to=eva.kurchatova@virtuozzo.com \
    --cc=devel@openvz.org \
    --cc=khorenko@virtuozzo.com \
    --cc=vladimir.riabchun@virtuozzo.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.