Skip to content

Commit 440c9d4

Browse files
mmhalkuba-moo
authored andcommitted
vsock/test: Add test for SO_LINGER null ptr deref
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 <[email protected]> Reviewed-by: Luigi Leonardi <[email protected]> Reviewed-by: Stefano Garzarella <[email protected]> Signed-off-by: Michal Luczaj <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 78dafe1 commit 440c9d4

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

tools/testing/vsock/vsock_test.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,6 +1788,42 @@ static void test_stream_connect_retry_server(const struct test_opts *opts)
17881788
close(fd);
17891789
}
17901790

1791+
static void test_stream_linger_client(const struct test_opts *opts)
1792+
{
1793+
struct linger optval = {
1794+
.l_onoff = 1,
1795+
.l_linger = 1
1796+
};
1797+
int fd;
1798+
1799+
fd = vsock_stream_connect(opts->peer_cid, opts->peer_port);
1800+
if (fd < 0) {
1801+
perror("connect");
1802+
exit(EXIT_FAILURE);
1803+
}
1804+
1805+
if (setsockopt(fd, SOL_SOCKET, SO_LINGER, &optval, sizeof(optval))) {
1806+
perror("setsockopt(SO_LINGER)");
1807+
exit(EXIT_FAILURE);
1808+
}
1809+
1810+
close(fd);
1811+
}
1812+
1813+
static void test_stream_linger_server(const struct test_opts *opts)
1814+
{
1815+
int fd;
1816+
1817+
fd = vsock_stream_accept(VMADDR_CID_ANY, opts->peer_port, NULL);
1818+
if (fd < 0) {
1819+
perror("accept");
1820+
exit(EXIT_FAILURE);
1821+
}
1822+
1823+
vsock_wait_remote_close(fd);
1824+
close(fd);
1825+
}
1826+
17911827
static struct test_case test_cases[] = {
17921828
{
17931829
.name = "SOCK_STREAM connection reset",
@@ -1943,6 +1979,11 @@ static struct test_case test_cases[] = {
19431979
.run_client = test_stream_connect_retry_client,
19441980
.run_server = test_stream_connect_retry_server,
19451981
},
1982+
{
1983+
.name = "SOCK_STREAM SO_LINGER null-ptr-deref",
1984+
.run_client = test_stream_linger_client,
1985+
.run_server = test_stream_linger_server,
1986+
},
19461987
{},
19471988
};
19481989

0 commit comments

Comments
 (0)