* [PATCH net-next] selftests: net: tcp_ao: test listen socket RST to a v4-mapped peer
@ 2026-12-05 2:22 Hungyu Lin
2026-12-06 2:53 ` netdev-bot+sashiko
0 siblings, 1 reply; 2+ messages in thread
From: Hungyu Lin @ 2026-12-05 2:22 UTC (permalink / raw)
To: edumazet, kuba, pabeni, davem, willemb
Cc: horms, shuah, 0x7f454c46, dsahern, rastislav.szabo, netdev,
linux-kselftest, dennylin0707
Test that a dual-stack listen socket replies with a signed RST to an
IPv4 segment from a peer whose key was added with a v4-mapped address.
Commit ef3e21c61baa ("net/tcp-ao: fix reset key lookup for IPv4 segments
on IPv6 listeners") fixed the key lookup for this RST, and a selftest
was suggested in its review [1].
The server kills the accepted socket without sending a FIN or a RST, so
the data that the client sends next reaches the listen socket, which
replies with a RST. That RST is signed without the ISNs of the
connection and the client drops it as a bad segment, so the test checks
the OutRsts counter on the server and expects a tcp_ao_mismatch event on
the client. The case runs after the netstat checks, as those expect no
bad segments. In the _ipv4 build the listen socket is an AF_INET6 one
bound to :: and the key is added for the v4-mapped address of the
client.
Let __test_listen_socket() take the family from the address, and let
test_cmp_getsockopt_setsockopt() compare a v4-mapped key address with
the AF_INET address that getsockopt() returns for it.
Without the fix, rst_ipv4 fails:
not ok 15 listen RST: OutRsts counter did not increase: 3 <= 3
not ok 16 Some trace events were expected, but didn't occur
Link: https://lore.kernel.org/all/CAL4WiiovxhEi8G4W9F7faF9COPTaUcjo_1VF2ObJpbUB0i1ibw@mail.gmail.com/ [1]
Signed-off-by: Hungyu Lin <dennylin0707@gmail.com>
---
tools/testing/selftests/net/tcp_ao/lib/sock.c | 13 ++-
tools/testing/selftests/net/tcp_ao/rst.c | 99 ++++++++++++++++++-
2 files changed, 109 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/net/tcp_ao/lib/sock.c b/tools/testing/selftests/net/tcp_ao/lib/sock.c
index 2e7b06a1a156..7121275cce3b 100644
--- a/tools/testing/selftests/net/tcp_ao/lib/sock.c
+++ b/tools/testing/selftests/net/tcp_ao/lib/sock.c
@@ -10,7 +10,8 @@
const unsigned int test_server_port = 7010;
int __test_listen_socket(int backlog, void *addr, size_t addr_sz)
{
- int err, sk = socket(test_family, SOCK_STREAM, IPPROTO_TCP);
+ int err, sk = socket(((struct sockaddr *)addr)->sa_family,
+ SOCK_STREAM, IPPROTO_TCP);
long flags;
if (sk < 0)
@@ -302,6 +303,8 @@ int test_set_ao_info(int sk, struct tcp_ao_info_opt *in)
int test_cmp_getsockopt_setsockopt(const struct tcp_ao_add *a,
const struct tcp_ao_getsockopt *b)
{
+ const struct sockaddr_in6 *a6 = (void *)&a->addr;
+ const struct sockaddr_in *b4 = (void *)&b->addr;
bool is_kdf_aes_128_cmac = false;
bool is_cmac_aes = false;
@@ -343,7 +346,13 @@ do { \
b->key, a->key);
return -1;
}
- if (memcmp(&b->addr, &a->addr, sizeof(b->addr))) {
+ if (a6->sin6_family == AF_INET6 && IN6_IS_ADDR_V4MAPPED(&a6->sin6_addr)) {
+ if (b4->sin_family != AF_INET ||
+ b4->sin_addr.s_addr != a6->sin6_addr.s6_addr32[3]) {
+ test_fail("getsockopt(): returned address is different");
+ return -1;
+ }
+ } else if (memcmp(&b->addr, &a->addr, sizeof(b->addr))) {
test_fail("getsockopt(): returned address is different");
return -1;
}
diff --git a/tools/testing/selftests/net/tcp_ao/rst.c b/tools/testing/selftests/net/tcp_ao/rst.c
index 883cddf377cf..ce9d24ac6437 100644
--- a/tools/testing/selftests/net/tcp_ao/rst.c
+++ b/tools/testing/selftests/net/tcp_ao/rst.c
@@ -170,6 +170,74 @@ static void test_server_passive_rst(unsigned int port)
synchronize_threads(); /* 6: server exits */
}
+#ifndef IPV6_TEST
+static int test_listen_socket_v4mapped(unsigned int port)
+{
+ struct sockaddr_in6 addr = {
+ .sin6_family = AF_INET6,
+ .sin6_port = htons(port),
+ };
+ struct tcp_ao_add ao;
+ int sk;
+
+ sk = __test_listen_socket(1, &addr, sizeof(addr));
+
+ addr.sin6_port = 0;
+ addr.sin6_addr.s6_addr32[2] = htonl(0xffff);
+ addr.sin6_addr.s6_addr32[3] = this_ip_dest.a4.s_addr;
+
+ if (test_prepare_key_sockaddr(&ao, DEFAULT_TEST_ALGO, &addr, sizeof(addr),
+ false, false, DEFAULT_TEST_PREFIX, 0, 100, 100,
+ 0, 0, strlen(DEFAULT_TEST_PASSWORD),
+ DEFAULT_TEST_PASSWORD))
+ test_error("test_prepare_key_sockaddr()");
+ if (setsockopt(sk, IPPROTO_TCP, TCP_AO_ADD_KEY, &ao, sizeof(ao)))
+ test_error("setsockopt(TCP_AO_ADD_KEY)");
+ if (test_verify_socket_key(sk, &ao))
+ test_error("test_verify_socket_key()");
+
+ return sk;
+}
+#endif
+
+static void test_server_listen_rst(unsigned int port)
+{
+ uint64_t before_cnt, after_cnt;
+ int sk, lsk;
+
+#ifdef IPV6_TEST
+ lsk = test_listen_socket(this_ip_addr, port, 1);
+ if (test_add_key(lsk, DEFAULT_TEST_PASSWORD, this_ip_dest, -1, 100, 100))
+ test_error("setsockopt(TCP_AO_ADD_KEY)");
+#else
+ lsk = test_listen_socket_v4mapped(port);
+#endif
+
+ synchronize_threads(); /* 1: MKT added => connect() */
+ if (test_wait_fd(lsk, TEST_TIMEOUT_SEC, 0))
+ test_error("test_wait_fd()");
+
+ sk = accept(lsk, NULL, NULL);
+ if (sk < 0)
+ test_error("accept()");
+
+ test_kill_sk(sk);
+ before_cnt = netstat_get_one("OutRsts", NULL);
+
+ synchronize_threads(); /* 2: accepted socket killed => send data */
+ synchronize_threads(); /* 3: client counters read => data sent */
+ synchronize_threads(); /* 4: client waited for the RST */
+ after_cnt = netstat_get_one("OutRsts", NULL);
+ if (after_cnt <= before_cnt)
+ test_fail("listen RST: OutRsts counter did not increase: %" PRIu64 " <= %" PRIu64,
+ after_cnt, before_cnt);
+ else
+ test_ok("listen RST: counter OutRsts increased %" PRIu64 " => %" PRIu64,
+ before_cnt, after_cnt);
+
+ close(lsk);
+}
+
static void *server_fn(void *arg)
{
struct netstat *ns_before, *ns_after;
@@ -184,6 +252,8 @@ static void *server_fn(void *arg)
netstats_check(ns_before, ns_after, "server");
netstat_free(ns_after);
netstat_free(ns_before);
+
+ test_server_listen_rst(port++);
synchronize_threads(); /* exit */
synchronize_threads(); /* don't race to exit() - client exits */
@@ -433,6 +503,32 @@ static void test_client_passive_rst(unsigned int port)
test_assert_counters("client passive RST", &cnt1, &cnt2, TEST_CNT_GOOD);
}
+static void test_client_listen_rst(unsigned int port)
+{
+ int sk, dummy;
+
+ sk = socket(test_family, SOCK_STREAM, IPPROTO_TCP);
+ if (sk < 0)
+ test_error("socket()");
+
+ if (test_add_key(sk, DEFAULT_TEST_PASSWORD, this_ip_dest, -1, 100, 100))
+ test_error("setsockopt(TCP_AO_ADD_KEY)");
+
+ synchronize_threads(); /* 1: MKT added => connect() */
+ if (test_connect_socket(sk, this_ip_dest, port) <= 0)
+ test_error("failed to connect()");
+
+ trace_ao_event_expect(TCP_AO_MISMATCH, this_ip_dest, this_ip_addr,
+ port, -1, 0, 0, 0, 1, 0, 0, 100, 100, -1);
+
+ synchronize_threads(); /* 2: accepted socket killed => send data */
+ if (!test_skpair_client(sk, packet_sz, 1, TEST_CNT_BAD, &dummy))
+ test_fail("listen RST: client sock is yet connected");
+
+ synchronize_threads(); /* 4: client waited for the RST */
+ test_kill_sk(sk);
+}
+
static void *client_fn(void *arg)
{
struct netstat *ns_before, *ns_after;
@@ -448,12 +544,13 @@ static void *client_fn(void *arg)
netstat_free(ns_after);
netstat_free(ns_before);
+ test_client_listen_rst(port++);
synchronize_threads(); /* exit */
return NULL;
}
int main(int argc, char *argv[])
{
- test_init(15, server_fn, client_fn);
+ test_init(16, server_fn, client_fn);
return 0;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH net-next] selftests: net: tcp_ao: test listen socket RST to a v4-mapped peer
2026-12-05 2:22 [PATCH net-next] selftests: net: tcp_ao: test listen socket RST to a v4-mapped peer Hungyu Lin
@ 2026-12-06 2:53 ` netdev-bot+sashiko
0 siblings, 0 replies; 2+ messages in thread
From: netdev-bot+sashiko @ 2026-12-06 2:53 UTC (permalink / raw)
To: dennylin0707
Cc: edumazet, kuba, pabeni, davem, willemb, horms, shuah, 0x7f454c46,
dsahern, rastislav.szabo, netdev, linux-kselftest
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] The only client-side check in test_client_listen_rst()
(tools/testing/selftests/net/tcp_ao/rst.c) can never fail.
- [Low] The file-level header comment of
tools/testing/selftests/net/tcp_ao/rst.c says the test covers two…
--
selftests: net: tcp_ao: test listen socket RST to a v4-mapped peer
This adds a case to the tcp_ao rst selftest. A dual-stack listen socket
must reply with an AO-signed RST to an IPv4 peer whose key was added with
a v4-mapped address. The patch also makes __test_listen_socket() take the
family from the address, and lets test_cmp_getsockopt_setsockopt()
compare v4-mapped key addresses.
Link: https://lore.kernel.org/all/CAL4WiiovxhEi8G4W9F7faF9COPTaUcjo_1VF2ObJpbUB0i1ibw@mail.gmail.com/
> diff --git a/tools/testing/selftests/net/tcp_ao/rst.c b/tools/testing/selftests/net/tcp_ao/rst.c
> index 883cddf377cff..ce9d24ac6437b 100644
> --- a/tools/testing/selftests/net/tcp_ao/rst.c
> +++ b/tools/testing/selftests/net/tcp_ao/rst.c
> @@ -170,6 +170,74 @@ static void test_server_passive_rst(unsigned int port)
[ ... ]
> +static void test_server_listen_rst(unsigned int port)
> +{
> + uint64_t before_cnt, after_cnt;
> + int sk, lsk;
[ ... ]
> + sk = accept(lsk, NULL, NULL);
> + if (sk < 0)
> + test_error("accept()");
> +
> + test_kill_sk(sk);
> + before_cnt = netstat_get_one("OutRsts", NULL);
> +
> + synchronize_threads(); /* 2: accepted socket killed => send data */
> + synchronize_threads(); /* 3: client counters read => data sent */
> + synchronize_threads(); /* 4: client waited for the RST */
> + after_cnt = netstat_get_one("OutRsts", NULL);
> + if (after_cnt <= before_cnt)
> + test_fail("listen RST: OutRsts counter did not increase: %" PRIu64 " <= %" PRIu64,
> + after_cnt, before_cnt);
> + else
> + test_ok("listen RST: counter OutRsts increased %" PRIu64 " => %" PRIu64,
> + before_cnt, after_cnt);
[Severity: Low]
This isn't a bug, but the header comment at the top of rst.c still
describes only the active reset and the passive (TIME-WAIT) reset:
* In both cases TCP-AO signatures have to be correct, which is verified by
* (1) checking that the TCP-AO connection was reset and (2) TCP-AO counters.
In the new listen socket case the client is expected to reject the RST
with a TCP_AO_MISMATCH instead of being reset. The case is checked with
the OutRsts counter and a trace event, not with a reset plus TCP-AO
counters.
Should the header be updated to describe this third case?
> +
> + close(lsk);
> +}
[ ... ]
> @@ -433,6 +503,32 @@ static void test_client_passive_rst(unsigned int port)
> test_assert_counters("client passive RST", &cnt1, &cnt2, TEST_CNT_GOOD);
> }
>
> +static void test_client_listen_rst(unsigned int port)
> +{
[ ... ]
> + trace_ao_event_expect(TCP_AO_MISMATCH, this_ip_dest, this_ip_addr,
> + port, -1, 0, 0, 0, 1, 0, 0, 100, 100, -1);
> +
> + synchronize_threads(); /* 2: accepted socket killed => send data */
> + if (!test_skpair_client(sk, packet_sz, 1, TEST_CNT_BAD, &dummy))
> + test_fail("listen RST: client sock is yet connected");
[Severity: Medium]
Can this test_fail() ever be reached? test_skpair_client() returns 0 only
when test_client_loop() gets back all buf_sz bytes:
tools/testing/selftests/net/tcp_ao/lib/sock.c:test_skpair_client() {
...
ret = test_client_loop(sk, buf_sz, msg_len, &c, cond, err);
test_tcp_counters_free(&c);
if (ret < 0)
return (int)ret;
return ret != buf_sz ? -1 : 0;
}
test_server_listen_rst() calls test_kill_sk() on the accepted socket and
never echoes anything back. Every outcome seems to give a non-zero
return:
- RST accepted: -ECONNRESET from __test_wait_fd()
- RST rejected and the TEST_CNT_BAD condition met: -ETIMEDOUT
- no RST at all: a real timeout, also -ETIMEDOUT
- short recv(): -1
The condition-met case and the real timeout both end up here in
__test_skpair_poll():
if (c && cond && __skpair_poll_should_stop(sk, c, cond))
break;
...
if (err)
*err = -ETIMEDOUT;
So the caller cannot tell those two apart either.
As a result, the client never asserts that its TCP-AO bad counters went
up. Two checks remain. One is the server's netns-wide OutRsts counter,
which goes up for any RST, signed or unsigned. The other is the
TCP_AO_MISMATCH trace expectation, which is dropped on kernels without
ftrace:
tools/testing/selftests/net/tcp_ao/lib/ftrace-tcp.c:trace_ao_event_expect() {
if (!kernel_config_has(KCONFIG_FTRACE))
return 0;
...
}
In that case the final trace check becomes test_skip(). The OutRsts check
does catch the failure from the commit message, where no RST is sent at
all.
On a kernel without ftrace, though, would a regression where the listener
sends an unsigned or wrongly keyed RST still pass?
For comparison, test_client_passive_rst() checks err == -ECONNRESET and
then calls test_assert_counters(). Could this case read the client
counters before and after and assert that the bad counters increased?
> +
> + synchronize_threads(); /* 4: client waited for the RST */
> + test_kill_sk(sk);
> +}
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261205022210.49972-1-dennylin0707%40gmail.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-06 2:53 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05 2:22 [PATCH net-next] selftests: net: tcp_ao: test listen socket RST to a v4-mapped peer Hungyu Lin
2026-12-06 2:53 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox