From patchwork Thu May 4 15:24:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13231329 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 72C471855; Thu, 4 May 2023 15:24:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E10CCC433D2; Thu, 4 May 2023 15:24:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1683213890; bh=FTouDkykxMQRz9rZE9nkcyfGey/Gq8f8Xobzg602TKk=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=sJWHtWYfWW2UBqQ/i7O6mFTpL2HsdSDbh10hddAJbSW12FVl3jNUl16s1FYsgFB5j mWfrcVgSEZ4VyYSW4dlQGYMLqEQAAuT/7M3H24rDo1ZVI9BktutmVr1MJwy79Rtp6N UrWlKbkw1Y7PGo2a3VtiLqKhb/at1av5NKbQ/jx3K/r42WSHTxno+UiBkDZZe1MiKx iEKt7eOBbwjiboL2aKL5mIbxcmRa2zO0P7MNAuJANXgJqCgqKUoZgcYK4YUSHwy7cg T1oOvRbgc0QzAhaUC6WSLHj5i/ms1cNvcmwlquHyT0dkjgyBrdBK5ZhUtEbnYqxhKA UZ9H8or+3FVgg== Subject: [PATCH 1/5] net/handshake: Remove unneeded check from handshake_dup() From: Chuck Lever To: kernel-tls-handshake@lists.linux.dev Cc: netdev@vger.kernel.org, dan.carpenter@linaro.org Date: Thu, 04 May 2023 11:24:38 -0400 Message-ID: <168321386878.16695.14651822244436092067.stgit@oracle-102.nfsv4bat.org> In-Reply-To: <168321371754.16695.4217960864733718685.stgit@oracle-102.nfsv4bat.org> References: <168321371754.16695.4217960864733718685.stgit@oracle-102.nfsv4bat.org> User-Agent: StGit/1.5 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Chuck Lever handshake_req_submit() now verifies that the socket has a file. Fixes: 3b3009ea8abb ("net/handshake: Create a NETLINK service for handling handshake requests") Signed-off-by: Chuck Lever Reviewed-by: Simon Horman --- net/handshake/netlink.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/net/handshake/netlink.c b/net/handshake/netlink.c index 35c9c445e0b8..7ec8a76c3c8a 100644 --- a/net/handshake/netlink.c +++ b/net/handshake/netlink.c @@ -99,9 +99,6 @@ static int handshake_dup(struct socket *sock) struct file *file; int newfd; - if (!sock->file) - return -EBADF; - file = get_file(sock->file); newfd = get_unused_fd_flags(O_CLOEXEC); if (newfd < 0) { From patchwork Thu May 4 15:25:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13231330 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0945879D0; Thu, 4 May 2023 15:25:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5E4BDC433EF; Thu, 4 May 2023 15:25:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1683213916; bh=UzrYB/+xFPPdTbyfTZH5iQH1u2R5hCE2c71kqPRwk7k=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=szlbBvb07cWeKVUYW9obTnlMbJ7t+ZslNxLYD8QgO4KLI+kj/1ahdYTJVPKitP4Xy 2sjyVBhBvq+83FELLpjWKCNrVYlJHdzBmJcjRaU49IqGc2YnriLsFYYWmfoXomB3w5 MjXOh1J7Kol45iUhRuATbJDExWtKS1VTf0E5mJ3639TRiv5DFXkgm/crmQgUGDshVl VWJiYdqq6BU+AhVwXVotOD3y3nwWfn9ac7djKrnT4wEdfvJNybm+uR7hdwzx3SkmXv JRa83bHWpTQ129V78/XScmZAg399h6qMwMGOM+zdwCqpTAFMxg6HUnFdDydKDUEwFD gn1f2N6L/owdA== Subject: [PATCH 2/5] net/handshake: Fix handshake_dup() ref counting From: Chuck Lever To: kernel-tls-handshake@lists.linux.dev Cc: netdev@vger.kernel.org, dan.carpenter@linaro.org Date: Thu, 04 May 2023 11:25:05 -0400 Message-ID: <168321389545.16695.14828237648251844351.stgit@oracle-102.nfsv4bat.org> In-Reply-To: <168321371754.16695.4217960864733718685.stgit@oracle-102.nfsv4bat.org> References: <168321371754.16695.4217960864733718685.stgit@oracle-102.nfsv4bat.org> User-Agent: StGit/1.5 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Chuck Lever If get_unused_fd_flags() fails, we ended up calling fput(sock->file) twice. Reported-by: Dan Carpenter Fixes: 3b3009ea8abb ("net/handshake: Create a NETLINK service for handling handshake requests") Signed-off-by: Chuck Lever Reviewed-by: Simon Horman --- net/handshake/netlink.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/net/handshake/netlink.c b/net/handshake/netlink.c index 7ec8a76c3c8a..3508bc3e661d 100644 --- a/net/handshake/netlink.c +++ b/net/handshake/netlink.c @@ -96,17 +96,13 @@ EXPORT_SYMBOL(handshake_genl_put); */ static int handshake_dup(struct socket *sock) { - struct file *file; int newfd; - file = get_file(sock->file); newfd = get_unused_fd_flags(O_CLOEXEC); - if (newfd < 0) { - fput(file); + if (newfd < 0) return newfd; - } - fd_install(newfd, file); + fd_install(newfd, sock->file); return newfd; } @@ -143,11 +139,11 @@ int handshake_nl_accept_doit(struct sk_buff *skb, struct genl_info *info) goto out_complete; trace_handshake_cmd_accept(net, req, req->hr_sk, fd); + get_file(sock->file); /* released by DONE */ return 0; out_complete: handshake_complete(req, -EIO, NULL); - fput(sock->file); out_status: trace_handshake_cmd_accept_err(net, req, NULL, err); return err; From patchwork Thu May 4 15:25:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13231331 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 514C8FC04; Thu, 4 May 2023 15:25:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DD333C433EF; Thu, 4 May 2023 15:25:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1683213943; bh=54ETPiT81oUrVet9tQSEV7zfyqNgqW6pD9IyJ9CtNZg=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=u57/Hx6mjmIqJCe9LJVhacwTj7GwB+MdJ/qO7qC9BSc9121Vq9RmsXHD8cOKkpYg1 66Td4bPLK4txXpG0kr5ruA0pOlC4x/YWW3X8zZ13bzilMs9YQqxnb5NGU8NQmBHvO9 jN4gSYe7Vj45QfC34/Ff3f/1ovxjQISrT6LPE5JB3kvqOE8ndFX8/swwRlnJlDGIaK SLawAp2/FT+T66egDGis2ltYA0BxiEOXw+NYTgOEov5soEnr4L52SLA+AIJzmeWapi zRPGXdYjWLQm1YWhAR8PrKb4VbnjCwgMTGszJZ208CIllpXcC55KD4qOfyDSU/e8Gd s+KQ0bSz8ZT1A== Subject: [PATCH 3/5] net/handshake: Fix uninitialized local variable From: Chuck Lever To: kernel-tls-handshake@lists.linux.dev Cc: netdev@vger.kernel.org, dan.carpenter@linaro.org Date: Thu, 04 May 2023 11:25:32 -0400 Message-ID: <168321392193.16695.5713194659624553982.stgit@oracle-102.nfsv4bat.org> In-Reply-To: <168321371754.16695.4217960864733718685.stgit@oracle-102.nfsv4bat.org> References: <168321371754.16695.4217960864733718685.stgit@oracle-102.nfsv4bat.org> User-Agent: StGit/1.5 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Chuck Lever trace_handshake_cmd_done_err() simply records the pointer in @req, so initializing it to NULL is sufficient and safe. Reported-by: Dan Carpenter Fixes: 3b3009ea8abb ("net/handshake: Create a NETLINK service for handling handshake requests") Signed-off-by: Chuck Lever Reviewed-by: Simon Horman --- net/handshake/netlink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/handshake/netlink.c b/net/handshake/netlink.c index 3508bc3e661d..8c2d13190314 100644 --- a/net/handshake/netlink.c +++ b/net/handshake/netlink.c @@ -152,8 +152,8 @@ int handshake_nl_accept_doit(struct sk_buff *skb, struct genl_info *info) int handshake_nl_done_doit(struct sk_buff *skb, struct genl_info *info) { struct net *net = sock_net(skb->sk); + struct handshake_req *req = NULL; struct socket *sock = NULL; - struct handshake_req *req; int fd, status, err; if (GENL_REQ_ATTR_CHECK(info, HANDSHAKE_A_DONE_SOCKFD)) From patchwork Thu May 4 15:25:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13231332 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EAB9579F4; Thu, 4 May 2023 15:26:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5C80EC433D2; Thu, 4 May 2023 15:26:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1683213969; bh=7SNbUsJbwS6aBollO8XYpeLF/vFw+x6n0WQJ1DfXHV8=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=eGvukNs4Ee3JYbfP4ezk9RO1183MpMBTbnXeyF1J3GQVT5GNioUUVhBx9W1luXhyt 1GeCqM8XW0FcxWIc3wEE1kHSgQLHheZgTwtGmntHPvzyvMZ0MLvHQTYr2UGCgY+WDJ rqwm8qc7O3qkjWGEqdNg6uiCHcOqBbDHJ6tENVOdGCeSFbCmO/RSaVXvV0qOSyAX+5 Vt/OZ0V7Q45rOv6L/+Ckon2BbBpSjKOj8ZwYnDtC1fsV9nc2RBQYrqJCBu4Q30ULT9 6KzG9SwS2IFQ9y5x3qZOoaCxUxTsTZNnBT6Y0Ay4tClP58TDplVEOeH3bbAYsBkCg1 RGmL0nxGa6nmQ== Subject: [PATCH 4/5] net/handshake: handshake_genl_notify() shouldn't ignore @flags From: Chuck Lever To: kernel-tls-handshake@lists.linux.dev Cc: netdev@vger.kernel.org, dan.carpenter@linaro.org Date: Thu, 04 May 2023 11:25:58 -0400 Message-ID: <168321394845.16695.3852024361115547230.stgit@oracle-102.nfsv4bat.org> In-Reply-To: <168321371754.16695.4217960864733718685.stgit@oracle-102.nfsv4bat.org> References: <168321371754.16695.4217960864733718685.stgit@oracle-102.nfsv4bat.org> User-Agent: StGit/1.5 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Chuck Lever Reported-by: Dan Carpenter Fixes: 3b3009ea8abb ("net/handshake: Create a NETLINK service for handling handshake requests") Signed-off-by: Chuck Lever Reviewed-by: Simon Horman --- net/handshake/netlink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/handshake/netlink.c b/net/handshake/netlink.c index 8c2d13190314..ab1ba5175c03 100644 --- a/net/handshake/netlink.c +++ b/net/handshake/netlink.c @@ -48,7 +48,7 @@ int handshake_genl_notify(struct net *net, const struct handshake_proto *proto, proto->hp_handler_class)) return -ESRCH; - msg = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL); + msg = genlmsg_new(GENLMSG_DEFAULT_SIZE, flags); if (!msg) return -ENOMEM; From patchwork Thu May 4 15:26:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13231333 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 22C29FC06; Thu, 4 May 2023 15:26:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AED40C4339B; Thu, 4 May 2023 15:26:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1683213988; bh=3+XK7KKMb/pdWRO5jeZ+e//49MxpSglEfIQL5W5/Fe8=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=VibbSfUT3fdTkN9YwfRRVCuzKa8mu+tJs+5PsYLOS/v6BT6HqMrGg1YpevcKCnMsO uyZgKOGmi4CgsAMIyie7xJ+Dd2dLth7NAsF6yTYeq8SbfsldDZqdYa00QFn69TxBR/ zabb7xki4eQnFXoKcVWOjKz094Pgy99sCnjEhg0Mc+BchTyrgKEgh35sSCzFjjBDHh EtkFj5fQQkR7TQnS2AyyiOeLaZ4w8BLxHOHhe3RuxWaxjvC3Nhe8OuDz2g4oOdegJk a5MAJtJzNkRIQREiiWcTja/PAEYLZV5s2eM/JhfMjWszSWony35I3G56rgiQS1FV2p cx/oa9FWZlXqA== Subject: [PATCH 5/5] net/handshake: Enable the SNI extension to work properly From: Chuck Lever To: kernel-tls-handshake@lists.linux.dev Cc: netdev@vger.kernel.org, dan.carpenter@linaro.org Date: Thu, 04 May 2023 11:26:17 -0400 Message-ID: <168321397496.16695.17457090959897234928.stgit@oracle-102.nfsv4bat.org> In-Reply-To: <168321371754.16695.4217960864733718685.stgit@oracle-102.nfsv4bat.org> References: <168321371754.16695.4217960864733718685.stgit@oracle-102.nfsv4bat.org> User-Agent: StGit/1.5 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Chuck Lever Enable the upper layer protocol to specify the SNI peername. This avoids the need for tlshd to use a DNS lookup, which can return a hostname that doesn't match the incoming certificate's SubjectName. Fixes: 2fd5532044a8 ("net/handshake: Add a kernel API for requesting a TLSv1.3 handshake") Signed-off-by: Chuck Lever Reviewed-by: Simon Horman --- Documentation/netlink/specs/handshake.yaml | 4 ++++ Documentation/networking/tls-handshake.rst | 5 +++++ include/net/handshake.h | 1 + include/uapi/linux/handshake.h | 1 + net/handshake/tlshd.c | 8 ++++++++ 5 files changed, 19 insertions(+) diff --git a/Documentation/netlink/specs/handshake.yaml b/Documentation/netlink/specs/handshake.yaml index 614f1a585511..6d89e30f5fd5 100644 --- a/Documentation/netlink/specs/handshake.yaml +++ b/Documentation/netlink/specs/handshake.yaml @@ -68,6 +68,9 @@ attribute-sets: type: nest nested-attributes: x509 multi-attr: true + - + name: peername + type: string - name: done attributes: @@ -105,6 +108,7 @@ operations: - auth-mode - peer-identity - certificate + - peername - name: done doc: Handler reports handshake completion diff --git a/Documentation/networking/tls-handshake.rst b/Documentation/networking/tls-handshake.rst index a2817a88e905..6f5ea1646a47 100644 --- a/Documentation/networking/tls-handshake.rst +++ b/Documentation/networking/tls-handshake.rst @@ -53,6 +53,7 @@ fills in a structure that contains the parameters of the request: struct socket *ta_sock; tls_done_func_t ta_done; void *ta_data; + const char *ta_peername; unsigned int ta_timeout_ms; key_serial_t ta_keyring; key_serial_t ta_my_cert; @@ -71,6 +72,10 @@ instantiated a struct file in sock->file. has completed. Further explanation of this function is in the "Handshake Completion" sesction below. +The consumer can provide a NUL-terminated hostname in the @ta_peername +field that is sent as part of ClientHello. If no peername is provided, +the DNS hostname associated with the server's IP address is used instead. + The consumer can fill in the @ta_timeout_ms field to force the servicing handshake agent to exit after a number of milliseconds. This enables the socket to be fully closed once both the kernel and the handshake agent diff --git a/include/net/handshake.h b/include/net/handshake.h index 3352b1ab43b3..2e26e436e85f 100644 --- a/include/net/handshake.h +++ b/include/net/handshake.h @@ -24,6 +24,7 @@ struct tls_handshake_args { struct socket *ta_sock; tls_done_func_t ta_done; void *ta_data; + const char *ta_peername; unsigned int ta_timeout_ms; key_serial_t ta_keyring; key_serial_t ta_my_cert; diff --git a/include/uapi/linux/handshake.h b/include/uapi/linux/handshake.h index 1de4d0b95325..3d7ea58778c9 100644 --- a/include/uapi/linux/handshake.h +++ b/include/uapi/linux/handshake.h @@ -44,6 +44,7 @@ enum { HANDSHAKE_A_ACCEPT_AUTH_MODE, HANDSHAKE_A_ACCEPT_PEER_IDENTITY, HANDSHAKE_A_ACCEPT_CERTIFICATE, + HANDSHAKE_A_ACCEPT_PEERNAME, __HANDSHAKE_A_ACCEPT_MAX, HANDSHAKE_A_ACCEPT_MAX = (__HANDSHAKE_A_ACCEPT_MAX - 1) diff --git a/net/handshake/tlshd.c b/net/handshake/tlshd.c index fcbeb63b4eb1..b735f5cced2f 100644 --- a/net/handshake/tlshd.c +++ b/net/handshake/tlshd.c @@ -31,6 +31,7 @@ struct tls_handshake_req { int th_type; unsigned int th_timeout_ms; int th_auth_mode; + const char *th_peername; key_serial_t th_keyring; key_serial_t th_certificate; key_serial_t th_privkey; @@ -48,6 +49,7 @@ tls_handshake_req_init(struct handshake_req *req, treq->th_timeout_ms = args->ta_timeout_ms; treq->th_consumer_done = args->ta_done; treq->th_consumer_data = args->ta_data; + treq->th_peername = args->ta_peername; treq->th_keyring = args->ta_keyring; treq->th_num_peerids = 0; treq->th_certificate = TLS_NO_CERT; @@ -214,6 +216,12 @@ static int tls_handshake_accept(struct handshake_req *req, ret = nla_put_u32(msg, HANDSHAKE_A_ACCEPT_MESSAGE_TYPE, treq->th_type); if (ret < 0) goto out_cancel; + if (treq->th_peername) { + ret = nla_put_string(msg, HANDSHAKE_A_ACCEPT_PEERNAME, + treq->th_peername); + if (ret < 0) + goto out_cancel; + } if (treq->th_timeout_ms) { ret = nla_put_u32(msg, HANDSHAKE_A_ACCEPT_TIMEOUT, treq->th_timeout_ms); if (ret < 0)