From nobody Sat May 14 19:58:13 2022 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 4EA831ADDC89; Sat, 14 May 2022 19:58:14 +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 4L0xCB1mCJz4VXZ; Sat, 14 May 2022 19:58:14 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1652558294; 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=TeMAhKWUrTY+ifV869oX9uFhT58sOSSrsdV2h8nNVXM=; b=PXyatNp0CTLyml04RvWSf756IZ3jO+ZbJIEZpSAbOrCxu5CIMDIUZ7xOCWobFNsaJbp6bN IbL/xV2pZk9YKmi3ySso6NCHf7VWOUgJSCKRw6DIMHmgwNuVdl3UjjyhnAk8ONqFaLChMb HTz9v83MBEeKbCAuzjjdegXhXzFRsbcP6qpBBsOyaBGh1UWD+6YqtCXIC7VMVLjbEokK4p 3JD3aAzhR7JMauxJN7rk1YphWQv1+bS4uMNEiD7JLDvUWta4dbLiTbA6Yvl95LwxiLAvXc AQqUpEu/v8l0viVbCxHBjsNB+DG99kVNGj1IigODmPzMlfEqogXqQDm8BOFiKA== 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 18ABD1DA2A; Sat, 14 May 2022 19:58:14 +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 24EJwDZl076966; Sat, 14 May 2022 19:58:13 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 24EJwDSw076965; Sat, 14 May 2022 19:58:13 GMT (envelope-from git) Date: Sat, 14 May 2022 19:58:13 GMT Message-Id: <202205141958.24EJwDSw076965@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Rick Macklem Subject: git: 373511338d95 - main - uipc_socket.c: Modify MSG_TLSAPPDATA to only do Alert Records 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: rmacklem X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 373511338d954895752e957f3028a178587c8c84 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1652558294; 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=TeMAhKWUrTY+ifV869oX9uFhT58sOSSrsdV2h8nNVXM=; b=RBYHWIQEOSdyU/H1kbvVhJGijnNBt7SO1IldHqtxgmapMhNBSyuAy5B1GrTjCAj19t+bzA wmRNSy1bKNk49SR5HR0kqEPK+qyMdvjrGSkaFOfqAIMdqz0ihslKikZ6xIH0405B+kF5VI BFLMLY9o5hPpeNKFrm0Iiz00fQRF89PkS2s41Uujnu0qUi6rNeP5T4B6Y5Pv+sVb0RZqmF HnpVYBoj5FLnPeiyMIp4NHJyULjL22aF02Gjk9qYyJ+deknmg08h7xyocAjXJ7hmjlq7S4 Q0xXtgoc+CX3noy4ff0cMz24rAwkzyTuSY1TGyKBaPvU/xFEREVFXIwvDFiESw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1652558294; a=rsa-sha256; cv=none; b=qBfqmf1lKxos56fWGbXq4gRhLLG8N9sq9je6w6Gp04cQtqt+3OAHg6mda2Xwf+xFFy/RrW R3SaResjl1vm2toxPx37VWMFLv7U89DffsqB49MAA+m/N9I1gC0aix+1WZyvfBqNfA6c1R YVNJ/1nWeMkyAAXVWh7eQldAUVGIQKLvWWry/0bBlm1oxC8iJaBw9FdGGEbcVF+QWlljcJ ax1Ug+ERv27Ai7u57IcJ+3egHMjZZ0za/xvLqVEd5D4WAFP/2BFoVjJdi7lRBRXqzYERF4 RUBs0dB6seBCFWytZFrfrsufKe6KxqCqK4gDaaxy4Pgj/7Rx9FutiWXxEFHWdQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by rmacklem: URL: https://cgit.FreeBSD.org/src/commit/?id=373511338d954895752e957f3028a178587c8c84 commit 373511338d954895752e957f3028a178587c8c84 Author: Rick Macklem AuthorDate: 2022-05-14 19:56:50 +0000 Commit: Rick Macklem CommitDate: 2022-05-14 19:56:50 +0000 uipc_socket.c: Modify MSG_TLSAPPDATA to only do Alert Records Without this patch, the MSG_TLSAPPDATA flag would cause soreceive_generic() to return ENXIO for any non-application data record in a TLS receive stream. This works ok for TLS1.2, since Alert records appear to be the only non-application data records received. However, for TLS1.3, there can be post-handshake handshake records, such as NewSessionKey sent to the client from the server. These handshake records cannot be handled by the upcall which does an SSL_read() with length == 0. It appears that the client can simply throw away these NewSessionKey records, but to do so, it needs to receive them within the kernel. This patch modifies the semantics of MSG_TLSAPPDATA slightly, so that it only applies to Alert records and not Handshake records. It is needed to allow the krpc to work with KTLS1.3. Reviewed by: hselasky MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D35170 --- sys/kern/uipc_socket.c | 8 ++++---- sys/sys/ktls.h | 2 ++ sys/sys/socket.h | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index 49a2b5773cc6..7351238343b3 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -2127,8 +2127,8 @@ dontblock: struct tls_get_record tgr; /* - * For MSG_TLSAPPDATA, check for a non-application data - * record. If found, return ENXIO without removing + * For MSG_TLSAPPDATA, check for an alert record. + * If found, return ENXIO without removing * it from the receive queue. This allows a subsequent * call without MSG_TLSAPPDATA to receive it. * Note that, for TLS, there should only be a single @@ -2139,8 +2139,8 @@ dontblock: if (cmsg->cmsg_type == TLS_GET_RECORD && cmsg->cmsg_len == CMSG_LEN(sizeof(tgr))) { memcpy(&tgr, CMSG_DATA(cmsg), sizeof(tgr)); - /* This will need to change for TLS 1.3. */ - if (tgr.tls_type != TLS_RLTYPE_APP) { + if (__predict_false(tgr.tls_type == + TLS_RLTYPE_ALERT)) { SOCKBUF_UNLOCK(&so->so_rcv); error = ENXIO; goto release; diff --git a/sys/sys/ktls.h b/sys/sys/ktls.h index 6d0b391ee0a5..885e4dc38ef9 100644 --- a/sys/sys/ktls.h +++ b/sys/sys/ktls.h @@ -50,6 +50,8 @@ struct tls_record_layer { #define TLS_CBC_IMPLICIT_IV_LEN 16 /* Type values for the record layer */ +#define TLS_RLTYPE_ALERT 21 +#define TLS_RLTYPE_HANDSHAKE 22 #define TLS_RLTYPE_APP 23 /* diff --git a/sys/sys/socket.h b/sys/sys/socket.h index 2cb76f9c6d63..de7a874b3079 100644 --- a/sys/sys/socket.h +++ b/sys/sys/socket.h @@ -470,7 +470,7 @@ struct msghdr { #endif #ifdef _KERNEL #define MSG_MORETOCOME 0x00100000 /* additional data pending */ -#define MSG_TLSAPPDATA 0x00200000 /* only soreceive() app. data (TLS) */ +#define MSG_TLSAPPDATA 0x00200000 /* do not soreceive() alert rec. (TLS) */ #endif /*