Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2406297lqp; Sun, 24 Mar 2024 18:13:03 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXy5KhtLtwMFokl6V3n2k0nOo43BcXQMd0nVosBqnVoi3Z0NxzhB0t97dJpFU7N0yR60vJtYAoxX/UmYT6qUjupdOdfKX+ScYSqTd75mA== X-Google-Smtp-Source: AGHT+IHlI6EmnC+r6MipCOqfHYZxAqBUbqSADZwuPtK9aI8yKrA9mIgmnQcFMizwkYTNOunxuLRN X-Received: by 2002:a05:6a20:7489:b0:1a3:c51f:eda1 with SMTP id p9-20020a056a20748900b001a3c51feda1mr1967034pzd.39.1711329183172; Sun, 24 Mar 2024 18:13:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711329183; cv=pass; d=google.com; s=arc-20160816; b=pMZOLUGjQNW/W+we7lseoaZrL0gtOV6R+QbM/dBopk50nz2G0hqZPLwb/fSNlXXdow Rov2yTECHH+HWQaU39AERHzhWy9vmQLnkypP0Q5EBuEAvl+A7BZCEcoM5vcul6zwx8QU 5sjwIIgNVb8r+jrOoX7itZJF0xEm1XdlQPay5cFVQjdX0e0f+UppIbSsnEPjj6rEYg2W RUJ83ppbd/whNK/zD0Qm20J9bt2yexjt8kVNRToqK4mzT0GrtjQBEuIQl2LQaFEAoj2P lHoadCX1R3PMTtln0r7ymvgUzBASWdy6hx+uOVGnDeWiVrdUYNhGFfNdgnJ0c1zBQfm/ SqLg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=cKFebZH22U9gX5oed0hws0ygE6OTXHjtPM8/bp2oA2g=; fh=hzxKU1eLKnHF3Vg2t0e+Ubw10y7//B0+o/Vh2I1mFsg=; b=dgAgeurcjCUnl5GkZo0xAPyJUB/CR/gllNrfxCcBMDr9+djT17jIYydiWU3dzBG6fG vhpoPlHYZhaq/0cOESf4BpGcbzgJj2hf39CJCIwtFi0wUtK6Wx7i0J8t/KtFA0j1TnmD 79zFOhc8qq/8USHAzlzKlRrUcpkox6jmc5dLiG5oHpr0ou/hU23TTUtdOzBVIqXzXMFy VgWqhUvM4tnKUMHDaT72oLVfoqpe8mP636wXDEWd2y4a2gi3LDGd/E3Ocas4z+7Vk+UV S3d9Ok5v4+ku4tzOUc2aakG8wkqTMs86j+IBeuxSVHSqkdYNzVt5rEenYoI2ucr33Zqn 9tqg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=p7C9QsC6; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113484-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113484-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id b6-20020a170902650600b001db3a062d35si4158028plk.371.2024.03.24.18.13.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 18:13:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-113484-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=p7C9QsC6; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113484-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113484-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 27492B23024 for ; Mon, 25 Mar 2024 00:48:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4D75C1B6774; Sun, 24 Mar 2024 22:44:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="p7C9QsC6" 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 3D2F91B6750; Sun, 24 Mar 2024 22:44:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320285; cv=none; b=WWj7h0/bAnXqGnrF5s6deEVw1+stWWArlbHLqtfXVaW/EqbTggUnOfztfcm3M8GyB3Lzxs9P7GP1dp1BI8mEZyBPZqEd+Yvzc7Rdr7Tyc5a3aJF9AIDL7XIQGO1JHvdKsy38xfq+iIoU+Hncb8hrqhgoOp5PvFiQPoSjUzGFOIw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320285; c=relaxed/simple; bh=DfOoZsIT4CceyDNQSJzOMOwj8RU1jaP12MR59o7D7JM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nz0KMzo6VbmNhY9D5DN/tPx6m5/mHLsTgQfSiol4i1nE94jNIkk6hJsfy1dPL/bBSmhsvqquQWrZBMRGyVIARk/X4SflBXuiPngmK3ykhGGWzNRJwHlpT6kcc90hYnw75/RiAZSSgwI+s37l3jJ+y/CG6XjXlhNOYAIGyX9wa84= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=p7C9QsC6; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 80552C433F1; Sun, 24 Mar 2024 22:44:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711320285; bh=DfOoZsIT4CceyDNQSJzOMOwj8RU1jaP12MR59o7D7JM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p7C9QsC6Wl0EVJeMJe9Ay8zKbLZYWvvTgt6TS+1uj1Suu33bEsmiTE1fC7QcmbmqB aJOnWljpPoOmqLJyqC83bAW/mTuI6s4V7n5aLbuLYWHa0+NVYUY9ClE3go/kMekyx8 hVCLETsh3WZss+vAzCgVEq0283jqRhziY7NknmZpR1T9AbwXAVCJmgL4W6qVovY9j5 uieuQPwVFp2ZEvk7aYBa6rAnIScpQQjnRD5JsAKGckPdVW68D7qbtFayH0CalFgmET Na1fgQloxbBnlO3I1LjiJEobZG8k/15ACqLIkh8v21LLEMarlSAx0MODBHD3qkKixP Gjz8wh7jGQWDA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Olga Kornievskaia , Trond Myklebust , Sasha Levin Subject: [PATCH 6.8 593/715] NFSv4.1/pnfs: fix NFS with TLS in pnfs Date: Sun, 24 Mar 2024 18:32:52 -0400 Message-ID: <20240324223455.1342824-594-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324223455.1342824-1-sashal@kernel.org> References: <20240324223455.1342824-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Olga Kornievskaia [ Upstream commit a35518cae4b325632840bc8c3aa9ad9bac430038 ] Currently, even though xprtsec=tls is specified and used for operations to MDS, any operations that go to DS travel over unencrypted connection. Or additionally, if more than 1 DS can serve the data, then trunked connections are also done unencrypted. IN GETDEVINCEINFO, we get an entry for the DS which carries a protocol type (which is TCP), then nfs4_set_ds_client() gets called with TCP instead of TCP with TLS. Currently, each trunked connection is created and uses clp->cl_hostname value which if TLS is used would get passed up in the handshake upcall, but instead we need to pass in the appropriate trunked address value. Fixes: c8407f2e560c ("NFS: Add an "xprtsec=" NFS mount option") Signed-off-by: Olga Kornievskaia Signed-off-by: Trond Myklebust Signed-off-by: Sasha Levin --- fs/nfs/pnfs_nfs.c | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/fs/nfs/pnfs_nfs.c b/fs/nfs/pnfs_nfs.c index afd23910f3bff..88e061bd711b7 100644 --- a/fs/nfs/pnfs_nfs.c +++ b/fs/nfs/pnfs_nfs.c @@ -919,6 +919,8 @@ static int _nfs4_pnfs_v4_ds_connect(struct nfs_server *mds_srv, dprintk("--> %s DS %s\n", __func__, ds->ds_remotestr); list_for_each_entry(da, &ds->ds_addrs, da_node) { + char servername[48]; + dprintk("%s: DS %s: trying address %s\n", __func__, ds->ds_remotestr, da->da_remotestr); @@ -929,6 +931,7 @@ static int _nfs4_pnfs_v4_ds_connect(struct nfs_server *mds_srv, .dstaddr = (struct sockaddr *)&da->da_addr, .addrlen = da->da_addrlen, .servername = clp->cl_hostname, + .xprtsec = clp->cl_xprtsec, }; struct nfs4_add_xprt_data xprtdata = { .clp = clp, @@ -938,10 +941,45 @@ static int _nfs4_pnfs_v4_ds_connect(struct nfs_server *mds_srv, .data = &xprtdata, }; - if (da->da_transport != clp->cl_proto) + if (da->da_transport != clp->cl_proto && + clp->cl_proto != XPRT_TRANSPORT_TCP_TLS) continue; + if (da->da_transport == XPRT_TRANSPORT_TCP && + mds_srv->nfs_client->cl_proto == + XPRT_TRANSPORT_TCP_TLS) { + struct sockaddr *addr = + (struct sockaddr *)&da->da_addr; + struct sockaddr_in *sin = + (struct sockaddr_in *)&da->da_addr; + struct sockaddr_in6 *sin6 = + (struct sockaddr_in6 *)&da->da_addr; + + /* for NFS with TLS we need to supply a correct + * servername of the trunked transport, not the + * servername of the main transport stored in + * clp->cl_hostname. And set the protocol to + * indicate to use TLS + */ + servername[0] = '\0'; + switch(addr->sa_family) { + case AF_INET: + snprintf(servername, sizeof(servername), + "%pI4", &sin->sin_addr.s_addr); + break; + case AF_INET6: + snprintf(servername, sizeof(servername), + "%pI6", &sin6->sin6_addr); + break; + default: + /* do not consider this address */ + continue; + } + xprt_args.ident = XPRT_TRANSPORT_TCP_TLS; + xprt_args.servername = servername; + } if (da->da_addr.ss_family != clp->cl_addr.ss_family) continue; + /** * Test this address for session trunking and * add as an alias @@ -953,6 +991,10 @@ static int _nfs4_pnfs_v4_ds_connect(struct nfs_server *mds_srv, if (xprtdata.cred) put_cred(xprtdata.cred); } else { + if (da->da_transport == XPRT_TRANSPORT_TCP && + mds_srv->nfs_client->cl_proto == + XPRT_TRANSPORT_TCP_TLS) + da->da_transport = XPRT_TRANSPORT_TCP_TLS; clp = nfs4_set_ds_client(mds_srv, &da->da_addr, da->da_addrlen, -- 2.43.0