Skip to content

Commit a1328a6

Browse files
kuba-mooPaolo Abeni
authored andcommitted
selftests: tls: check that disconnect does nothing
"Inspired" by syzbot test, pre-queue some data, disconnect() and try to receive(). This used to trigger a warning in TLS's strp. Now we expect the disconnect() to have almost no effect. Link: https://lore.kernel.org/67e6be74.050a0220.2f068f.007e.GAE@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Reviewed-by: Sabrina Dubroca <sd@queasysnail.net> Link: https://patch.msgid.link/20250404180334.3224206-2-kuba@kernel.org Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent 5071a1e commit a1328a6

File tree

1 file changed

+36
-0
lines changed
  • tools/testing/selftests/net

1 file changed

+36
-0
lines changed

tools/testing/selftests/net/tls.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,6 +1753,42 @@ TEST_F(tls_basic, rekey_tx)
17531753
EXPECT_EQ(memcmp(buf, test_str, send_len), 0);
17541754
}
17551755

1756+
TEST_F(tls_basic, disconnect)
1757+
{
1758+
char const *test_str = "test_message";
1759+
int send_len = strlen(test_str) + 1;
1760+
struct tls_crypto_info_keys key;
1761+
struct sockaddr_in addr;
1762+
char buf[20];
1763+
int ret;
1764+
1765+
if (self->notls)
1766+
return;
1767+
1768+
tls_crypto_info_init(TLS_1_3_VERSION, TLS_CIPHER_AES_GCM_128,
1769+
&key, 0);
1770+
1771+
ret = setsockopt(self->fd, SOL_TLS, TLS_TX, &key, key.len);
1772+
ASSERT_EQ(ret, 0);
1773+
1774+
/* Pre-queue the data so that setsockopt parses it but doesn't
1775+
* dequeue it from the TCP socket. recvmsg would dequeue.
1776+
*/
1777+
EXPECT_EQ(send(self->fd, test_str, send_len, 0), send_len);
1778+
1779+
ret = setsockopt(self->cfd, SOL_TLS, TLS_RX, &key, key.len);
1780+
ASSERT_EQ(ret, 0);
1781+
1782+
addr.sin_family = AF_UNSPEC;
1783+
addr.sin_addr.s_addr = htonl(INADDR_ANY);
1784+
addr.sin_port = 0;
1785+
ret = connect(self->cfd, &addr, sizeof(addr));
1786+
EXPECT_EQ(ret, -1);
1787+
EXPECT_EQ(errno, EOPNOTSUPP);
1788+
1789+
EXPECT_EQ(recv(self->cfd, buf, send_len, 0), send_len);
1790+
}
1791+
17561792
TEST_F(tls, rekey)
17571793
{
17581794
char const *test_str_1 = "test_message_before_rekey";

0 commit comments

Comments
 (0)