]> git.baikalelectronics.ru Git - kernel.git/commitdiff
selftests: tls: test for correct proto_ops
authorJakub Kicinski <kuba@kernel.org>
Wed, 24 Nov 2021 23:25:57 +0000 (15:25 -0800)
committerJakub Kicinski <kuba@kernel.org>
Fri, 26 Nov 2021 03:28:17 +0000 (19:28 -0800)
Previous patch fixes overriding callbacks incorrectly. Triggering
the crash in sendpage_locked would be more spectacular but it's
hard to get to, so take the easier path of proving this is broken
and call getname. We're currently getting IPv4 socket info on an
IPv6 socket.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/testing/selftests/net/tls.c

index 6e78d7207cc1416547fe8c96672a5b6b311cab21..8a22db0cca496a62d4b452d6fc190cb13f60f99f 100644 (file)
@@ -1617,4 +1617,59 @@ TEST(keysizes) {
        close(cfd);
 }
 
+TEST(tls_v6ops) {
+       struct tls_crypto_info_keys tls12;
+       struct sockaddr_in6 addr, addr2;
+       int sfd, ret, fd;
+       socklen_t len, len2;
+
+       tls_crypto_info_init(TLS_1_2_VERSION, TLS_CIPHER_AES_GCM_128, &tls12);
+
+       addr.sin6_family = AF_INET6;
+       addr.sin6_addr = in6addr_any;
+       addr.sin6_port = 0;
+
+       fd = socket(AF_INET6, SOCK_STREAM, 0);
+       sfd = socket(AF_INET6, SOCK_STREAM, 0);
+
+       ret = bind(sfd, &addr, sizeof(addr));
+       ASSERT_EQ(ret, 0);
+       ret = listen(sfd, 10);
+       ASSERT_EQ(ret, 0);
+
+       len = sizeof(addr);
+       ret = getsockname(sfd, &addr, &len);
+       ASSERT_EQ(ret, 0);
+
+       ret = connect(fd, &addr, sizeof(addr));
+       ASSERT_EQ(ret, 0);
+
+       len = sizeof(addr);
+       ret = getsockname(fd, &addr, &len);
+       ASSERT_EQ(ret, 0);
+
+       ret = setsockopt(fd, IPPROTO_TCP, TCP_ULP, "tls", sizeof("tls"));
+       if (ret) {
+               ASSERT_EQ(errno, ENOENT);
+               SKIP(return, "no TLS support");
+       }
+       ASSERT_EQ(ret, 0);
+
+       ret = setsockopt(fd, SOL_TLS, TLS_TX, &tls12, tls12.len);
+       ASSERT_EQ(ret, 0);
+
+       ret = setsockopt(fd, SOL_TLS, TLS_RX, &tls12, tls12.len);
+       ASSERT_EQ(ret, 0);
+
+       len2 = sizeof(addr2);
+       ret = getsockname(fd, &addr2, &len2);
+       ASSERT_EQ(ret, 0);
+
+       EXPECT_EQ(len2, len);
+       EXPECT_EQ(memcmp(&addr, &addr2, len), 0);
+
+       close(fd);
+       close(sfd);
+}
+
 TEST_HARNESS_MAIN