Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

SUNRPC: Cache cred of process creating the rpc_client

When converting kuids to AUTH_UNIX creds, etc we will want to use the
same user namespace as the process that created the rpc client.

Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>

authored by

Trond Myklebust and committed by
Anna Schumaker
79caa5fa 2cfd11f1

+22 -2
+1
fs/lockd/host.c
··· 458 458 .authflavor = RPC_AUTH_UNIX, 459 459 .flags = (RPC_CLNT_CREATE_NOPING | 460 460 RPC_CLNT_CREATE_AUTOBIND), 461 + .cred = current_cred(), 461 462 }; 462 463 463 464 /*
+1
fs/lockd/mon.c
··· 82 82 .version = NSM_VERSION, 83 83 .authflavor = RPC_AUTH_NULL, 84 84 .flags = RPC_CLNT_CREATE_NOPING, 85 + .cred = current_cred(), 85 86 }; 86 87 87 88 return rpc_create(&args);
+1
fs/nfs/client.c
··· 500 500 .program = &nfs_program, 501 501 .version = clp->rpc_ops->version, 502 502 .authflavor = flavor, 503 + .cred = current_cred(), 503 504 }; 504 505 505 506 if (test_bit(NFS_CS_DISCRTRY, &clp->cl_flags))
+2
fs/nfs/mount_clnt.c
··· 163 163 .program = &mnt_program, 164 164 .version = info->version, 165 165 .authflavor = RPC_AUTH_UNIX, 166 + .cred = current_cred(), 166 167 }; 167 168 struct rpc_clnt *mnt_clnt; 168 169 int status; ··· 250 249 .version = info->version, 251 250 .authflavor = RPC_AUTH_UNIX, 252 251 .flags = RPC_CLNT_CREATE_NOPING, 252 + .cred = current_cred(), 253 253 }; 254 254 struct rpc_message msg = { 255 255 .rpc_argp = info->dirpath,
+1
fs/nfsd/nfs4callback.c
··· 868 868 .program = &cb_program, 869 869 .version = 1, 870 870 .flags = (RPC_CLNT_CREATE_NOPING | RPC_CLNT_CREATE_QUIET), 871 + .cred = current_cred(), 871 872 }; 872 873 struct rpc_clnt *client; 873 874 const struct cred *cred;
+2
include/linux/sunrpc/clnt.h
··· 72 72 struct dentry *cl_debugfs; /* debugfs directory */ 73 73 #endif 74 74 struct rpc_xprt_iter cl_xpi; 75 + const struct cred *cl_cred; 75 76 }; 76 77 77 78 /* ··· 127 126 unsigned long flags; 128 127 char *client_name; 129 128 struct svc_xprt *bc_xprt; /* NFSv4.1 backchannel */ 129 + const struct cred *cred; 130 130 }; 131 131 132 132 struct rpc_add_xprt_test {
+7
net/sunrpc/clnt.c
··· 394 394 if (err) 395 395 goto out_no_clid; 396 396 397 + clnt->cl_cred = get_cred(args->cred); 397 398 clnt->cl_procinfo = version->procs; 398 399 clnt->cl_maxproc = version->nrprocs; 399 400 clnt->cl_prog = args->prognumber ? : program->number; ··· 440 439 out_no_path: 441 440 rpc_free_iostats(clnt->cl_metrics); 442 441 out_no_stats: 442 + put_cred(clnt->cl_cred); 443 443 rpc_free_clid(clnt); 444 444 out_no_clid: 445 445 kfree(clnt); ··· 633 631 new->cl_discrtry = clnt->cl_discrtry; 634 632 new->cl_chatty = clnt->cl_chatty; 635 633 new->cl_principal = clnt->cl_principal; 634 + new->cl_cred = get_cred(clnt->cl_cred); 636 635 return new; 637 636 638 637 out_err: ··· 655 652 .prognumber = clnt->cl_prog, 656 653 .version = clnt->cl_vers, 657 654 .authflavor = clnt->cl_auth->au_flavor, 655 + .cred = clnt->cl_cred, 658 656 }; 659 657 return __rpc_clone_client(&args, clnt); 660 658 } ··· 677 673 .prognumber = clnt->cl_prog, 678 674 .version = clnt->cl_vers, 679 675 .authflavor = flavor, 676 + .cred = clnt->cl_cred, 680 677 }; 681 678 return __rpc_clone_client(&args, clnt); 682 679 } ··· 885 880 xprt_put(rcu_dereference_raw(clnt->cl_xprt)); 886 881 xprt_iter_destroy(&clnt->cl_xpi); 887 882 rpciod_down(); 883 + put_cred(clnt->cl_cred); 888 884 rpc_free_clid(clnt); 889 885 kfree(clnt); 890 886 return parent; ··· 950 944 .prognumber = program->number, 951 945 .version = vers, 952 946 .authflavor = old->cl_auth->au_flavor, 947 + .cred = old->cl_cred, 953 948 }; 954 949 struct rpc_clnt *clnt; 955 950 int err;
+7 -2
net/sunrpc/rpcb_clnt.c
··· 240 240 .program = &rpcb_program, 241 241 .version = RPCBVERS_2, 242 242 .authflavor = RPC_AUTH_NULL, 243 + .cred = current_cred(), 243 244 /* 244 245 * We turn off the idle timeout to prevent the kernel 245 246 * from automatically disconnecting the socket. ··· 300 299 .program = &rpcb_program, 301 300 .version = RPCBVERS_2, 302 301 .authflavor = RPC_AUTH_UNIX, 302 + .cred = current_cred(), 303 303 .flags = RPC_CLNT_CREATE_NOPING, 304 304 }; 305 305 struct rpc_clnt *clnt, *clnt4; ··· 360 358 static struct rpc_clnt *rpcb_create(struct net *net, const char *nodename, 361 359 const char *hostname, 362 360 struct sockaddr *srvaddr, size_t salen, 363 - int proto, u32 version) 361 + int proto, u32 version, 362 + const struct cred *cred) 364 363 { 365 364 struct rpc_create_args args = { 366 365 .net = net, ··· 373 370 .program = &rpcb_program, 374 371 .version = version, 375 372 .authflavor = RPC_AUTH_UNIX, 373 + .cred = cred, 376 374 .flags = (RPC_CLNT_CREATE_NOPING | 377 375 RPC_CLNT_CREATE_NONPRIVPORT), 378 376 }; ··· 749 745 rpcb_clnt = rpcb_create(xprt->xprt_net, 750 746 clnt->cl_nodename, 751 747 xprt->servername, sap, salen, 752 - xprt->prot, bind_version); 748 + xprt->prot, bind_version, 749 + clnt->cl_cred); 753 750 if (IS_ERR(rpcb_clnt)) { 754 751 status = PTR_ERR(rpcb_clnt); 755 752 dprintk("RPC: %5u %s: rpcb_create failed, error %ld\n",