From nobody Thu Oct 19 18:36:46 2023 X-Original-To: dev-commits-src-main@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 4SBGdp3py0z4xkRJ; Thu, 19 Oct 2023 18:36:46 +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 4SBGdp2xQ5z3VyH; Thu, 19 Oct 2023 18:36:46 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1697740606; 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=dKiBtuiOx6uEw89FxFGcwPl0DUIaQGT3egm1l6/Guzs=; b=Q4WiGPOOV8V/7G1KB2hHWq74tq7WmaO4u9/1Lpx9vhxS/U1d1Lp9ZZtepX2/1i1ZOldI3y G/yAnuGzumyem5QrYULfz0zUmKCRaaV2rK/KYjmBVg1NbOJTXQCpBxWNMstD3SUD0jz55X 2YV2p4IZrYvjwwWrYnyHSz7W9l6sHc0IYj8t3WatxX3d6X+OXhqSctqtiC4uOSRC/JIuNc bzwt+ps07/1e6d7OEypMAWCMKbHFGRI+iTecOQz2k+SI5TcodA1JSUfZk/dF+YwRAmxXY5 gApe8KqrYKSvvBUrQNbQGUdMeVfdsNa4Dx39zPIfHFeL5WhlcZhU0J9gh1iUPg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1697740606; a=rsa-sha256; cv=none; b=oz5jqsfH0mzoN5V53mDomRog8RJv84trfyEqLFXzMlyyhIdvJPWVtg7UA6xM3QdG1Nuu+b 9xgcdGQ5iYfgSF9LOnmHPyW3wUhxhwHiLACl6eIaWgaOiHwPa3b+fuCKF9OuURakUnm29E 5XuZMh8sHKWVpmHwvDEW9Fbvf4MCsLy4pVJcE1jk5l17EJdzOtGkQytlynL3OQ0lZJxFy/ RuKIcjSNojXj5go0p+KvgkhfeK4iw2Dm677EVo0wDd/n/J+NjJeIBX/zocJkyRuO/liRM9 XeVeH7+udmv6Jec7A0wKZz/Uyt5HMFTTfI+90ti4j1TdmeV613qT/jwCkoifmQ== 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=1697740606; 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=dKiBtuiOx6uEw89FxFGcwPl0DUIaQGT3egm1l6/Guzs=; b=rE0OdMhn7sjeL2oj8LMaMD9Dk/EqqwVTd9yxbUYBwbNsVftE4y+/DzyXuwB1xROVuZ3Wyk P0BOBRcq27Ef1ChzJOT6lctWsKhQ6uOf5g06Z3KfQ0ns9JioQai9Q8TjR7W2S5lxnwQ7Cf o1aj/BbQNz97kEdReM72YYM80sZvjncJaQ885btOirLa8iH91jfMsJPTvpbMj8TWiRoyUe W+P6OJyoHfUln1BmjzZVEM2XekdXuirAMyJxPyClevlxEfOGYgVNb9CV8+jc9gaMejBikx goe0JEF5TQ0O82nAxRSES2kP5pW8RGb/TZdF586D2SYJuj7uxDtfIhEfS73z2A== 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 4SBGdp1jSZz11Jr; Thu, 19 Oct 2023 18:36:46 +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 39JIakMw094297; Thu, 19 Oct 2023 18:36:46 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 39JIakvd094294; Thu, 19 Oct 2023 18:36:46 GMT (envelope-from git) Date: Thu, 19 Oct 2023 18:36:46 GMT Message-Id: <202310191836.39JIakvd094294@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: c085ca524579 - main - KTLS: Handle TLS 1.3 in ssl3_get_record. List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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: c085ca5245797ae17fc69353bbdf7584acb2feaa Auto-Submitted: auto-generated The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=c085ca5245797ae17fc69353bbdf7584acb2feaa commit c085ca5245797ae17fc69353bbdf7584acb2feaa Author: Daiki Ueno AuthorDate: 2021-10-10 06:54:07 +0000 Commit: John Baldwin CommitDate: 2023-10-19 18:34:58 +0000 KTLS: Handle TLS 1.3 in ssl3_get_record. - Don't unpad records, check the outer record type, or extract the inner record type from TLS 1.3 records handled by the kernel. KTLS performs all of these steps and returns the inner record type in the TLS header. - When checking the length of a received TLS 1.3 record don't allow for the extra byte for the nested record type when KTLS is used. - Pass a pointer to the record type in the TLS header to the SSL3_RT_INNER_CONTENT_TYPE message callback. For KTLS, the old pointer pointed to the last byte of payload rather than the record type. For the non-KTLS case, the TLS header has been updated with the inner type before this callback is invoked. Obtained from: OpenSSL commit a5fb9605329fb939abb536c1604d44a511741624) --- crypto/openssl/ssl/record/ssl3_record.c | 46 ++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/crypto/openssl/ssl/record/ssl3_record.c b/crypto/openssl/ssl/record/ssl3_record.c index 57915e1bd6e0..d6c0cf346723 100644 --- a/crypto/openssl/ssl/record/ssl3_record.c +++ b/crypto/openssl/ssl/record/ssl3_record.c @@ -366,7 +366,9 @@ int ssl3_get_record(SSL *s) } } - if (SSL_IS_TLS13(s) && s->enc_read_ctx != NULL) { + if (SSL_IS_TLS13(s) + && s->enc_read_ctx != NULL + && !using_ktls) { if (thisrr->type != SSL3_RT_APPLICATION_DATA && (thisrr->type != SSL3_RT_CHANGE_CIPHER_SPEC || !SSL_IS_FIRST_HANDSHAKE(s)) @@ -396,7 +398,13 @@ int ssl3_get_record(SSL *s) } if (SSL_IS_TLS13(s)) { - if (thisrr->length > SSL3_RT_MAX_TLS13_ENCRYPTED_LENGTH) { + size_t len = SSL3_RT_MAX_TLS13_ENCRYPTED_LENGTH; + + /* KTLS strips the inner record type. */ + if (using_ktls) + len = SSL3_RT_MAX_ENCRYPTED_LENGTH; + + if (thisrr->length > len) { SSLfatal(s, SSL_AD_RECORD_OVERFLOW, SSL_R_ENCRYPTED_LENGTH_TOO_LONG); return -1; @@ -689,21 +697,29 @@ int ssl3_get_record(SSL *s) if (SSL_IS_TLS13(s) && s->enc_read_ctx != NULL && thisrr->type != SSL3_RT_ALERT) { - size_t end; + /* + * The following logic are irrelevant in KTLS: the kernel provides + * unprotected record and thus record type represent the actual + * content type, and padding is already removed and thisrr->type and + * thisrr->length should have the correct values. + */ + if (!using_ktls) { + size_t end; - if (thisrr->length == 0 - || thisrr->type != SSL3_RT_APPLICATION_DATA) { - SSLfatal(s, SSL_AD_UNEXPECTED_MESSAGE, SSL_R_BAD_RECORD_TYPE); - goto end; - } + if (thisrr->length == 0 + || thisrr->type != SSL3_RT_APPLICATION_DATA) { + SSLfatal(s, SSL_AD_UNEXPECTED_MESSAGE, SSL_R_BAD_RECORD_TYPE); + goto end; + } - /* Strip trailing padding */ - for (end = thisrr->length - 1; end > 0 && thisrr->data[end] == 0; - end--) - continue; + /* Strip trailing padding */ + for (end = thisrr->length - 1; end > 0 && thisrr->data[end] == 0; + end--) + continue; - thisrr->length = end; - thisrr->type = thisrr->data[end]; + thisrr->length = end; + thisrr->type = thisrr->data[end]; + } if (thisrr->type != SSL3_RT_APPLICATION_DATA && thisrr->type != SSL3_RT_ALERT && thisrr->type != SSL3_RT_HANDSHAKE) { @@ -712,7 +728,7 @@ int ssl3_get_record(SSL *s) } if (s->msg_callback) s->msg_callback(0, s->version, SSL3_RT_INNER_CONTENT_TYPE, - &thisrr->data[end], 1, s, s->msg_callback_arg); + &thisrr->type, 1, s, s->msg_callback_arg); } /*