Skip to content

Commit f11b2a1

Browse files
jtlaytontrondmypd
authored andcommitted
nfs4: copy acceptor name from context to nfs_client
The current CB_COMPOUND handling code tries to compare the principal name of the request with the cl_hostname in the client. This is not guaranteed to ever work, particularly if the client happened to mount a CNAME of the server or a non-fqdn. Fix this by instead comparing the cr_principal string with the acceptor name that we get from gssd. In the event that gssd didn't send one down (i.e. it was too old), then we fall back to trying to use the cl_hostname as we do today. Signed-off-by: Jeff Layton <jlayton@poochiereds.net> Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
1 parent a0337d1 commit f11b2a1

5 files changed

Lines changed: 47 additions & 1 deletion

File tree

‎fs/nfs/callback.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,18 @@ check_gss_callback_principal(struct nfs_client *clp, struct svc_rqst *rqstp)
428428
if (p == NULL)
429429
return 0;
430430

431+
/*
432+
* Did we get the acceptor from userland during the SETCLIENID
433+
* negotiation?
434+
*/
435+
if (clp->cl_acceptor)
436+
return !strcmp(p, clp->cl_acceptor);
437+
438+
/*
439+
* Otherwise try to verify it using the cl_hostname. Note that this
440+
* doesn't work if a non-canonical hostname was used in the devname.
441+
*/
442+
431443
/* Expect a GSS_C_NT_HOSTBASED_NAME like "nfs@serverhostname" */
432444

433445
if (memcmp(p, "nfs@", 4) != 0)

‎fs/nfs/client.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ void nfs_free_client(struct nfs_client *clp)
252252
put_net(clp->cl_net);
253253
put_nfs_version(clp->cl_nfs_mod);
254254
kfree(clp->cl_hostname);
255+
kfree(clp->cl_acceptor);
255256
kfree(clp);
256257

257258
dprintk("<-- nfs_free_client()\n");

‎fs/nfs/nfs4proc.c‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4936,6 +4936,18 @@ nfs4_init_callback_netid(const struct nfs_client *clp, char *buf, size_t len)
49364936
return scnprintf(buf, len, "tcp");
49374937
}
49384938

4939+
static void nfs4_setclientid_done(struct rpc_task *task, void *calldata)
4940+
{
4941+
struct nfs4_setclientid *sc = calldata;
4942+
4943+
if (task->tk_status == 0)
4944+
sc->sc_cred = get_rpccred(task->tk_rqstp->rq_cred);
4945+
}
4946+
4947+
static const struct rpc_call_ops nfs4_setclientid_ops = {
4948+
.rpc_call_done = nfs4_setclientid_done,
4949+
};
4950+
49394951
/**
49404952
* nfs4_proc_setclientid - Negotiate client ID
49414953
* @clp: state data structure
@@ -4962,6 +4974,14 @@ int nfs4_proc_setclientid(struct nfs_client *clp, u32 program,
49624974
.rpc_resp = res,
49634975
.rpc_cred = cred,
49644976
};
4977+
struct rpc_task *task;
4978+
struct rpc_task_setup task_setup_data = {
4979+
.rpc_client = clp->cl_rpcclient,
4980+
.rpc_message = &msg,
4981+
.callback_ops = &nfs4_setclientid_ops,
4982+
.callback_data = &setclientid,
4983+
.flags = RPC_TASK_TIMEOUT,
4984+
};
49654985
int status;
49664986

49674987
/* nfs_client_id4 */
@@ -4988,7 +5008,18 @@ int nfs4_proc_setclientid(struct nfs_client *clp, u32 program,
49885008
dprintk("NFS call setclientid auth=%s, '%.*s'\n",
49895009
clp->cl_rpcclient->cl_auth->au_ops->au_name,
49905010
setclientid.sc_name_len, setclientid.sc_name);
4991-
status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
5011+
task = rpc_run_task(&task_setup_data);
5012+
if (IS_ERR(task)) {
5013+
status = PTR_ERR(task);
5014+
goto out;
5015+
}
5016+
status = task->tk_status;
5017+
if (setclientid.sc_cred) {
5018+
clp->cl_acceptor = rpcauth_stringify_acceptor(setclientid.sc_cred);
5019+
put_rpccred(setclientid.sc_cred);
5020+
}
5021+
rpc_put_task(task);
5022+
out:
49925023
trace_nfs4_setclientid(clp, status);
49935024
dprintk("NFS reply setclientid: %d\n", status);
49945025
return status;

‎include/linux/nfs_fs_sb.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ struct nfs_client {
4545
struct sockaddr_storage cl_addr; /* server identifier */
4646
size_t cl_addrlen;
4747
char * cl_hostname; /* hostname of server */
48+
char * cl_acceptor; /* GSSAPI acceptor name */
4849
struct list_head cl_share_link; /* link in global client list */
4950
struct list_head cl_superblocks; /* List of nfs_server structs */
5051

‎include/linux/nfs_xdr.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,7 @@ struct nfs4_setclientid {
993993
unsigned int sc_uaddr_len;
994994
char sc_uaddr[RPCBIND_MAXUADDRLEN + 1];
995995
u32 sc_cb_ident;
996+
struct rpc_cred *sc_cred;
996997
};
997998

998999
struct nfs4_setclientid_res {

0 commit comments

Comments
 (0)