From nobody Fri Dec 31 14:26:19 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 EA22D1924FDE; Fri, 31 Dec 2021 14:26:19 +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 4JQSB34k0tz4kS1; Fri, 31 Dec 2021 14:26:19 +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 82B0B553B; Fri, 31 Dec 2021 14:26:19 +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 1BVEQJGC040803; Fri, 31 Dec 2021 14:26:19 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1BVEQJIi040802; Fri, 31 Dec 2021 14:26:19 GMT (envelope-from git) Date: Fri, 31 Dec 2021 14:26:19 GMT Message-Id: <202112311426.1BVEQJIi040802@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 5a3abce55e16 - stable/13 - ktls: Add a regression test to exercise socket error handling 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: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 5a3abce55e16e43adc1db506bf47ba1aca59b82c Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1640960779; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=aM3zFE5oZOv7C1szO4Wd2ZPeVAu+vnF648NhilhEONs=; b=QXr1WR2HqGtDeXZnkVhT5IjB0MpJvR6EZQyxgZ2NoMZ+AlVHCEYUZXLeXXqFp6CgaX+IzX 8PGi3Cv42TsA97QN73EdH46oLHPc+2maxAG5fjPyWCV28QnnM4LnmsL6dgvg7VmKK1BXn7 7KIDPyiWFkm9dvLRhoq9+p+fKnvMunLVZdTn6BPDQuSAHc7HE/ISTj+6LpzuD78Lsq9v37 Y0AkdDfDceYz00ZkKHYW7WQ548BYv6oYl/MpfryLUuBxQQO3dHQrC/Opx/Z2a5KVOY1PZq lKUGLlLndcBYs1uCUkICH5/H/LBFbgvybpiR7yeNbotArlvifBRt2e63E7a+Eg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1640960779; a=rsa-sha256; cv=none; b=FRFg7BVsWlD38cb+S0nQWue6G4oMOq4VPUbq22dmY9/TU7vYkC9+7CHacTU1Xybmj7qcMl NYecuKYip05u+zlAvtMMJcdsGlJDi0m+momHhLNR+M49ZOVl1N6ZZVDNBboj4mmwjn04K/ Yz94VHuxITuQDL2A9u/b82CPh8GbW9M62GKTDKWdTQiCYn1AEZQYKN58xe3W/+IXHth8F3 vLLQMvV3NKhsg4ii9dZ6sIknkpQwoLsP2FC6ayMebz7kKwg3WOPXVGxX1F25ZUYQ76UWPk Hs2YTG+64R+NOmIq8csAF1SAakg7/XJjUquHFX3Fl/5Oo5Ew+/ExdfJaf+s3Jw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=5a3abce55e16e43adc1db506bf47ba1aca59b82c commit 5a3abce55e16e43adc1db506bf47ba1aca59b82c Author: Mark Johnston AuthorDate: 2021-12-17 16:00:19 +0000 Commit: Mark Johnston CommitDate: 2021-12-31 14:25:45 +0000 ktls: Add a regression test to exercise socket error handling Prior to commit 916c61a5ed37 ("Fix handling of errors from pru_send(PRUS_NOTREADY)") this test triggered a kernel panic due to an mbuf double free. Reviewed by: jhb Sponsored by: The FreeBSD Foundation (cherry picked from commit ee5686c614ba7e11e8586b2e5b02dfc550679e96) --- tests/sys/kern/ktls_test.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/sys/kern/ktls_test.c b/tests/sys/kern/ktls_test.c index 9942e78091b1..b2c722914854 100644 --- a/tests/sys/kern/ktls_test.c +++ b/tests/sys/kern/ktls_test.c @@ -1662,6 +1662,45 @@ ATF_TC_BODY(ktls_receive_unsupported_##name, tc) \ AES_CBC_TESTS(GEN_UNSUPPORTED_RECEIVE_TEST); TLS_13_TESTS(GEN_UNSUPPORTED_RECEIVE_TEST); +/* + * Try to perform an invalid sendto(2) on a TXTLS-enabled socket, to exercise + * KTLS error handling in the socket layer. + */ +ATF_TC_WITHOUT_HEAD(ktls_sendto_baddst); +ATF_TC_BODY(ktls_sendto_baddst, tc) +{ + char buf[32]; + struct sockaddr_in dst; + struct tls_enable en; + ssize_t n; + int s; + + ATF_REQUIRE_KTLS(); + + s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + ATF_REQUIRE(s >= 0); + + build_tls_enable(CRYPTO_AES_NIST_GCM_16, 128 / 8, 0, + TLS_MINOR_VER_THREE, (uint64_t)random(), &en); + + ATF_REQUIRE(setsockopt(s, IPPROTO_TCP, TCP_TXTLS_ENABLE, &en, + sizeof(en)) == 0); + + memset(&dst, 0, sizeof(dst)); + dst.sin_family = AF_INET; + dst.sin_len = sizeof(dst); + dst.sin_addr.s_addr = htonl(INADDR_BROADCAST); + dst.sin_port = htons(12345); + + memset(buf, 0, sizeof(buf)); + n = sendto(s, buf, sizeof(buf), 0, (struct sockaddr *)&dst, + sizeof(dst)); + + /* Can't transmit to the broadcast address over TCP. */ + ATF_REQUIRE_ERRNO(EACCES, n == -1); + ATF_REQUIRE(close(s) == 0); +} + ATF_TP_ADD_TCS(tp) { /* Transmit tests */ @@ -1678,5 +1717,8 @@ ATF_TP_ADD_TCS(tp) TLS_13_TESTS(ADD_UNSUPPORTED_RECEIVE_TEST); INVALID_CIPHER_SUITES(ADD_INVALID_RECEIVE_TEST); + /* Miscellaneous */ + ATF_TP_ADD_TC(tp, ktls_sendto_baddst); + return (atf_no_error()); }