* [PATCH net 0/4] selftests/net/tcp_ao: A bunch of fixes for TCP-AO selftests
@ 2024-04-13 1:42 Dmitry Safonov
2024-04-13 1:42 ` [PATCH net 1/4] selftests/tcp_ao: Make RST tests less flaky Dmitry Safonov
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Dmitry Safonov @ 2024-04-13 1:42 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Shuah Khan
Cc: netdev, linux-kselftest, linux-kernel, Dmitry Safonov
Started as addressing the flakiness issues in rst_ipv*, that affect
netdev dashboard.
Signed-off-by: Dmitry Safonov <0x7f454c46@gmail.com>
---
Dmitry Safonov (4):
selftests/tcp_ao: Make RST tests less flaky
selftests/tcp_ao: Zero-init tcp_ao_info_opt
selftests/tcp_ao: Fix fscanf() call for format-security
selftests/tcp_ao: Printing fixes to confirm with format-security
tools/testing/selftests/net/tcp_ao/lib/proc.c | 2 +-
tools/testing/selftests/net/tcp_ao/lib/setup.c | 12 +++++------
tools/testing/selftests/net/tcp_ao/rst.c | 23 ++++++++++++----------
.../selftests/net/tcp_ao/setsockopt-closed.c | 2 +-
4 files changed, 21 insertions(+), 18 deletions(-)
---
base-commit: 8f2c057754b25075aa3da132cd4fd4478cdab854
change-id: 20240413-tcp-ao-selftests-fixes-adacd65cb8ba
Best regards,
--
Dmitry Safonov <0x7f454c46@gmail.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH net 1/4] selftests/tcp_ao: Make RST tests less flaky
2024-04-13 1:42 [PATCH net 0/4] selftests/net/tcp_ao: A bunch of fixes for TCP-AO selftests Dmitry Safonov
@ 2024-04-13 1:42 ` Dmitry Safonov
2024-04-13 1:42 ` [PATCH net 2/4] selftests/tcp_ao: Zero-init tcp_ao_info_opt Dmitry Safonov
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Dmitry Safonov @ 2024-04-13 1:42 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Shuah Khan
Cc: netdev, linux-kselftest, linux-kernel, Dmitry Safonov
Currently, "active reset" cases are flaky, because select() is called
for 3 sockets, while only 2 are expected to receive RST.
The idea of the third socket was to get into request_sock_queue,
but the test mistakenly attempted to connect() after the listener
socket was shut down.
Repair this test, it's important to check the different kernel
code-paths for signing RST TCP-AO segments.
Fixes: c6df7b2361d7 ("selftests/net: Add TCP-AO RST test")
Reported-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Dmitry Safonov <0x7f454c46@gmail.com>
---
tools/testing/selftests/net/tcp_ao/rst.c | 23 +++++++++++++----------
1 file changed, 13 insertions(+), 10 deletions(-)
diff --git a/tools/testing/selftests/net/tcp_ao/rst.c b/tools/testing/selftests/net/tcp_ao/rst.c
index 7df8b8700e39..a2fe88d35ac0 100644
--- a/tools/testing/selftests/net/tcp_ao/rst.c
+++ b/tools/testing/selftests/net/tcp_ao/rst.c
@@ -256,8 +256,6 @@ static int test_wait_fds(int sk[], size_t nr, bool is_writable[],
static void test_client_active_rst(unsigned int port)
{
- /* one in queue, another accept()ed */
- unsigned int wait_for = backlog + 2;
int i, sk[3], err;
bool is_writable[ARRAY_SIZE(sk)] = {false};
unsigned int last = ARRAY_SIZE(sk) - 1;
@@ -275,16 +273,20 @@ static void test_client_active_rst(unsigned int port)
for (i = 0; i < last; i++) {
err = _test_connect_socket(sk[i], this_ip_dest, port,
(i == 0) ? TEST_TIMEOUT_SEC : -1);
-
if (err < 0)
test_error("failed to connect()");
}
- synchronize_threads(); /* 2: connection accept()ed, another queued */
- err = test_wait_fds(sk, last, is_writable, wait_for, TEST_TIMEOUT_SEC);
+ synchronize_threads(); /* 2: two connections: one accept()ed, another queued */
+ err = test_wait_fds(sk, last, is_writable, last, TEST_TIMEOUT_SEC);
if (err < 0)
test_error("test_wait_fds(): %d", err);
+ /* async connect() with third sk to get into request_sock_queue */
+ err = _test_connect_socket(sk[last], this_ip_dest, port, -1);
+ if (err < 0)
+ test_error("failed to connect()");
+
synchronize_threads(); /* 3: close listen socket */
if (test_client_verify(sk[0], packet_sz, quota / packet_sz, TEST_TIMEOUT_SEC))
test_fail("Failed to send data on connected socket");
@@ -292,13 +294,14 @@ static void test_client_active_rst(unsigned int port)
test_ok("Verified established tcp connection");
synchronize_threads(); /* 4: finishing up */
- err = _test_connect_socket(sk[last], this_ip_dest, port, -1);
- if (err < 0)
- test_error("failed to connect()");
synchronize_threads(); /* 5: closed active sk */
- err = test_wait_fds(sk, ARRAY_SIZE(sk), NULL,
- wait_for, TEST_TIMEOUT_SEC);
+ /*
+ * Wait for 2 connections: one accepted, another in the accept queue,
+ * the one in request_sock_queue won't get fully established, so
+ * doesn't receive an active RST, see inet_csk_listen_stop().
+ */
+ err = test_wait_fds(sk, last, NULL, last, TEST_TIMEOUT_SEC);
if (err < 0)
test_error("select(): %d", err);
--
2.42.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH net 2/4] selftests/tcp_ao: Zero-init tcp_ao_info_opt
2024-04-13 1:42 [PATCH net 0/4] selftests/net/tcp_ao: A bunch of fixes for TCP-AO selftests Dmitry Safonov
2024-04-13 1:42 ` [PATCH net 1/4] selftests/tcp_ao: Make RST tests less flaky Dmitry Safonov
@ 2024-04-13 1:42 ` Dmitry Safonov
2024-04-13 1:42 ` [PATCH net 3/4] selftests/tcp_ao: Fix fscanf() call for format-security Dmitry Safonov
2024-04-13 1:42 ` [PATCH net 4/4] selftests/tcp_ao: Printing fixes to confirm with format-security Dmitry Safonov
3 siblings, 0 replies; 5+ messages in thread
From: Dmitry Safonov @ 2024-04-13 1:42 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Shuah Khan
Cc: netdev, linux-kselftest, linux-kernel, Dmitry Safonov
The structure is on the stack and has to be zero-initialized as
the kernel checks for:
> if (in.reserved != 0 || in.reserved2 != 0)
> return -EINVAL;
Fixes: b26660531cf6 ("selftests/net: Add test for TCP-AO add setsockopt() command")
Signed-off-by: Dmitry Safonov <0x7f454c46@gmail.com>
---
tools/testing/selftests/net/tcp_ao/setsockopt-closed.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/net/tcp_ao/setsockopt-closed.c b/tools/testing/selftests/net/tcp_ao/setsockopt-closed.c
index 452de131fa3a..517930f9721b 100644
--- a/tools/testing/selftests/net/tcp_ao/setsockopt-closed.c
+++ b/tools/testing/selftests/net/tcp_ao/setsockopt-closed.c
@@ -21,7 +21,7 @@ static void make_listen(int sk)
static void test_vefify_ao_info(int sk, struct tcp_ao_info_opt *info,
const char *tst)
{
- struct tcp_ao_info_opt tmp;
+ struct tcp_ao_info_opt tmp = {};
socklen_t len = sizeof(tmp);
if (getsockopt(sk, IPPROTO_TCP, TCP_AO_INFO, &tmp, &len))
--
2.42.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH net 3/4] selftests/tcp_ao: Fix fscanf() call for format-security
2024-04-13 1:42 [PATCH net 0/4] selftests/net/tcp_ao: A bunch of fixes for TCP-AO selftests Dmitry Safonov
2024-04-13 1:42 ` [PATCH net 1/4] selftests/tcp_ao: Make RST tests less flaky Dmitry Safonov
2024-04-13 1:42 ` [PATCH net 2/4] selftests/tcp_ao: Zero-init tcp_ao_info_opt Dmitry Safonov
@ 2024-04-13 1:42 ` Dmitry Safonov
2024-04-13 1:42 ` [PATCH net 4/4] selftests/tcp_ao: Printing fixes to confirm with format-security Dmitry Safonov
3 siblings, 0 replies; 5+ messages in thread
From: Dmitry Safonov @ 2024-04-13 1:42 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Shuah Khan
Cc: netdev, linux-kselftest, linux-kernel, Dmitry Safonov
On my new laptop with packages from nixos-unstable, gcc 12.3.0 produces:
> lib/proc.c: In function ‘netstat_read_type’:
> lib/proc.c:89:9: error: format not a string literal and no format arguments [-Werror=format-security]
> 89 | if (fscanf(fnetstat, type->header_name) == EOF)
> | ^~
> cc1: some warnings being treated as errors
Here the selftests lib parses header name, while expectes non-space word
ending with a column.
Fixes: cfbab37b3da0 ("selftests/net: Add TCP-AO library")
Signed-off-by: Dmitry Safonov <0x7f454c46@gmail.com>
---
tools/testing/selftests/net/tcp_ao/lib/proc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/net/tcp_ao/lib/proc.c b/tools/testing/selftests/net/tcp_ao/lib/proc.c
index 2fb6dd8adba6..8b984fa04286 100644
--- a/tools/testing/selftests/net/tcp_ao/lib/proc.c
+++ b/tools/testing/selftests/net/tcp_ao/lib/proc.c
@@ -86,7 +86,7 @@ static void netstat_read_type(FILE *fnetstat, struct netstat **dest, char *line)
pos = strchr(line, ' ') + 1;
- if (fscanf(fnetstat, type->header_name) == EOF)
+ if (fscanf(fnetstat, "%[^ :]", type->header_name) == EOF)
test_error("fscanf(%s)", type->header_name);
if (fread(&tmp, 1, 1, fnetstat) != 1 || tmp != ':')
test_error("Unexpected netstat format (%c)", tmp);
--
2.42.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH net 4/4] selftests/tcp_ao: Printing fixes to confirm with format-security
2024-04-13 1:42 [PATCH net 0/4] selftests/net/tcp_ao: A bunch of fixes for TCP-AO selftests Dmitry Safonov
` (2 preceding siblings ...)
2024-04-13 1:42 ` [PATCH net 3/4] selftests/tcp_ao: Fix fscanf() call for format-security Dmitry Safonov
@ 2024-04-13 1:42 ` Dmitry Safonov
3 siblings, 0 replies; 5+ messages in thread
From: Dmitry Safonov @ 2024-04-13 1:42 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Shuah Khan
Cc: netdev, linux-kselftest, linux-kernel, Dmitry Safonov
On my new laptop with packages from nixos-unstable, gcc 12.3.0 produces
> lib/setup.c: In function ‘__test_msg’:
> lib/setup.c:20:9: error: format not a string literal and no format arguments [-Werror=format-security]
> 20 | ksft_print_msg(buf);
> | ^~~~~~~~~~~~~~
> lib/setup.c: In function ‘__test_ok’:
> lib/setup.c:26:9: error: format not a string literal and no format arguments [-Werror=format-security]
> 26 | ksft_test_result_pass(buf);
> | ^~~~~~~~~~~~~~~~~~~~~
> lib/setup.c: In function ‘__test_fail’:
> lib/setup.c:32:9: error: format not a string literal and no format arguments [-Werror=format-security]
> 32 | ksft_test_result_fail(buf);
> | ^~~~~~~~~~~~~~~~~~~~~
> lib/setup.c: In function ‘__test_xfail’:
> lib/setup.c:38:9: error: format not a string literal and no format arguments [-Werror=format-security]
> 38 | ksft_test_result_xfail(buf);
> | ^~~~~~~~~~~~~~~~~~~~~~
> lib/setup.c: In function ‘__test_error’:
> lib/setup.c:44:9: error: format not a string literal and no format arguments [-Werror=format-security]
> 44 | ksft_test_result_error(buf);
> | ^~~~~~~~~~~~~~~~~~~~~~
> lib/setup.c: In function ‘__test_skip’:
> lib/setup.c:50:9: error: format not a string literal and no format arguments [-Werror=format-security]
> 50 | ksft_test_result_skip(buf);
> | ^~~~~~~~~~~~~~~~~~~~~
> cc1: some warnings being treated as errors
As the buffer was already pre-printed into, print it as a string
rather than a format-string.
Fixes: cfbab37b3da0 ("selftests/net: Add TCP-AO library")
Signed-off-by: Dmitry Safonov <0x7f454c46@gmail.com>
---
tools/testing/selftests/net/tcp_ao/lib/setup.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/tools/testing/selftests/net/tcp_ao/lib/setup.c b/tools/testing/selftests/net/tcp_ao/lib/setup.c
index 92276f916f2f..e408b9243b2c 100644
--- a/tools/testing/selftests/net/tcp_ao/lib/setup.c
+++ b/tools/testing/selftests/net/tcp_ao/lib/setup.c
@@ -17,37 +17,37 @@ static pthread_mutex_t ksft_print_lock = PTHREAD_MUTEX_INITIALIZER;
void __test_msg(const char *buf)
{
pthread_mutex_lock(&ksft_print_lock);
- ksft_print_msg(buf);
+ ksft_print_msg("%s", buf);
pthread_mutex_unlock(&ksft_print_lock);
}
void __test_ok(const char *buf)
{
pthread_mutex_lock(&ksft_print_lock);
- ksft_test_result_pass(buf);
+ ksft_test_result_pass("%s", buf);
pthread_mutex_unlock(&ksft_print_lock);
}
void __test_fail(const char *buf)
{
pthread_mutex_lock(&ksft_print_lock);
- ksft_test_result_fail(buf);
+ ksft_test_result_fail("%s", buf);
pthread_mutex_unlock(&ksft_print_lock);
}
void __test_xfail(const char *buf)
{
pthread_mutex_lock(&ksft_print_lock);
- ksft_test_result_xfail(buf);
+ ksft_test_result_xfail("%s", buf);
pthread_mutex_unlock(&ksft_print_lock);
}
void __test_error(const char *buf)
{
pthread_mutex_lock(&ksft_print_lock);
- ksft_test_result_error(buf);
+ ksft_test_result_error("%s", buf);
pthread_mutex_unlock(&ksft_print_lock);
}
void __test_skip(const char *buf)
{
pthread_mutex_lock(&ksft_print_lock);
- ksft_test_result_skip(buf);
+ ksft_test_result_skip("%s", buf);
pthread_mutex_unlock(&ksft_print_lock);
}
--
2.42.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-04-13 1:42 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-13 1:42 [PATCH net 0/4] selftests/net/tcp_ao: A bunch of fixes for TCP-AO selftests Dmitry Safonov
2024-04-13 1:42 ` [PATCH net 1/4] selftests/tcp_ao: Make RST tests less flaky Dmitry Safonov
2024-04-13 1:42 ` [PATCH net 2/4] selftests/tcp_ao: Zero-init tcp_ao_info_opt Dmitry Safonov
2024-04-13 1:42 ` [PATCH net 3/4] selftests/tcp_ao: Fix fscanf() call for format-security Dmitry Safonov
2024-04-13 1:42 ` [PATCH net 4/4] selftests/tcp_ao: Printing fixes to confirm with format-security Dmitry Safonov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).