From nobody Wed Oct 25 00:41:49 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 4SFVVj4rWmz4xl4d; Wed, 25 Oct 2023 00:41:49 +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 4SFVVj41KTz3SV2; Wed, 25 Oct 2023 00:41:49 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1698194509; 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=yPk5Kd/y+DkD0z0kjc9djP/Pnw6HYoLU4R3NlMn7kZA=; b=NXQdWTc+q2oXmEULmEHD+BkzHY6nMXxQZfKYi11YEDWq+YeY5gq+WSkJRP6aTY1zlBi4Ul Gvv2nju2YSyYn7j6lbar9DEFA4oeKl5BjriduAw4knhoPd06egOIdsJzOme79m1mty/mWb lwSz5dzJqwtq4pjLHqqz6kU/mX4pKm212kEIyhBnFklU0m9lMT3xyp2BYJFweJOZAJESqR kJZNL8b2FClRNp/A+5mVX99ov9KxbpLljAyqzFIM/BSVuLYvT6sVugr/aVINv4SFNMSc09 Wj95SUm62liUgf2F+5dyYHsHvUffyl4NeGD0zPXTv9tL7b+f6caDYw8uak6jdQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1698194509; a=rsa-sha256; cv=none; b=Ct2upypSXlRiD9n0xmgjV5gqmBk4zVoa9MpTVpmEBVyXiz82zP5aADxfHsYrFu5C9Rqp4M u+q6NRrHrjvkdTtljGLBoBu0mbIyd0q9wKsjWvUxuWZMfPckWUZDz4OGlCOH9ZM9NgsJTC G927+0TQAfBunx/mp71i8LlvQOxgIspoj8ZoDE0Nib5PKPaBGl6PLEHKwKmqhVILu4iWgC qbXZuovG5JuvGvpPEIY7riqgfo+6WmkrR4+Ehj6H7ttlZ1eFBaWIr/JXzPdNnzjMlhE6LH Zu4RoFyXlvjbY8CCN+hUxyEdilNVM49Gdr+zyjqjx8VZM3Xan//Zx6HfJt7UfQ== 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=1698194509; 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=yPk5Kd/y+DkD0z0kjc9djP/Pnw6HYoLU4R3NlMn7kZA=; b=Kej/h/OAfGTrVG+vKk8Kqqbzl8koskMqsRhsCVR4TZZqX9+e28UvfAQ+BW7sGK6HbYkZUK gKyrNrFBwqqvZP/np169//Soi5cNqch69vc4OnsAamp2iYUwG9iUphi6i8/iE3hIlj09+S NAk0OiG+mwgYSUxAolnJ6Jvp/56yDJQSFxhCwrGyN5ah1ykqFH4m2iiWOw92ZKnERaYOhh +lCJu0nZFgfvmWIYkWZBDDlYYquFYvi7IFDJ78diEDm7DgNvkuSkqiX+UzeOTXtQuIbZK4 RI7a0lVoBacBWzuauEAk4eDKxeOabtsLW3S5yDZnNykot87IUKWIvUGYNjbx7g== 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 4SFVVj36Fyzl2j; Wed, 25 Oct 2023 00:41:49 +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 39P0fnsA005866; Wed, 25 Oct 2023 00:41:49 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 39P0fnGq005863; Wed, 25 Oct 2023 00:41:49 GMT (envelope-from git) Date: Wed, 25 Oct 2023 00:41:49 GMT Message-Id: <202310250041.39P0fnGq005863@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: 03282b36fd45 - releng/14.0 - KTLS: Handle TLS 1.3 in ssl3_get_record. 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/releng/14.0 X-Git-Reftype: branch X-Git-Commit: 03282b36fd459d1f6150314be62148ce038404f8 Auto-Submitted: auto-generated The branch releng/14.0 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=03282b36fd459d1f6150314be62148ce038404f8 commit 03282b36fd459d1f6150314be62148ce038404f8 Author: Daiki Ueno AuthorDate: 2021-10-10 06:54:07 +0000 Commit: John Baldwin CommitDate: 2023-10-24 19:29:07 +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) (cherry picked from commit c085ca5245797ae17fc69353bbdf7584acb2feaa) (cherry picked from commit 4d85e7386f7756c98f3e4ae1fb0037b56903510f) Approved by: re (gjb) --- 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); } /*