From nobody Wed Oct 25 00:41:50 2023 X-Original-To: dev-commits-src-branches@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 4SFVVk6FQkz4xl9f; Wed, 25 Oct 2023 00:41:50 +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 4SFVVk5M8nz3SNl; Wed, 25 Oct 2023 00:41:50 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1698194510; 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=I2V5uke0g/JJQCnmTewaWtfkm0LwAbvFWHkA3SVMgrs=; b=rheBZpUKZZSVROWUuCSQ5LRZCTsVOSDLxCgwoQul9xlGJiB8AOd5fD44Wabi4gqtOoRVeh ti+udfkTSkoMPBfbjQ04sV1GE4IALK8M7Gtk++G3pEKO+CvPLd9oh0iGxRMQDKywP56MR5 Vgm6jFv4U7XwKLOjpllejY9mJhaYPMCe4G9Ui4xefRs0Ff3v6hAImuehVUqIzKzBn1GV1c StUjiVfDRQMUj0lt7RjzBgQmfsL9znXjsAGneOULQSetmwQC+vBGj7lBP1Z7aOKf01tYuO 2KQ3DNc2kA3g1Sk5IKMOTkDk13ExVQwoX0Ynh7A4xK6v8y3yp70r/BHWv7u5fw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1698194510; a=rsa-sha256; cv=none; b=FyKNxX7n0zDT7CcF5kqRjJDtpT2lQmisooLyd2naZKLkfhaHGQv1RvGfrniuT3o3PsXnMQ p71yyJmdqM8wDnnaaLVnGb/2P0pZB8dXPNucpbJZUnlbQpACe6RIUjUUV1/k6f71INJ1mY y18PhHCTB8Onu7AZzsH8uH5EDJk72/48Q1Bb9vCvuDB/gez8KstKI/nFEpMzTTucZSOuXV 57ADdMf6QdaB8U3uXvoHNdo/Wmkd/3PN5tjnvydfFHtcz6YTqgKpQYqKF2mzln07bYktkW sqM1Pqr/T3EQgi3mdzujX82A/7Dbu5P94EjToGTIx2yeKC89TXnp9QyLaerNaA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1698194510; 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=I2V5uke0g/JJQCnmTewaWtfkm0LwAbvFWHkA3SVMgrs=; b=YSsYHXGRepFCc8PlVTgJ4DTrO2aMV9/nyxUQudy92/7NFuxgIkojWcC9SejuvKtVGG54cn r0dmGqEwU3LKABYsxCen1tyAWgF1GRvcz9o9aE+6snRhhG2A9nvTVGLIFDYhzBWoy7UJtg 4BUG5v7HPVU4uzsJ8L9pFcZ4qXZPnr+meTB43RwBufTEMq1poiM5vJe5fZL+tHkEwXCFl4 5ZcMgsSaINCzsYoDCF99p07DdTlud+RO/nm73+w8uLUHoHip7oAQIRib+y/ehwazDQMbQc 2HsA7QwvBBwbURBwX+NWVzTiSwMcbLwb4xtDK5JMO7rWDK19MDieST4126OGKw== 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 4SFVVk4S8czkmd; Wed, 25 Oct 2023 00:41:50 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 39P0foSp005924; Wed, 25 Oct 2023 00:41:50 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 39P0fomi005921; Wed, 25 Oct 2023 00:41:50 GMT (envelope-from git) Date: Wed, 25 Oct 2023 00:41:50 GMT Message-Id: <202310250041.39P0fomi005921@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: a02cdd1698df - releng/14.0 - KTLS: Enable KTLS for receiving as well in TLS 1.3 List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/releng/14.0 X-Git-Reftype: branch X-Git-Commit: a02cdd1698df64cfcf616f2f9105515e5f26b4df Auto-Submitted: auto-generated The branch releng/14.0 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=a02cdd1698df64cfcf616f2f9105515e5f26b4df commit a02cdd1698df64cfcf616f2f9105515e5f26b4df Author: Daiki Ueno AuthorDate: 2021-10-10 07:14:06 +0000 Commit: John Baldwin CommitDate: 2023-10-24 19:29:27 +0000 KTLS: Enable KTLS for receiving as well in TLS 1.3 This removes a guard condition that prevents KTLS being enabled for receiving in TLS 1.3. Use the correct sequence number and BIO for receive vs transmit offload. Obtained from: OpenSSL commit 7c78932b9a4330fb7c8db72b3fb37cbff1401f8b (cherry picked from commit 6ed16d17333c5b1895aff35ddc1d46834f53a9eb) (cherry picked from commit 263d7e50adb8d0d72ab287b1210002fb2fe4b6b6) Approved by: re (gjb) --- crypto/openssl/ssl/tls13_enc.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/crypto/openssl/ssl/tls13_enc.c b/crypto/openssl/ssl/tls13_enc.c index 861ecdf91701..39a27d926ce7 100644 --- a/crypto/openssl/ssl/tls13_enc.c +++ b/crypto/openssl/ssl/tls13_enc.c @@ -438,6 +438,7 @@ int tls13_change_cipher_state(SSL *s, int which) const EVP_CIPHER *cipher = NULL; #if !defined(OPENSSL_NO_KTLS) && defined(OPENSSL_KTLS_TLS13) ktls_crypto_info_t crypto_info; + void *rl_sequence; BIO *bio; #endif @@ -692,8 +693,7 @@ int tls13_change_cipher_state(SSL *s, int which) s->statem.enc_write_state = ENC_WRITE_STATE_VALID; #ifndef OPENSSL_NO_KTLS # if defined(OPENSSL_KTLS_TLS13) - if (!(which & SSL3_CC_WRITE) - || !(which & SSL3_CC_APPLICATION) + if (!(which & SSL3_CC_APPLICATION) || (s->options & SSL_OP_ENABLE_KTLS) == 0) goto skip_ktls; @@ -709,7 +709,10 @@ int tls13_change_cipher_state(SSL *s, int which) if (!ktls_check_supported_cipher(s, cipher, ciph_ctx)) goto skip_ktls; - bio = s->wbio; + if (which & SSL3_CC_WRITE) + bio = s->wbio; + else + bio = s->rbio; if (!ossl_assert(bio != NULL)) { SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR); @@ -717,19 +720,26 @@ int tls13_change_cipher_state(SSL *s, int which) } /* All future data will get encrypted by ktls. Flush the BIO or skip ktls */ - if (BIO_flush(bio) <= 0) - goto skip_ktls; + if (which & SSL3_CC_WRITE) { + if (BIO_flush(bio) <= 0) + goto skip_ktls; + } /* configure kernel crypto structure */ - if (!ktls_configure_crypto(s, cipher, ciph_ctx, - RECORD_LAYER_get_write_sequence(&s->rlayer), - &crypto_info, which & SSL3_CC_WRITE, iv, key, - NULL, 0)) + if (which & SSL3_CC_WRITE) + rl_sequence = RECORD_LAYER_get_write_sequence(&s->rlayer); + else + rl_sequence = RECORD_LAYER_get_read_sequence(&s->rlayer); + + if (!ktls_configure_crypto(s, cipher, ciph_ctx, rl_sequence, &crypto_info, + which & SSL3_CC_WRITE, iv, key, NULL, 0)) goto skip_ktls; /* ktls works with user provided buffers directly */ - if (BIO_set_ktls(bio, &crypto_info, which & SSL3_CC_WRITE)) - ssl3_release_write_buffer(s); + if (BIO_set_ktls(bio, &crypto_info, which & SSL3_CC_WRITE)) { + if (which & SSL3_CC_WRITE) + ssl3_release_write_buffer(s); + } skip_ktls: # endif #endif