Skip to content

Commit a35518c

Browse files
olgakorn1Trond Myklebust
authored andcommitted
NFSv4.1/pnfs: fix NFS with TLS in pnfs
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: c8407f2 ("NFS: Add an "xprtsec=" NFS mount option") Signed-off-by: Olga Kornievskaia <kolga@netapp.com> Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
1 parent 698ad1a commit a35518c

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

fs/nfs/pnfs_nfs.c

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,8 @@ static int _nfs4_pnfs_v4_ds_connect(struct nfs_server *mds_srv,
919919
dprintk("--> %s DS %s\n", __func__, ds->ds_remotestr);
920920

921921
list_for_each_entry(da, &ds->ds_addrs, da_node) {
922+
char servername[48];
923+
922924
dprintk("%s: DS %s: trying address %s\n",
923925
__func__, ds->ds_remotestr, da->da_remotestr);
924926

@@ -929,6 +931,7 @@ static int _nfs4_pnfs_v4_ds_connect(struct nfs_server *mds_srv,
929931
.dstaddr = (struct sockaddr *)&da->da_addr,
930932
.addrlen = da->da_addrlen,
931933
.servername = clp->cl_hostname,
934+
.xprtsec = clp->cl_xprtsec,
932935
};
933936
struct nfs4_add_xprt_data xprtdata = {
934937
.clp = clp,
@@ -938,10 +941,45 @@ static int _nfs4_pnfs_v4_ds_connect(struct nfs_server *mds_srv,
938941
.data = &xprtdata,
939942
};
940943

941-
if (da->da_transport != clp->cl_proto)
944+
if (da->da_transport != clp->cl_proto &&
945+
clp->cl_proto != XPRT_TRANSPORT_TCP_TLS)
942946
continue;
947+
if (da->da_transport == XPRT_TRANSPORT_TCP &&
948+
mds_srv->nfs_client->cl_proto ==
949+
XPRT_TRANSPORT_TCP_TLS) {
950+
struct sockaddr *addr =
951+
(struct sockaddr *)&da->da_addr;
952+
struct sockaddr_in *sin =
953+
(struct sockaddr_in *)&da->da_addr;
954+
struct sockaddr_in6 *sin6 =
955+
(struct sockaddr_in6 *)&da->da_addr;
956+
957+
/* for NFS with TLS we need to supply a correct
958+
* servername of the trunked transport, not the
959+
* servername of the main transport stored in
960+
* clp->cl_hostname. And set the protocol to
961+
* indicate to use TLS
962+
*/
963+
servername[0] = '\0';
964+
switch(addr->sa_family) {
965+
case AF_INET:
966+
snprintf(servername, sizeof(servername),
967+
"%pI4", &sin->sin_addr.s_addr);
968+
break;
969+
case AF_INET6:
970+
snprintf(servername, sizeof(servername),
971+
"%pI6", &sin6->sin6_addr);
972+
break;
973+
default:
974+
/* do not consider this address */
975+
continue;
976+
}
977+
xprt_args.ident = XPRT_TRANSPORT_TCP_TLS;
978+
xprt_args.servername = servername;
979+
}
943980
if (da->da_addr.ss_family != clp->cl_addr.ss_family)
944981
continue;
982+
945983
/**
946984
* Test this address for session trunking and
947985
* add as an alias
@@ -953,6 +991,10 @@ static int _nfs4_pnfs_v4_ds_connect(struct nfs_server *mds_srv,
953991
if (xprtdata.cred)
954992
put_cred(xprtdata.cred);
955993
} else {
994+
if (da->da_transport == XPRT_TRANSPORT_TCP &&
995+
mds_srv->nfs_client->cl_proto ==
996+
XPRT_TRANSPORT_TCP_TLS)
997+
da->da_transport = XPRT_TRANSPORT_TCP_TLS;
956998
clp = nfs4_set_ds_client(mds_srv,
957999
&da->da_addr,
9581000
da->da_addrlen,

0 commit comments

Comments
 (0)