From nobody Tue Oct 24 19:25:59 2023 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 4SFMVH4Ff0z4yPhZ; Tue, 24 Oct 2023 19:25:59 +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 4SFMVH3P9kz4NHR; Tue, 24 Oct 2023 19:25:59 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1698175559; 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=/ajG69pTRJdDMCc44P523GCVUlwEGHjTL1WPUugIN/Y=; b=Wk1Nvo2NkpLYO9TZnHd/td92ARQDGNczdYDvjRrDc/kLkAvutEwg3ORzVRiS6BjHhtD0qZ 3eWw4GuLvxF088SbJ8cBa65vd1s+KBycAvO+dW/g2xzXnoh4mnPwcBUc/W8djf+sfocXLK xhcyr76CunUfMZzNNkQpHQrOENDPWayojini05AVhZkf8zqLiBwVeUWZxcMbRw6qCwWIl6 efL1+7xikGrFk+U3gdxCWX/V/7Yq1ETiWWP0iPf0W8MYXxL72eDWq53B+d+epWA/Ev98TO Lby0vf4/VFXwNaZ/ZzUKV4PbJsx8fjihfPeRwU3krQXuOuzBo2JeogPUn+XS0A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1698175559; a=rsa-sha256; cv=none; b=SW0btElh4GB6iNEevkWyhjC0g2R1YQrpMcv9NCnklcPPMgmZJoQ7aHcDc8pHYL6HalcchP oyGf+mYECrqoXszxjVSxWcn8M5nceDI2HlXHCJCqppBrQpLOBB6A0MYDyRY5qf0H3kQvpk Yky2O+NvICAXVRCEIa/pJy4NQdHrIkzFhW94DiFk5nbmPYeQYEtSYLkFDtU5bDBTOUtAcB knp9wFRjjNkHC1zWczumAUGcxVF21ZS0TaRj/IJFERcjpXGqnXVZVAuwFlbxo7RJkEpnB3 +fZNDw5TbhxceuM5ANVID6h+oOi5ZJVZO7SHWzeiPhtULTAC4yA8JSNkBWsgjA== 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=1698175559; 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=/ajG69pTRJdDMCc44P523GCVUlwEGHjTL1WPUugIN/Y=; b=URN4WGogLTJGVX/EwTmMlkVwfTK7NzKLvlFXOEyDtESZJOB3guHqZs0SJ2zHMSE3tfy+U8 vjvDGvUwFWILIDgkYErzwdZW8BkrPzndOftrdFzXu1uBzxuhI0CSx4x7hlWy5yWMmTl0Si V6nsEND6aVqUEO7tTosVDW2zM4ltjrqhtO5X2hWc9uQzRRFR84bKyiw2n9FnEu/XuLIW4A 7PCsV86h43OnJ/5EufVXsMGNb/xGtw1X6VH0tosy1lDsmIYtTiZ0coIFfyMqLuido8/DUU pyBd7m7ExIWuw2Vgi9bHJPFPuUbaLEvqEgOcXqBWMmQmteBvvEvfFCrZIiOJjg== 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 4SFMVH2GFhzb5v; Tue, 24 Oct 2023 19:25:59 +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 39OJPx7V074545; Tue, 24 Oct 2023 19:25:59 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 39OJPxDR074542; Tue, 24 Oct 2023 19:25:59 GMT (envelope-from git) Date: Tue, 24 Oct 2023 19:25:59 GMT Message-Id: <202310241925.39OJPxDR074542@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: 263d7e50adb8 - stable/14 - KTLS: Enable KTLS for receiving as well in TLS 1.3 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/stable/14 X-Git-Reftype: branch X-Git-Commit: 263d7e50adb8d0d72ab287b1210002fb2fe4b6b6 Auto-Submitted: auto-generated The branch stable/14 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=263d7e50adb8d0d72ab287b1210002fb2fe4b6b6 commit 263d7e50adb8d0d72ab287b1210002fb2fe4b6b6 Author: Daiki Ueno AuthorDate: 2021-10-10 07:14:06 +0000 Commit: John Baldwin CommitDate: 2023-10-24 19:03:04 +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) --- 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