From: sashiko-bot@kernel.org
To: "Jordan Rife" <jrife@google.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH net-next v3 4/4] selftests/bpf: Ensure dst addr/port are preserved after socket abort
Date: Sat, 25 Apr 2026 04:31:44 +0000 [thread overview]
Message-ID: <20260425043145.91098C2BCB2@smtp.kernel.org> (raw)
In-Reply-To: <20260330215707.2374657-5-jrife@google.com>
Sashiko AI review found 3 potential issue(s):
- [High] The test silently passes if the socket abort mechanism fails or if the target socket is not found, rendering it ineffective.
- [Medium] Uninitialized variable `out` is read and evaluated if `read()` returns an error.
- [Low] Passing a NULL pointer to the `%s` format specifier in `snprintf` causes undefined behavior.
--
commit 8c3285f5a0be84b220c0ac15975fdc9d109ad136
Author: Jordan Rife <jrife@google.com>
selftests/bpf: Ensure dst addr/port are preserved after socket abort
This commit adds a test to ensure that sock_release hooks see the original
dst_ip4, dst_ip6, and dst_port values for connected UDP and TCP sockets
following a socket abort.
diff --git a/tools/testing/selftests/bpf/prog_tests/sock_destroy_release.c b/tools/testing/selftests/bpf/prog_tests/sock_destroy_release.c
new file mode 100644
index 0000000000000..022031332b839
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/sock_destroy_release.c
[ ... ]
> +static void destroy(struct sock_destroy_release *skel, int fd, int sock_type)
> +{
[ ... ]
> + /* Delete matching socket. */
> + nread = read(iter_fd, &out, sizeof(out));
> + ASSERT_GE(nread, 0, "nread");
> + if (nread)
> + ASSERT_EQ(out, cookie, "cookie matches");
If the iterator fails to find the target socket, read() returns 0. The test
tolerates this because ASSERT_GE(0, 0) passes and if (nread) simply skips
the ASSERT_EQ.
Since the test then proceeds to call close(connect_fd), which performs a
normal socket closure, won't the sock_release hook naturally see the intact
dst_ip and dst_port values, causing the test to silently pass without the
socket ever being aborted? Should this assert that nread == sizeof(out)?
Additionally, if read() fails and returns -1, the ASSERT_GE() macro logs a
test failure but does not return early.
Because -1 evaluates to true in C, could this lead to executing
ASSERT_EQ(out, cookie, ...) where out is an uninitialized stack variable?
[ ... ]
> +static void do_tests(struct sock_destroy_release *skel, int sock_type,
> + int family, const char * const *bind_addrs,
> + size_t bind_addrs_len, const int *bind_ports,
> + size_t bind_ports_len)
> +{
> + const char *protocol_name = sock_type == SOCK_STREAM ? "tcp" : "udp";
> + const char *family_name = family == AF_INET ? "ipv4" : "ipv6";
> + char name[256];
> +
> + for (size_t i = 0; i < bind_addrs_len; i++) {
> + for (size_t j = 0; j < bind_ports_len; j++) {
> + snprintf(name, sizeof(name), "%s/%s/destroy/%s:%d",
> + protocol_name, family_name, bind_addrs[i],
> + bind_ports[j]);
Looking at test_sock_destroy_release(), the bind4_addresses and
bind6_addresses arrays contain NULL as their first element.
Could passing a NULL pointer to the %s format specifier cause undefined
behavior here?
While some libc implementations like glibc gracefully handle this by
outputting (null), others might crash or trigger sanitizer warnings.
Would it be safer to explicitly guard the argument, such as checking for
NULL and substituting it with a placeholder string?
diff --git a/tools/testing/selftests/bpf/progs/sock_destroy_release.c b/tools/testing/selftests/bpf/progs/sock_destroy_release.c
new file mode 100644
index 0000000000000..5389f79226f99
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/sock_destroy_release.c
[ ... ]
> +void maybe_abort(struct sock_common *sk, struct seq_file *seq)
> +{
> + __u64 sock_cookie;
> +
> + if (!sk)
> + return;
> +
> + sock_cookie = bpf_get_socket_cookie(sk);
> + if (sock_cookie != abort_cookie)
> + return;
> +
> + bpf_sock_destroy(sk);
> + bpf_seq_write(seq, &sock_cookie, sizeof(sock_cookie));
> +}
Is it possible for bpf_sock_destroy() to fail and return an error code?
If it does, the iterator will still return the cookie to userspace, which
will receive it and incorrectly assume the socket was aborted.
Would it make sense to only call bpf_seq_write() if bpf_sock_destroy()
succeeds?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260330215707.2374657-1-jrife@google.com?part=4
prev parent reply other threads:[~2026-04-25 4:31 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-30 21:57 [PATCH net-next v3 0/4] udp: Preserve UDP socket addresses on abort Jordan Rife
2026-03-30 21:57 ` [PATCH net-next v3 1/4] udp: Only compare daddr/dport when sk_state == TCP_ESTABLISHED Jordan Rife
2026-03-31 1:21 ` Kuniyuki Iwashima
2026-04-01 20:50 ` Jordan Rife
2026-03-30 21:57 ` [PATCH net-next v3 2/4] udp: Remove disconnected sockets from the 4-tuple hash Jordan Rife
2026-03-31 16:51 ` kernel test robot
2026-03-31 17:33 ` kernel test robot
2026-03-31 17:42 ` kernel test robot
2026-03-31 17:55 ` kernel test robot
2026-03-31 18:49 ` kernel test robot
2026-04-25 2:45 ` sashiko-bot
2026-03-30 21:57 ` [PATCH net-next v3 3/4] udp: Preserve destination address info after abort Jordan Rife
2026-03-30 21:57 ` [PATCH net-next v3 4/4] selftests/bpf: Ensure dst addr/port are preserved after socket abort Jordan Rife
2026-04-25 4:31 ` 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=20260425043145.91098C2BCB2@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=jrife@google.com \
--cc=sashiko@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox