Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp4565038rwd; Tue, 30 May 2023 07:09:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7yrev2FNNy6Gbxsjd1/jfC2Z6DWDcO84LPHtTfaTeDv28hhB/v5SxthfubCs0QL70/2BO5 X-Received: by 2002:a05:6a20:7d83:b0:10a:a57a:9f7e with SMTP id v3-20020a056a207d8300b0010aa57a9f7emr2887887pzj.25.1685455748499; Tue, 30 May 2023 07:09:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685455748; cv=none; d=google.com; s=arc-20160816; b=v5oGyfcsOMR5fgeC+ozZ6TJq8tKXhy2bb15Rf2hvix3ZaYYGHuah7pnl5Kk5l/k3ti XZ0zzfqsbobMZ9pAznZfYv/hEMicZHMM6Hg3Ut3FhspV2yailrJL/foa0sfilNsOCIbS vURmNSmyCQloXFCjISMH9O4xuFYN765QE9GKpw6aWGtjfMKRjQBaCLGZbywBv231CBvC 9HsuBsiXfjsBAbe4sh1jX3/1v7pfa8hjvRLvimnGMN7mKip3/DUUpMLQLR2F3FSQBE6a sLmsd4WV15gqYt6MuZrd0VAG8rnJNBkP8OMciHB50F+gOE38vLcFrXdm/GxMZohOafML g/4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:dkim-signature; bh=fuTxpenLO+gXFJ/cSlquUWsDlARu/mB65Nx71MPuTqM=; b=FifRvuS/sr16d5pkUqhzepzV/lRqD/xMR8vgPJeDY41wZa30FcoLWSaTaa19Ap8Ymq SywyRuSJzi0nMTjphTr0FEV/Yc95LazJT5OS6rukFwooo7TgU12fkQbYuxwD2up1DjsZ 7YaBHII7pan/L+oH7nAaE9sFFgEMJU5uezpv2hhoCxdNbDY/vjxuxOG0ozRz7/MRlx8V IOgaijlH1jTBKE+vCJzq1EhkTjONIMk73cSiQF11l9BQgo8+TKatumoYFQfmBAl/yTT/ EAer1MRU7NP3CjChByVlD73oHu0V8wX+MLCEHsZJJdtMDfPWdDLW9nS5dk/IGWSkdF5s bIYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Vz3FmnxE; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i17-20020a63e911000000b0050f66d3f72csi10533683pgh.532.2023.05.30.07.08.55; Tue, 30 May 2023 07:09:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Vz3FmnxE; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232935AbjE3OI2 (ORCPT + 99 others); Tue, 30 May 2023 10:08:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232938AbjE3OI1 (ORCPT ); Tue, 30 May 2023 10:08:27 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB673EC for ; Tue, 30 May 2023 07:08:21 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 28383625A9 for ; Tue, 30 May 2023 14:08:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 11438C433D2; Tue, 30 May 2023 14:08:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685455700; bh=ofC3CZ4r/P3uLrWkpv9u764Q+NkU35iRcZ8sEshiWA0=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=Vz3FmnxEC6O60Rm82UvOG87SVF/2avgwD913z3f6ikj0MFCgI8sGVgTFv1z2tWluP NCbc544k/Nrp0f7WeEJxcoW7QMOc7ibBwgRYvzrKysLc4mrIwMDqIJnSGQudWfLuXa YeqB4AXi90YO+RsYNvowXiGKsJ7xCWwg9yzzPdDiR1XBjR0BYvbaJ3euExEJ0a4nRP ShLlCyO1IO4NT/TjJfsDPqH6EBweKnofymWrXIpAFRKHi5bkL1abPeQNkqphIEt0QN 297aQg+xi/MqLS/+uqltx0I4hpNuER6M5QMFXJsxk4HviE7qiGZbPgWk2OdPqjLAHw R8Kl+oI8aR1+g== Subject: [PATCH v3 07/11] SUNRPC: Add a connect worker function for TLS From: Chuck Lever To: anna.schumaker@netapp.com, trondmy@hammerspace.com Cc: Chuck Lever , Jeff Layton , jlayton@redhat.com, linux-nfs@vger.kernel.org, kernel-tls-handshake@lists.linux.dev Date: Tue, 30 May 2023 10:08:09 -0400 Message-ID: <168545567896.1917.14080628021266912546.stgit@oracle-102.nfsv4bat.org> In-Reply-To: <168545533442.1917.10040716812361925735.stgit@oracle-102.nfsv4bat.org> References: <168545533442.1917.10040716812361925735.stgit@oracle-102.nfsv4bat.org> User-Agent: StGit/1.5 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Chuck Lever Introduce a connect worker function that will handle the AUTH_TLS probe and TLS handshake, once a TCP connection is established. Signed-off-by: Chuck Lever Reviewed-by: Jeff Layton --- include/linux/sunrpc/xprtsock.h | 1 + net/sunrpc/xprtsock.c | 70 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/include/linux/sunrpc/xprtsock.h b/include/linux/sunrpc/xprtsock.h index daef030f4848..574a6a5391ba 100644 --- a/include/linux/sunrpc/xprtsock.h +++ b/include/linux/sunrpc/xprtsock.h @@ -60,6 +60,7 @@ struct sock_xprt { struct sockaddr_storage srcaddr; unsigned short srcport; int xprt_err; + struct rpc_clnt *clnt; /* * UDP socket buffer size parameters diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c index 6f2fc863b47e..7ea5984a52a3 100644 --- a/net/sunrpc/xprtsock.c +++ b/net/sunrpc/xprtsock.c @@ -2411,6 +2411,62 @@ static void xs_tcp_setup_socket(struct work_struct *work) current_restore_flags(pflags, PF_MEMALLOC); } +/** + * xs_tls_connect - establish a TLS session on a socket + * @work: queued work item + * + */ +static void xs_tls_connect(struct work_struct *work) +{ + struct sock_xprt *transport = + container_of(work, struct sock_xprt, connect_worker.work); + struct rpc_clnt *clnt; + + clnt = transport->clnt; + transport->clnt = NULL; + if (IS_ERR(clnt)) + goto out_unlock; + + xs_tcp_setup_socket(work); + + rpc_shutdown_client(clnt); + +out_unlock: + return; +} + +static void xs_set_transport_clnt(struct rpc_clnt *clnt, struct rpc_xprt *xprt) +{ + struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt); + struct rpc_create_args args = { + .net = xprt->xprt_net, + .protocol = xprt->prot, + .address = (struct sockaddr *)&xprt->addr, + .addrsize = xprt->addrlen, + .timeout = clnt->cl_timeout, + .servername = xprt->servername, + .nodename = clnt->cl_nodename, + .program = clnt->cl_program, + .prognumber = clnt->cl_prog, + .version = clnt->cl_vers, + .authflavor = RPC_AUTH_TLS, + .cred = clnt->cl_cred, + .xprtsec = { + .policy = RPC_XPRTSEC_NONE, + }, + .flags = RPC_CLNT_CREATE_NOPING, + }; + + switch (xprt->xprtsec.policy) { + case RPC_XPRTSEC_TLS_ANON: + case RPC_XPRTSEC_TLS_X509: + transport->clnt = rpc_create(&args); + break; + default: + transport->clnt = ERR_PTR(-ENOTCONN); + } +} + /** * xs_connect - connect a socket to a remote endpoint * @xprt: pointer to transport structure @@ -2442,6 +2498,8 @@ static void xs_connect(struct rpc_xprt *xprt, struct rpc_task *task) } else dprintk("RPC: xs_connect scheduled xprt %p\n", xprt); + xs_set_transport_clnt(task->tk_client, xprt); + queue_delayed_work(xprtiod_workqueue, &transport->connect_worker, delay); @@ -3057,7 +3115,17 @@ static struct rpc_xprt *xs_setup_tcp(struct xprt_create *args) INIT_WORK(&transport->recv_worker, xs_stream_data_receive_workfn); INIT_WORK(&transport->error_worker, xs_error_handle); - INIT_DELAYED_WORK(&transport->connect_worker, xs_tcp_setup_socket); + + xprt->xprtsec = args->xprtsec; + switch (args->xprtsec.policy) { + case RPC_XPRTSEC_NONE: + INIT_DELAYED_WORK(&transport->connect_worker, xs_tcp_setup_socket); + break; + case RPC_XPRTSEC_TLS_ANON: + case RPC_XPRTSEC_TLS_X509: + INIT_DELAYED_WORK(&transport->connect_worker, xs_tls_connect); + break; + } switch (addr->sa_family) { case AF_INET: