All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jiayuan Chen" <jiayuan.chen@linux.dev>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf v2 3/3] selftests/bpf: Test bpf_sock_destroy() on TIME_WAIT and listener socks
Date: Sun, 06 Sep 2026 07:50:35 +0000	[thread overview]
Message-ID: <20260906075035.BED911F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260906074135.185212-4-jiayuan.chen@linux.dev>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The file descriptor returned by `accept()` is leaked on the test failure path in `test_tcp_listen_pending()`.
--

commit a0eed787a7f06953fc57cb1d362195f000753ca9
Author: Jiayuan Chen <jiayuan.chen@linux.dev>

selftests/bpf: Test bpf_sock_destroy() on TIME_WAIT and listener socks

This commit adds two subtests to the sock_destroy BPF selftest. The tests
ensure that bpf_sock_destroy() correctly handles sockets in TIME_WAIT and
listener sockets with pending connections in the accept queue.

> diff --git a/tools/testing/selftests/bpf/prog_tests/sock_destroy.c b/tools/testing/selftests/bpf/prog_tests/sock_destroy.c
> index 9c11938fe597d..c9f0885709c7e 100644
> --- a/tools/testing/selftests/bpf/prog_tests/sock_destroy.c
> +++ b/tools/testing/selftests/bpf/prog_tests/sock_destroy.c

[ ... ]

> @@ -110,6 +111,120 @@ 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, n, serv_port;
> +	struct pollfd pfd = { .events = POLLIN };
> +	char buf[1];
> +
> +	serv = start_server(AF_INET6, SOCK_STREAM, NULL, 0, 0);

[ ... ]

> +	/* Run iterator program that destroys server sockets. */
> +	start_iter_sockets(skel->progs.iter_tcp6_server);
> +
> +	n = accept(serv, NULL, NULL);
> +	if (!ASSERT_LT(n, 0, "accept on destroyed listener"))
> +		goto cleanup;

[Severity: Medium]
Does this code leak the file descriptor on the error path?

If accept(serv, NULL, NULL) unexpectedly succeeds, it returns a valid
file descriptor in n (where n >= 0). The ASSERT_LT(n, 0) check then
fails and execution jumps to the cleanup block.

Because n is not closed in cleanup, the accepted socket is leaked.

> +	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 (serv != -1)
> +		close(serv);
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260906074135.185212-1-jiayuan.chen@linux.dev?part=3

      reply	other threads:[~2026-09-06  7:50 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-06  7:41 [PATCH bpf v2 0/3] bpf,tcp: Fix bpf_sock_destroy() on TIME_WAIT and listener socks Jiayuan Chen
2026-09-06  7:41 ` [PATCH bpf v2 1/3] bpf: Fix out-of-bounds read of sk_protocol in bpf_sock_destroy() Jiayuan Chen
2026-09-07 23:23   ` Kuniyuki Iwashima
2026-09-06  7:41 ` [PATCH bpf v2 2/3] tcp: Skip cond_resched() in inet_csk_listen_stop() under BPF context Jiayuan Chen
2026-09-06  8:01   ` sashiko-bot
2026-09-06  8:23   ` bot+bpf-ci
2026-09-07 23:34     ` Kuniyuki Iwashima
2026-09-08  8:07       ` Jiayuan Chen
2026-09-08 12:22         ` Jiayuan Chen
2026-09-06  7:41 ` [PATCH bpf v2 3/3] selftests/bpf: Test bpf_sock_destroy() on TIME_WAIT and listener socks Jiayuan Chen
2026-09-06  7:50   ` sashiko-bot [this message]

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=20260906075035.BED911F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=jiayuan.chen@linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.