Skip to contentSkip to conversation

vsock/test: fix failures due to wrong SO_RCVLOWAT parameter

PATCH Superseded Konstantin Shkolnyy 2 participants 2 messages Oct 24, 2024 – Oct 25, 2024

Subsystems (4)

v2 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 vsock/test: fix failures due to wrong SO_RCVLOWAT parameter

This happens on 64-bit big-endian machines.
SO_RCVLOWAT requires an int parameter. However, instead of int, the test uses unsigned long in one place and size_t in another. Both are 8 bytes long on 64-bit machines. The kernel, having received the 8 bytes, doesn't test for the exact size of the parameter, it only cares that it's >= sizeof(int), and casts the 4 lower-addressed bytes to an int, which, on a big-endian machine, contains 0. 0 doesn't trigger an error, SO_RCVLOWAT returns with success and the socket stays with the default SO_RCVLOWAT = 1, which results in test failures.

Fixes b1346338fbae ("vsock_test: POLLIN + SO_RCVLOWAT test")
Fixes 542e893fbadc ("vsock/test: two tests to check credit update logic")

---

Notes:
The problem was found on s390 (big endian), while x86-64 didn't show it. After this fix, all tests pass on s390.
Changes for v2:
- add "Fixes:" lines to the commit message

 tools/testing/vsock/vsock_test.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/vsock/vsock_test.c +2 -2
index 8d38dbf8f41f..7fd25b814b4b 100644
@@ -835,7 +835,7 @@ static void test_stream_poll_rcvlowat_server(const struct test_opts *opts)
 
 static void test_stream_poll_rcvlowat_client(const struct test_opts *opts)
 {
-	unsigned long lowat_val = RCVLOWAT_BUF_SIZE;
+	int lowat_val = RCVLOWAT_BUF_SIZE;
 	char buf[RCVLOWAT_BUF_SIZE];
 	struct pollfd fds;
 	short poll_flags;
@@ -1357,7 +1357,7 @@ static void test_stream_rcvlowat_def_cred_upd_client(const struct test_opts *opt
 static void test_stream_credit_update_test(const struct test_opts *opts,
 					   bool low_rx_bytes_test)
 {
-	size_t recv_buf_size;
+	int recv_buf_size;
 	struct pollfd fds;
 	size_t buf_size;
 	void *buf;
Signature · 1 line
2.34.1
maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 13 lines · Konstantin Shkolnyy

This happens on 64-bit big-endian machines.
SO_RCVLOWAT requires an int parameter. However, instead of int, the test uses unsigned long in one place and size_t in another. Both are 8 bytes long on 64-bit machines. The kernel, having received the 8 bytes, doesn't test for the exact size of the parameter, it only cares that it's >= sizeof(int), and casts the 4 lower-addressed bytes to an int, which, on a big-endian machine, contains 0. 0 doesn't trigger an error, SO_RCVLOWAT returns with success and the socket stays with the default SO_RCVLOWAT = 1, which results in test failures.

Fixes b1346338fbae ("vsock_test: POLLIN + SO_RCVLOWAT test")
Fixes 542e893fbadc ("vsock/test: two tests to check credit update logic")
Quoted 6 lines

---

Notes:
The problem was found on s390 (big endian), while x86-64 didn't show it. After this fix, all tests pass on s390.
Changes for v2:
- add "Fixes:" lines to the commit message

LGTM!

Quoted 29 lines

tools/testing/vsock/vsock_test.c | 4 ++--

1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/vsock/vsock_test.c +2 -2
index 8d38dbf8f41f..7fd25b814b4b 100644
@@ -835,7 +835,7 @@ static void test_stream_poll_rcvlowat_server(const struct test_opts *opts)
 
 static void test_stream_poll_rcvlowat_client(const struct test_opts *opts)
 {
-	unsigned long lowat_val = RCVLOWAT_BUF_SIZE;
+	int lowat_val = RCVLOWAT_BUF_SIZE;
 	char buf[RCVLOWAT_BUF_SIZE];
 	struct pollfd fds;
 	short poll_flags;
@@ -1357,7 +1357,7 @@ static void test_stream_rcvlowat_def_cred_upd_client(const struct test_opts *opt
 static void test_stream_credit_update_test(const struct test_opts *opts,
 					   bool low_rx_bytes_test)
 {
-	size_t recv_buf_size;
+	int recv_buf_size;
 	struct pollfd fds;
 	size_t buf_size;
 	void *buf;
Signature · 1 line
2.34.1