From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (mail.openvz.org [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id C3EA580033 for ; Tue, 1 Dec 2026 15:40:04 +0000 (UTC) Received: from mail.openvz.org (localhost [127.0.0.1]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6B1FcqH4020204; Tue, 1 Dec 2026 18:38:53 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6B1FcqH4020204 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="TNDB83vx" Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6B1FcoQU020193 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Tue, 1 Dec 2026 18:38:50 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6B1FcoQU020193 Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-6ba63cc6d3aso3087442a12.2 for ; Tue, 01 Dec 2026 07:38:50 -0800 (PST) X-Gm-Message-State: APuU4Z8jyl1jxLeV0SV7+IcHCkCuGw3LtEFeKXYK9JSftn5WF1U1Kf5W taUY1dizeTp6oQROr6BOyYvXKz5fN+gc0IZjMyxyVUM2noh5Ed5yIHd7YOWmOhUXH2Xu8aSk8px RttcS/A3nbk3knCLsIxM65jxf4jhXplUKsCuNxcKvG1U4qEnJMFcQ2A== X-Gm-Gg: AZFdTZf9MCzZR7HF+JG0jTQCjyYeoj/dHZ1BFJxfGAMd+FIjMvAVrY7jp1KpKK9q+r0 zZYWP311bwdhcAQ9pFMAAtlM0iE/NCgMlwBiJHn0p9MY5n3mNscDhi3c29SKjvl+WUUd8YYJ+F/ QRMuR5aNS0mVwTujC0VLHWMg9JkVEXyVpVJevQ5lQ73FvYceOrcG6lJeQrnBBfbplKh41sKJfkQ zX5dLxWGrnkZXbaz06FWLa+vXaPddMihYTqsBEbbvql1PqYTlGxiaymIQCzwH4jJXt/gmKc5L4Y NMjMdN33tT6fYBv6f4YgfqSKeuY4TV3hCVJJSf895iLANYJv5YDLPIYhe6QK8/K8OPBv79GGcZe FUq7JNfQmucMVBPX21GPzh8abDg== X-Received: by 2002:aa7:da51:0:b0:6af:a64f:bd44 with SMTP id 4fb4d7f45d1cf-6ba37ee193dmr20885576a12.45.1796139529641; Tue, 01 Dec 2026 07:38:49 -0800 (PST) X-Received: by 2002:aa7:da51:0:b0:6af:a64f:bd44 with SMTP id 4fb4d7f45d1cf-6ba37ee193dmr20885562a12.45.1796139529122; Tue, 01 Dec 2026 07:38:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1796139529; cv=none; d=google.com; s=arc-20260327; b=gkSjCbGRnx3FPTQ4N1VzNV/S5A8+kjB7x6vIJsn299uhThzy/FNn79FnpK3UrLdPa1 LkrfEWBzxuzoKOtkMRL4oep571LU64jWnKCPXg7XGXMVdgsGrc5hR7/k3QvNB6TLar68 MoJGMfPECjRyGcs4My3tsmm72UptK0PYbwz1BvHBvA4fUg8/8/HIwQI2tQ9xDkYjIgkW DXsEWzUU5zLLcbk4tMALVQVnWHJJwOKBA6qbFDk/rGdkBF+1e9Ir8uAgOdOKw7WE3rIo VgIch1XpJhCRfYdMjWM5Wos1u2OBLVgFiqzmItA7H1NhhfrEN1CIWYc29XoXh9Ib6k88 430g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=jS+nFs3noy2IapgiMy29Ub4++ruppF2NiE/fUgjm4uI=; fh=/QSWnKFFIPNLStgUoDwCQRaXnWcMIG7fyKJgHY+VEpU=; b=XSxbkCxdXwSVhO9oP72gjf8XGzHG2aK0otiU5/gMryspq6qNHAjwQE3Xdn5n2tJA5L va4MwjHT+IZxt3qWdYYKY/wmWngsWHo9v7d0UO7AD1KrriPRvZF5/9PAlBIJNhbERRIX t42YD95nS02D7eJLtItUvn18rP+rj+eCziIm23dgWBfI2jYbb61HZ7vXjn+brhd59yVN euHWkdDy0ABXF78XUUGWUOjontbXpfWZK67d2mXh58B5/3B1JCQG2bJhFKPlqDrBxYr6 zmvDoBcMrhq1JQV1wxr7c3S2dyM/0A0T63Lsk26QNLyttvHhjfFzhUsJBliLqUyCO3g8 kZQg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=TNDB83vx; spf=pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=eva.kurchatova@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: from relay.virtuozzo.com (relay.virtuozzo.com. [130.117.225.111]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-6bc312b788bsi2724920a12.253.2026.12.01.07.38.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 07:38:49 -0800 (PST) Received-SPF: pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) client-ip=130.117.225.111; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=TNDB83vx; spf=pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=eva.kurchatova@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=MIME-Version:Message-ID:Date:Subject:From: Content-Type; bh=jS+nFs3noy2IapgiMy29Ub4++ruppF2NiE/fUgjm4uI=; b=TNDB83vxu1eU ibrEJAF1a41iOWIKuh4le7Mu1d2duRfY+B5BRlGtievjCKli3QcgsS2q4hludz+626Rgp1qZOv4xZ Ujzy9yPjvT/iJDloUIiVLBxWcc2IiqlxG1qrphPPF8AnKFd89ArEaJ1uzKIz+ADkdyFYUv81sjmGu dEXcGrtXyRfJz22IWIlL7i3/lpnKbvXPOUIJforkTrGGmfmWuNy7OXhgSSYEmzRS7uUB0zH/OCk47 HuvYxrXnwJ0UKixk9xS+zuJBvnU/t0s2FzpeSCDJaXtW1PNIZWb1jnviJhvaT72EotA18J/t7Psxx /8jDM2Nz5AatzahYiJC33g==; Received: from ch-vpn.virtuozzo.com ([130.117.225.6] helo=LekKit-T14) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1xYPvC-0081OE-1L; Tue, 01 Dec 2026 16:37:45 +0100 From: Eva Kurchatova To: khorenko@virtuozzo.com, vladimir.riabchun@virtuozzo.com Date: Tue, 1 Dec 2026 14:10:27 +0200 Message-ID: <20261201153749.2872789-13-eva.kurchatova@virtuozzo.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261201153749.2872789-1-eva.kurchatova@virtuozzo.com> References: <20261201153749.2872789-1-eva.kurchatova@virtuozzo.com> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.2 v2 12/15] ms/selftests/bpf: Test bpf_sock_destroy() on TIME_WAIT and listener socks X-BeenThere: devel@openvz.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: OpenVZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: devel-bounces@openvz.org Errors-To: devel-bounces@openvz.org From: Jiayuan Chen Add two subtests. tcp_timewait: the client shuts down first and the server closes after it, so the client sock ends up in TIME_WAIT. A tcp iterator then finds the timewait sock by the cookie it inherited from the client sock and destroys it. Iterate once more to make sure it is gone. Without the first fix bpf_sock_destroy() reads past the timewait sock and KASAN complains. tcp_listen_pending: connect to a listener but never accept, so the child sits in the accept queue, then destroy the listener. Without the second fix the cond_resched() in inet_csk_listen_stop() trips the might_sleep check under rcu_read_lock(). ./test_progs -a sock_destroy #444/1 sock_destroy/tcp_client:OK #444/2 sock_destroy/tcp_server:OK #444/3 sock_destroy/tcp_listen_pending:OK #444/4 sock_destroy/tcp_timewait:OK #444/5 sock_destroy/udp_client:OK #444/6 sock_destroy/udp_server:OK #444/7 sock_destroy/trace_tcp_destroy_sock:OK #444 sock_destroy:OK Summary: 1/7 PASSED, 0 SKIPPED, 0/0 FAILED Signed-off-by: Jiayuan Chen Link: https://lore.kernel.org/r/20260910112810.153801-1-jiayuan.chen@linux.dev Signed-off-by: Alexei Starovoitov (cherry picked from commit 8036d3a5a6589ef0721d15e7c03976bc3996f7a8) https://virtuozzo.atlassian.net/browse/VSTOR-158161 Feature: fix ms/net Signed-off-by: Eva Kurchatova --- .../selftests/bpf/prog_tests/sock_destroy.c | 121 ++++++++++++++++++ .../selftests/bpf/progs/sock_destroy_prog.c | 30 +++++ 2 files changed, 151 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/sock_destroy.c b/tools/testing/selftests/bpf/prog_tests/sock_destroy.c index 9c11938fe597..78d642a02bdb 100644 --- a/tools/testing/selftests/bpf/prog_tests/sock_destroy.c +++ b/tools/testing/selftests/bpf/prog_tests/sock_destroy.c @@ -1,4 +1,5 @@ // SPDX-License-Identifier: GPL-2.0 +#include #include #include @@ -110,6 +111,122 @@ static void test_tcp_server(struct sock_destroy_prog *skel) close(serv); } +static void test_tcp_listen_pending(struct sock_destroy_prog *skel) +{ + int serv = -1, clien = -1, accept_serv = -1, n, serv_port; + struct pollfd pfd = { .events = POLLIN }; + char buf[1]; + + serv = start_server(AF_INET6, SOCK_STREAM, NULL, 0, 0); + if (!ASSERT_GE(serv, 0, "start_server")) + goto cleanup; + serv_port = get_socket_local_port(serv); + if (!ASSERT_GE(serv_port, 0, "get_sock_local_port")) + goto cleanup; + skel->bss->serv_port = (__be16)serv_port; + + /* + * Connect but never accept, so the child sits in the accept queue + * of the listener. Wait until it's actually there. + */ + clien = connect_to_fd(serv, 0); + if (!ASSERT_GE(clien, 0, "connect_to_fd")) + goto cleanup; + pfd.fd = serv; + if (!ASSERT_EQ(poll(&pfd, 1, -1), 1, "poll listener")) + goto cleanup; + + /* Run iterator program that destroys server sockets. */ + start_iter_sockets(skel->progs.iter_tcp6_server); + + accept_serv = accept(serv, NULL, NULL); + if (!ASSERT_LT(accept_serv, 0, "accept on destroyed listener")) + goto cleanup; + ASSERT_EQ(errno, EINVAL, "error code on destroyed listener"); + + /* The unaccepted child was reset along with the listener. */ + n = recv(clien, buf, sizeof(buf), 0); + if (!ASSERT_LT(n, 0, "client recv on reset child")) + goto cleanup; + ASSERT_EQ(errno, ECONNRESET, "error code on reset child"); + +cleanup: + if (clien != -1) + close(clien); + if (accept_serv != -1) + close(accept_serv); + if (serv != -1) + close(serv); +} + +static void test_tcp_timewait(struct sock_destroy_prog *skel) +{ + int serv = -1, clien = -1, accept_serv = -1, n; + struct timeval tv = {}; + char buf[1]; + + serv = start_server(AF_INET6, SOCK_STREAM, NULL, 0, 0); + if (!ASSERT_GE(serv, 0, "start_server")) + goto cleanup; + + clien = connect_to_fd(serv, 0); + if (!ASSERT_GE(clien, 0, "connect_to_fd")) + goto cleanup; + + accept_serv = accept(serv, NULL, NULL); + if (!ASSERT_GE(accept_serv, 0, "serv accept")) + goto cleanup; + + /* + * Active close from the client, then close the server side. Once + * recv() sees EOF the server FIN has been processed and the client + * sock is in TIME_WAIT. Block without timeout so a loaded CI box + * can't race us. + */ + if (!ASSERT_OK(setsockopt(clien, SOL_SOCKET, SO_RCVTIMEO, &tv, + sizeof(tv)), "clear rcvtimeo")) + goto cleanup; + if (!ASSERT_OK(shutdown(clien, SHUT_WR), "client shutdown")) + goto cleanup; + + /* + * Make sure the server has seen the client FIN before it closes, + * so the two FINs never cross. + */ + n = recv(accept_serv, buf, sizeof(buf), 0); + if (!ASSERT_EQ(n, 0, "server recv EOF")) + goto cleanup; + + close(accept_serv); + accept_serv = -1; + + /* block until return EOF */ + n = recv(clien, buf, sizeof(buf), 0); + if (!ASSERT_EQ(n, 0, "client recv EOF")) + goto cleanup; + + /* Run iterator program that destroys the timewait client sock. */ + skel->bss->tw_found = 0; + start_iter_sockets(skel->progs.iter_tcp6_timewait); + if (!ASSERT_EQ(skel->bss->tw_found, 1, "timewait sock found")) + goto cleanup; + + ASSERT_OK(skel->bss->tw_destroy_err, "destroy timewait sock"); + + /* The destroyed timewait sock must be gone. */ + skel->bss->tw_found = 0; + start_iter_sockets(skel->progs.iter_tcp6_timewait); + ASSERT_EQ(skel->bss->tw_found, 0, "timewait sock destroyed"); + +cleanup: + if (clien != -1) + close(clien); + if (accept_serv != -1) + close(accept_serv); + if (serv != -1) + close(serv); +} + static void test_udp_client(struct sock_destroy_prog *skel) { int serv = -1, clien = -1, n = 0; @@ -204,6 +321,10 @@ void test_sock_destroy(void) test_tcp_client(skel); if (test__start_subtest("tcp_server")) test_tcp_server(skel); + if (test__start_subtest("tcp_listen_pending")) + test_tcp_listen_pending(skel); + if (test__start_subtest("tcp_timewait")) + test_tcp_timewait(skel); if (test__start_subtest("udp_client")) test_udp_client(skel); if (test__start_subtest("udp_server")) diff --git a/tools/testing/selftests/bpf/progs/sock_destroy_prog.c b/tools/testing/selftests/bpf/progs/sock_destroy_prog.c index 9e0bf7a54cec..0a8887543218 100644 --- a/tools/testing/selftests/bpf/progs/sock_destroy_prog.c +++ b/tools/testing/selftests/bpf/progs/sock_destroy_prog.c @@ -7,6 +7,8 @@ #include "bpf_tracing_net.h" __be16 serv_port = 0; +int tw_found = 0; +int tw_destroy_err = 0; int bpf_sock_destroy(struct sock_common *sk) __ksym; @@ -100,6 +102,34 @@ int iter_tcp6_server(struct bpf_iter__tcp *ctx) return 0; } +SEC("iter/tcp") +int iter_tcp6_timewait(struct bpf_iter__tcp *ctx) +{ + struct sock_common *sk_common = ctx->sk_common; + __u64 *val; + int key = 0; + + if (!sk_common) + return 0; + + if (sk_common->skc_family != AF_INET6) + return 0; + + if (!bpf_skc_to_tcp_timewait_sock(sk_common)) + return 0; + + val = bpf_map_lookup_elem(&tcp_conn_sockets, &key); + if (!val) + return 0; + /* The timewait sock inherits the cookie of the closed client sock. */ + if (bpf_get_socket_cookie(sk_common) != *val) + return 0; + + tw_found++; + tw_destroy_err = bpf_sock_destroy(sk_common); + + return 0; +} SEC("iter/udp") int iter_udp6_client(struct bpf_iter__udp *ctx) -- 2.56.1 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel