Keys on the per-namespace .nfs keyring need not grant user read permission once tlshd possesses the keyring, but nothing tells tlshd which keyring to possess. An xprtsec=mtls mount can present only keys that tlshd's own credentials can read, and one namespace's keys are not isolated from another's. Record the serial number of the namespace's .nfs keyring in the nfs_client's xprtsec parameters under the x509 policy, so tlshd possesses that keyring when it reads the certificate and private key. Signed-off-by: Chuck Lever --- fs/nfs/client.c | 9 ++++++++- fs/nfs/netns.h | 7 +++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/fs/nfs/client.c b/fs/nfs/client.c index 60386330aeec..bda1d19db527 100644 --- a/fs/nfs/client.c +++ b/fs/nfs/client.c @@ -191,6 +191,13 @@ struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_init) clp->cl_principal = "*"; clp->cl_xprtsec = cl_init->xprtsec; + /* + * Every client in a namespace names the same keyring, so + * nfs_match_client() does not compare keyring_serial. + */ + if (clp->cl_xprtsec.policy == RPC_XPRTSEC_TLS_X509) + clp->cl_xprtsec.keyring_serial = + key_serial(nfs_net_keyring(clp->cl_net)); return clp; error_cleanup: @@ -549,7 +556,7 @@ int nfs_create_rpc_client(struct nfs_client *clp, .version = clp->rpc_ops->version, .authflavor = flavor, .cred = cl_init->cred, - .xprtsec = cl_init->xprtsec, + .xprtsec = clp->cl_xprtsec, .connect_timeout = cl_init->connect_timeout, .reconnect_timeout = cl_init->reconnect_timeout, }; diff --git a/fs/nfs/netns.h b/fs/nfs/netns.h index da0854510404..c8ca7b989f4b 100644 --- a/fs/nfs/netns.h +++ b/fs/nfs/netns.h @@ -47,4 +47,11 @@ struct nfs_net { extern unsigned int nfs_net_id; +static inline struct key *nfs_net_keyring(struct net *net) +{ + struct nfs_net *nn = net_generic(net, nfs_net_id); + + return nn->nfs_keyring; +} + #endif -- 2.55.0