]> www.infradead.org Git - users/willy/pagecache.git/commitdiff
vsock/test: Add test for SO_LINGER null ptr deref
authorMichal Luczaj <mhal@rbox.co>
Mon, 10 Feb 2025 12:15:01 +0000 (13:15 +0100)
committerJakub Kicinski <kuba@kernel.org>
Thu, 13 Feb 2025 04:01:29 +0000 (20:01 -0800)
Explicitly close() a TCP_ESTABLISHED (connectible) socket with SO_LINGER
enabled.

As for now, test does not verify if close() actually lingers.
On an unpatched machine, may trigger a null pointer dereference.

Tested-by: Luigi Leonardi <leonardi@redhat.com>
Reviewed-by: Luigi Leonardi <leonardi@redhat.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: Michal Luczaj <mhal@rbox.co>
Link: https://patch.msgid.link/20250210-vsock-linger-nullderef-v3-2-ef6244d02b54@rbox.co
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/testing/vsock/vsock_test.c

index dfff8b288265f96b602cb1bfa0e6dce02f114222..d0f6d253ac72d08a957cb81a3c38fcc72bec5a53 100644 (file)
@@ -1788,6 +1788,42 @@ static void test_stream_connect_retry_server(const struct test_opts *opts)
        close(fd);
 }
 
+static void test_stream_linger_client(const struct test_opts *opts)
+{
+       struct linger optval = {
+               .l_onoff = 1,
+               .l_linger = 1
+       };
+       int fd;
+
+       fd = vsock_stream_connect(opts->peer_cid, opts->peer_port);
+       if (fd < 0) {
+               perror("connect");
+               exit(EXIT_FAILURE);
+       }
+
+       if (setsockopt(fd, SOL_SOCKET, SO_LINGER, &optval, sizeof(optval))) {
+               perror("setsockopt(SO_LINGER)");
+               exit(EXIT_FAILURE);
+       }
+
+       close(fd);
+}
+
+static void test_stream_linger_server(const struct test_opts *opts)
+{
+       int fd;
+
+       fd = vsock_stream_accept(VMADDR_CID_ANY, opts->peer_port, NULL);
+       if (fd < 0) {
+               perror("accept");
+               exit(EXIT_FAILURE);
+       }
+
+       vsock_wait_remote_close(fd);
+       close(fd);
+}
+
 static struct test_case test_cases[] = {
        {
                .name = "SOCK_STREAM connection reset",
@@ -1943,6 +1979,11 @@ static struct test_case test_cases[] = {
                .run_client = test_stream_connect_retry_client,
                .run_server = test_stream_connect_retry_server,
        },
+       {
+               .name = "SOCK_STREAM SO_LINGER null-ptr-deref",
+               .run_client = test_stream_linger_client,
+               .run_server = test_stream_linger_server,
+       },
        {},
 };