From nobody Mon Nov 15 20:03:56 2021 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id CAE911889BCB; Mon, 15 Nov 2021 20:03:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HtKrs1c7mz3DB8; Mon, 15 Nov 2021 20:03:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id C3CE91FDDC; Mon, 15 Nov 2021 20:03:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1AFK3uQm087871; Mon, 15 Nov 2021 20:03:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1AFK3uON087870; Mon, 15 Nov 2021 20:03:56 GMT (envelope-from git) Date: Mon, 15 Nov 2021 20:03:56 GMT Message-Id: <202111152003.1AFK3uON087870@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: 83a54b582f89 - main - ktls: Add tests ensuring unsupported receive cipher suites are rejected. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 83a54b582f89ff63f9076eb7d50b5cdbd009905f Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=83a54b582f89ff63f9076eb7d50b5cdbd009905f commit 83a54b582f89ff63f9076eb7d50b5cdbd009905f Author: John Baldwin AuthorDate: 2021-11-15 19:32:49 +0000 Commit: John Baldwin CommitDate: 2021-11-15 19:32:49 +0000 ktls: Add tests ensuring unsupported receive cipher suites are rejected. Reviewed by: markj Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D32982 --- tests/sys/kern/ktls_test.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/tests/sys/kern/ktls_test.c b/tests/sys/kern/ktls_test.c index 5aea56baa91f..21e3213a8634 100644 --- a/tests/sys/kern/ktls_test.c +++ b/tests/sys/kern/ktls_test.c @@ -1237,6 +1237,14 @@ test_ktls_receive_app_data(struct tls_enable *en, uint64_t seqno, size_t len) M(chacha20_poly1305_1_2, CRYPTO_CHACHA20_POLY1305, 256 / 8, 0, \ TLS_MINOR_VER_TWO) +#define TLS_13_TESTS(M) \ + M(aes128_gcm_1_3, CRYPTO_AES_NIST_GCM_16, 128 / 8, 0, \ + TLS_MINOR_VER_THREE) \ + M(aes256_gcm_1_3, CRYPTO_AES_NIST_GCM_16, 256 / 8, 0, \ + TLS_MINOR_VER_THREE) \ + M(chacha20_poly1305_1_3, CRYPTO_CHACHA20_POLY1305, 256 / 8, 0, \ + TLS_MINOR_VER_THREE) + #define AES_CBC_TESTS(M) \ M(aes128_cbc_1_0_sha1, CRYPTO_AES_CBC, 128 / 8, \ CRYPTO_SHA1_HMAC, TLS_MINOR_VER_ZERO) \ @@ -1612,6 +1620,48 @@ ATF_TC_BODY(ktls_receive_invalid_##name, tc) \ */ INVALID_CIPHER_SUITES(GEN_INVALID_RECEIVE_TEST); +static void +test_ktls_unsupported_receive_cipher_suite(struct tls_enable *en) +{ + int sockets[2]; + + ATF_REQUIRE_MSG(socketpair_tcp(sockets), "failed to create sockets"); + + ATF_REQUIRE(setsockopt(sockets[1], IPPROTO_TCP, TCP_RXTLS_ENABLE, en, + sizeof(*en)) == -1); + ATF_REQUIRE(errno == EPROTONOSUPPORT || errno == ENOTSUP); + + close(sockets[1]); + close(sockets[0]); +} + +#define GEN_UNSUPPORTED_RECEIVE_TEST(name, cipher_alg, key_size, \ + auth_alg, minor) \ +ATF_TC_WITHOUT_HEAD(ktls_receive_unsupported_##name); \ +ATF_TC_BODY(ktls_receive_unsupported_##name, tc) \ +{ \ + struct tls_enable en; \ + uint64_t seqno; \ + \ + ATF_REQUIRE_KTLS(); \ + seqno = random(); \ + build_tls_enable(cipher_alg, key_size, auth_alg, minor, seqno, \ + &en); \ + test_ktls_unsupported_receive_cipher_suite(&en); \ + free_tls_enable(&en); \ +} + +#define ADD_UNSUPPORTED_RECEIVE_TEST(name, cipher_alg, key_size, \ + auth_alg, minor) \ + ATF_TP_ADD_TC(tp, ktls_receive_unsupported_##name); + +/* + * Ensure that valid cipher suites not supported for receive are + * rejected. + */ +AES_CBC_TESTS(GEN_UNSUPPORTED_RECEIVE_TEST); +TLS_13_TESTS(GEN_UNSUPPORTED_RECEIVE_TEST); + ATF_TP_ADD_TCS(tp) { /* Transmit tests */ @@ -1623,7 +1673,9 @@ ATF_TP_ADD_TCS(tp) INVALID_CIPHER_SUITES(ADD_INVALID_TRANSMIT_TEST); /* Receive tests */ + AES_CBC_TESTS(ADD_UNSUPPORTED_RECEIVE_TEST); TLS_12_TESTS(ADD_RECEIVE_TESTS); + TLS_13_TESTS(ADD_UNSUPPORTED_RECEIVE_TEST); INVALID_CIPHER_SUITES(ADD_INVALID_RECEIVE_TEST); return (atf_no_error());