From: Eric Dumazet <edumazet@google.com>
To: "David S . Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>
Cc: Simon Horman <horms@kernel.org>,
Dmitry Safonov <0x7f454c46@gmail.com>,
Neal Cardwell <ncardwell@google.com>,
Kuniyuki Iwashima <kuniyu@google.com>,
netdev@vger.kernel.org, eric.dumazet@gmail.com,
Eric Dumazet <edumazet@google.com>
Subject: [PATCH net 2/2] selftests/net: Add TCP-AO key shadowing test
Date: Mon, 22 Jun 2026 18:52:48 +0000 [thread overview]
Message-ID: <20260622185248.1717846-3-edumazet@google.com> (raw)
In-Reply-To: <20260622185248.1717846-1-edumazet@google.com>
Add a new selftest shadowing.c to tools/testing/selftests/net/tcp_ao
to verify that more specific keys are correctly preferred over less
specific ones (shadowing prevention), regardless of their insertion order.
The test configures a server with a specific host key, and a client with
both a specific host key and a wildcard subnet key, inserted in the
"wrong" order (wildcard last, which would shadow the specific one under
the bug). It then verifies that the client can still successfully
connect to the server, which only succeeds if the client correctly
selects the more specific key for the outbound connection.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Assisted-by: Gemini:gemini-3.1-pro
---
tools/testing/selftests/net/tcp_ao/Makefile | 1 +
.../testing/selftests/net/tcp_ao/shadowing.c | 93 +++++++++++++++++++
2 files changed, 94 insertions(+)
create mode 100644 tools/testing/selftests/net/tcp_ao/shadowing.c
diff --git a/tools/testing/selftests/net/tcp_ao/Makefile b/tools/testing/selftests/net/tcp_ao/Makefile
index 5b0205c70c3983815315048c0ec1275525b7a29a..0c601d7049320be2310f9ff32988ae229584222e 100644
--- a/tools/testing/selftests/net/tcp_ao/Makefile
+++ b/tools/testing/selftests/net/tcp_ao/Makefile
@@ -2,6 +2,7 @@
TEST_BOTH_AF := bench-lookups
TEST_BOTH_AF += connect
TEST_BOTH_AF += connect-deny
+TEST_BOTH_AF += shadowing
TEST_BOTH_AF += icmps-accept icmps-discard
TEST_BOTH_AF += key-management
TEST_BOTH_AF += restore
diff --git a/tools/testing/selftests/net/tcp_ao/shadowing.c b/tools/testing/selftests/net/tcp_ao/shadowing.c
new file mode 100644
index 0000000000000000000000000000000000000000..da14b13e032d5a0632f398b7eaa72b8045e61ffe
--- /dev/null
+++ b/tools/testing/selftests/net/tcp_ao/shadowing.c
@@ -0,0 +1,93 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <inttypes.h>
+#include "aolib.h"
+
+static void *server_fn(void *arg)
+{
+ int sk, lsk;
+ ssize_t bytes;
+
+ lsk = test_listen_socket(this_ip_addr, test_server_port, 1);
+
+ /* Server only has the specific key for the client.
+ * It expects KeyID 100, signed with "pass_specific".
+ */
+ if (test_add_key(lsk, "pass_specific", this_ip_dest, -1, 100, 100))
+ test_error("setsockopt(TCP_AO_ADD_KEY)");
+
+ synchronize_threads(); /* 1: Server ready and key added */
+
+ 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()");
+
+ synchronize_threads(); /* 2: Connection accepted */
+
+ /* Verify we can receive data from the client */
+ bytes = test_server_run(sk, 0, 0);
+ if (bytes < 0) {
+ test_fail("server: failed to receive data");
+ } else {
+ test_ok("server: connection authenticated successfully");
+ }
+
+ close(sk);
+ close(lsk);
+ return NULL;
+}
+
+static void *client_fn(void *arg)
+{
+ int sk = socket(test_family, SOCK_STREAM, IPPROTO_TCP);
+ union tcp_addr wildcard_addr = {};
+
+ if (sk < 0)
+ test_error("socket()");
+
+ /* Client adds keys in the "wrong" order (wildcard last) to trigger shadowing.
+ * 1. Specific key (Key B, ID 100)
+ * 2. Wildcard key (Key A, ID 101)
+ *
+ * Without the fix, the wildcard key will be at the head of the list
+ * and will shadow the specific key during outbound lookup, causing
+ * the client to send a SYN with KeyID 101 (which the server doesn't have).
+ */
+
+ /* 1. Add specific key */
+ if (test_add_key(sk, "pass_specific", this_ip_dest, -1, 100, 100))
+ test_error("setsockopt(TCP_AO_ADD_KEY) specific");
+
+ /* 2. Add wildcard key (any address, prefix 0) */
+ if (test_add_key(sk, "pass_wildcard", wildcard_addr, 0, 101, 101))
+ test_error("setsockopt(TCP_AO_ADD_KEY) wildcard");
+
+ synchronize_threads(); /* 1: Client ready and keys added => connect() */
+
+ if (test_connect_socket(sk, this_ip_dest, test_server_port) <= 0) {
+ test_fail("client: failed to connect (shadowing bug present?)");
+ close(sk);
+ return NULL;
+ }
+
+ synchronize_threads(); /* 2: Connection established */
+
+ /* Send some data to verify the connection works */
+ if (test_client_verify(sk, 100, 20)) {
+ test_fail("client: verify failed");
+ } else {
+ test_ok("client: connection established and verified (precedence correct)");
+ }
+
+ close(sk);
+ return NULL;
+}
+
+int main(int argc, char *argv[])
+{
+ /* We expect 2 test results: 1 from server, 1 from client */
+ test_init(2, server_fn, client_fn);
+ return 0;
+}
--
2.55.0.rc0.799.gd6f94ed593-goog
prev parent reply other threads:[~2026-06-22 18:52 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-22 18:52 [PATCH net 0/2] tcp: make TCP-AO lookups more predictable Eric Dumazet
2026-06-22 18:52 ` [PATCH net 1/2] tcp: fix TCP-AO key lookup precedence (shadowing) Eric Dumazet
2026-06-22 18:52 ` Eric Dumazet [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=20260622185248.1717846-3-edumazet@google.com \
--to=edumazet@google.com \
--cc=0x7f454c46@gmail.com \
--cc=davem@davemloft.net \
--cc=eric.dumazet@gmail.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=ncardwell@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox