Skip to content

Commit 700a800

Browse files
committed
Merge tag 'nfsd-5.2' of git://linux-nfs.org/~bfields/linux
Pull nfsd updates from Bruce Fields: "This consists mostly of nfsd container work: Scott Mayhew revived an old api that communicates with a userspace daemon to manage some on-disk state that's used to track clients across server reboots. We've been using a usermode_helper upcall for that, but it's tough to run those with the right namespaces, so a daemon is much friendlier to container use cases. Trond fixed nfsd's handling of user credentials in user namespaces. He also contributed patches that allow containers to support different sets of NFS protocol versions. The only remaining container bug I'm aware of is that the NFS reply cache is shared between all containers. If anyone's aware of other gaps in our container support, let me know. The rest of this is miscellaneous bugfixes" * tag 'nfsd-5.2' of git://linux-nfs.org/~bfields/linux: (23 commits) nfsd: update callback done processing locks: move checks from locks_free_lock() to locks_release_private() nfsd: fh_drop_write in nfsd_unlink nfsd: allow fh_want_write to be called twice nfsd: knfsd must use the container user namespace SUNRPC: rsi_parse() should use the current user namespace SUNRPC: Fix the server AUTH_UNIX userspace mappings lockd: Pass the user cred from knfsd when starting the lockd server SUNRPC: Temporary sockets should inherit the cred from their parent SUNRPC: Cache the process user cred in the RPC server listener nfsd: Allow containers to set supported nfs versions nfsd: Add custom rpcbind callbacks for knfsd SUNRPC: Allow further customisation of RPC program registration SUNRPC: Clean up generic dispatcher code SUNRPC: Add a callback to initialise server requests SUNRPC/nfs: Fix return value for nfs4_callback_compound() nfsd: handle legacy client tracking records sent by nfsdcld nfsd: re-order client tracking method selection nfsd: keep a tally of RECLAIM_COMPLETE operations when using nfsdcld nfsd: un-deprecate nfsdcld ...
2 parents b06ed1e + 1c73b9d commit 700a800

34 files changed

Lines changed: 1085 additions & 316 deletions

‎fs/lockd/clntlock.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ struct nlm_host *nlmclnt_init(const struct nlmclnt_initdata *nlm_init)
5656
u32 nlm_version = (nlm_init->nfs_version == 2) ? 1 : 4;
5757
int status;
5858

59-
status = lockd_up(nlm_init->net);
59+
status = lockd_up(nlm_init->net, nlm_init->cred);
6060
if (status < 0)
6161
return ERR_PTR(status);
6262

@@ -241,7 +241,7 @@ reclaimer(void *ptr)
241241
allow_signal(SIGKILL);
242242

243243
down_write(&host->h_rwsem);
244-
lockd_up(net); /* note: this cannot fail as lockd is already running */
244+
lockd_up(net, NULL); /* note: this cannot fail as lockd is already running */
245245

246246
dprintk("lockd: reclaiming locks for host %s\n", host->h_name);
247247

‎fs/lockd/svc.c‎

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -188,28 +188,31 @@ lockd(void *vrqstp)
188188

189189
static int create_lockd_listener(struct svc_serv *serv, const char *name,
190190
struct net *net, const int family,
191-
const unsigned short port)
191+
const unsigned short port,
192+
const struct cred *cred)
192193
{
193194
struct svc_xprt *xprt;
194195

195196
xprt = svc_find_xprt(serv, name, net, family, 0);
196197
if (xprt == NULL)
197198
return svc_create_xprt(serv, name, net, family, port,
198-
SVC_SOCK_DEFAULTS);
199+
SVC_SOCK_DEFAULTS, cred);
199200
svc_xprt_put(xprt);
200201
return 0;
201202
}
202203

203204
static int create_lockd_family(struct svc_serv *serv, struct net *net,
204-
const int family)
205+
const int family, const struct cred *cred)
205206
{
206207
int err;
207208

208-
err = create_lockd_listener(serv, "udp", net, family, nlm_udpport);
209+
err = create_lockd_listener(serv, "udp", net, family, nlm_udpport,
210+
cred);
209211
if (err < 0)
210212
return err;
211213

212-
return create_lockd_listener(serv, "tcp", net, family, nlm_tcpport);
214+
return create_lockd_listener(serv, "tcp", net, family, nlm_tcpport,
215+
cred);
213216
}
214217

215218
/*
@@ -222,16 +225,17 @@ static int create_lockd_family(struct svc_serv *serv, struct net *net,
222225
* Returns zero if all listeners are available; otherwise a
223226
* negative errno value is returned.
224227
*/
225-
static int make_socks(struct svc_serv *serv, struct net *net)
228+
static int make_socks(struct svc_serv *serv, struct net *net,
229+
const struct cred *cred)
226230
{
227231
static int warned;
228232
int err;
229233

230-
err = create_lockd_family(serv, net, PF_INET);
234+
err = create_lockd_family(serv, net, PF_INET, cred);
231235
if (err < 0)
232236
goto out_err;
233237

234-
err = create_lockd_family(serv, net, PF_INET6);
238+
err = create_lockd_family(serv, net, PF_INET6, cred);
235239
if (err < 0 && err != -EAFNOSUPPORT)
236240
goto out_err;
237241

@@ -246,7 +250,8 @@ static int make_socks(struct svc_serv *serv, struct net *net)
246250
return err;
247251
}
248252

249-
static int lockd_up_net(struct svc_serv *serv, struct net *net)
253+
static int lockd_up_net(struct svc_serv *serv, struct net *net,
254+
const struct cred *cred)
250255
{
251256
struct lockd_net *ln = net_generic(net, lockd_net_id);
252257
int error;
@@ -258,7 +263,7 @@ static int lockd_up_net(struct svc_serv *serv, struct net *net)
258263
if (error)
259264
goto err_bind;
260265

261-
error = make_socks(serv, net);
266+
error = make_socks(serv, net, cred);
262267
if (error < 0)
263268
goto err_bind;
264269
set_grace_period(net);
@@ -461,7 +466,7 @@ static struct svc_serv *lockd_create_svc(void)
461466
/*
462467
* Bring up the lockd process if it's not already up.
463468
*/
464-
int lockd_up(struct net *net)
469+
int lockd_up(struct net *net, const struct cred *cred)
465470
{
466471
struct svc_serv *serv;
467472
int error;
@@ -474,7 +479,7 @@ int lockd_up(struct net *net)
474479
goto err_create;
475480
}
476481

477-
error = lockd_up_net(serv, net);
482+
error = lockd_up_net(serv, net, cred);
478483
if (error < 0) {
479484
lockd_unregister_notifiers();
480485
goto err_put;
@@ -807,5 +812,7 @@ static struct svc_program nlmsvc_program = {
807812
.pg_name = "lockd", /* service name */
808813
.pg_class = "nfsd", /* share authentication with nfsd */
809814
.pg_stats = &nlmsvc_stats, /* stats table */
810-
.pg_authenticate = &lockd_authenticate /* export authentication */
815+
.pg_authenticate = &lockd_authenticate, /* export authentication */
816+
.pg_init_request = svc_generic_init_request,
817+
.pg_rpcbind_set = svc_generic_rpcbind_set,
811818
};

‎fs/locks.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,12 @@ EXPORT_SYMBOL_GPL(locks_alloc_lock);
352352

353353
void locks_release_private(struct file_lock *fl)
354354
{
355+
BUG_ON(waitqueue_active(&fl->fl_wait));
356+
BUG_ON(!list_empty(&fl->fl_list));
357+
BUG_ON(!list_empty(&fl->fl_blocked_requests));
358+
BUG_ON(!list_empty(&fl->fl_blocked_member));
359+
BUG_ON(!hlist_unhashed(&fl->fl_link));
360+
355361
if (fl->fl_ops) {
356362
if (fl->fl_ops->fl_release_private)
357363
fl->fl_ops->fl_release_private(fl);
@@ -371,12 +377,6 @@ EXPORT_SYMBOL_GPL(locks_release_private);
371377
/* Free a lock which is not in use. */
372378
void locks_free_lock(struct file_lock *fl)
373379
{
374-
BUG_ON(waitqueue_active(&fl->fl_wait));
375-
BUG_ON(!list_empty(&fl->fl_list));
376-
BUG_ON(!list_empty(&fl->fl_blocked_requests));
377-
BUG_ON(!list_empty(&fl->fl_blocked_member));
378-
BUG_ON(!hlist_unhashed(&fl->fl_link));
379-
380380
locks_release_private(fl);
381381
kmem_cache_free(filelock_cache, fl);
382382
}

‎fs/nfs/callback.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,22 @@ static struct svc_program nfs4_callback_program;
4141

4242
static int nfs4_callback_up_net(struct svc_serv *serv, struct net *net)
4343
{
44+
const struct cred *cred = current_cred();
4445
int ret;
4546
struct nfs_net *nn = net_generic(net, nfs_net_id);
4647

4748
ret = svc_create_xprt(serv, "tcp", net, PF_INET,
48-
nfs_callback_set_tcpport, SVC_SOCK_ANONYMOUS);
49+
nfs_callback_set_tcpport, SVC_SOCK_ANONYMOUS,
50+
cred);
4951
if (ret <= 0)
5052
goto out_err;
5153
nn->nfs_callback_tcpport = ret;
5254
dprintk("NFS: Callback listener port = %u (af %u, net %x)\n",
5355
nn->nfs_callback_tcpport, PF_INET, net->ns.inum);
5456

5557
ret = svc_create_xprt(serv, "tcp", net, PF_INET6,
56-
nfs_callback_set_tcpport, SVC_SOCK_ANONYMOUS);
58+
nfs_callback_set_tcpport, SVC_SOCK_ANONYMOUS,
59+
cred);
5760
if (ret > 0) {
5861
nn->nfs_callback_tcpport6 = ret;
5962
dprintk("NFS: Callback listener port = %u (af %u, net %x)\n",
@@ -457,4 +460,6 @@ static struct svc_program nfs4_callback_program = {
457460
.pg_class = "nfs", /* authentication class */
458461
.pg_stats = &nfs4_callback_stats,
459462
.pg_authenticate = nfs_callback_authenticate,
463+
.pg_init_request = svc_generic_init_request,
464+
.pg_rpcbind_set = svc_generic_rpcbind_set,
460465
};

‎fs/nfs/callback_xdr.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ static __be32 nfs4_callback_compound(struct svc_rqst *rqstp)
983983

984984
out_invalidcred:
985985
pr_warn_ratelimited("NFS: NFSv4 callback contains invalid cred\n");
986-
return rpc_autherr_badcred;
986+
return svc_return_autherr(rqstp, rpc_autherr_badcred);
987987
}
988988

989989
/*

‎fs/nfs/client.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,7 @@ static int nfs_start_lockd(struct nfs_server *server)
558558
1 : 0,
559559
.net = clp->cl_net,
560560
.nlmclnt_ops = clp->cl_nfs_mod->rpc_ops->nlmclnt_ops,
561+
.cred = current_cred(),
561562
};
562563

563564
if (nlm_init.nfs_version > 3)

‎fs/nfsd/export.c‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -570,13 +570,13 @@ static int svc_export_parse(struct cache_detail *cd, char *mesg, int mlen)
570570
err = get_int(&mesg, &an_int);
571571
if (err)
572572
goto out3;
573-
exp.ex_anon_uid= make_kuid(&init_user_ns, an_int);
573+
exp.ex_anon_uid= make_kuid(current_user_ns(), an_int);
574574

575575
/* anon gid */
576576
err = get_int(&mesg, &an_int);
577577
if (err)
578578
goto out3;
579-
exp.ex_anon_gid= make_kgid(&init_user_ns, an_int);
579+
exp.ex_anon_gid= make_kgid(current_user_ns(), an_int);
580580

581581
/* fsid */
582582
err = get_int(&mesg, &an_int);
@@ -1170,15 +1170,17 @@ static void show_secinfo(struct seq_file *m, struct svc_export *exp)
11701170
static void exp_flags(struct seq_file *m, int flag, int fsid,
11711171
kuid_t anonu, kgid_t anong, struct nfsd4_fs_locations *fsloc)
11721172
{
1173+
struct user_namespace *userns = m->file->f_cred->user_ns;
1174+
11731175
show_expflags(m, flag, NFSEXP_ALLFLAGS);
11741176
if (flag & NFSEXP_FSID)
11751177
seq_printf(m, ",fsid=%d", fsid);
1176-
if (!uid_eq(anonu, make_kuid(&init_user_ns, (uid_t)-2)) &&
1177-
!uid_eq(anonu, make_kuid(&init_user_ns, 0x10000-2)))
1178-
seq_printf(m, ",anonuid=%u", from_kuid(&init_user_ns, anonu));
1179-
if (!gid_eq(anong, make_kgid(&init_user_ns, (gid_t)-2)) &&
1180-
!gid_eq(anong, make_kgid(&init_user_ns, 0x10000-2)))
1181-
seq_printf(m, ",anongid=%u", from_kgid(&init_user_ns, anong));
1178+
if (!uid_eq(anonu, make_kuid(userns, (uid_t)-2)) &&
1179+
!uid_eq(anonu, make_kuid(userns, 0x10000-2)))
1180+
seq_printf(m, ",anonuid=%u", from_kuid_munged(userns, anonu));
1181+
if (!gid_eq(anong, make_kgid(userns, (gid_t)-2)) &&
1182+
!gid_eq(anong, make_kgid(userns, 0x10000-2)))
1183+
seq_printf(m, ",anongid=%u", from_kgid_munged(userns, anong));
11821184
if (fsloc && fsloc->locations_count > 0) {
11831185
char *loctype = (fsloc->migrated) ? "refer" : "replicas";
11841186
int i;

‎fs/nfsd/netns.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ struct nfsd_net {
104104
time_t nfsd4_grace;
105105
bool somebody_reclaimed;
106106

107+
bool track_reclaim_completes;
108+
atomic_t nr_reclaim_complete;
109+
107110
bool nfsd_net_up;
108111
bool lockd_up;
109112

@@ -131,10 +134,18 @@ struct nfsd_net {
131134
u32 s2s_cp_cl_id;
132135
struct idr s2s_cp_stateids;
133136
spinlock_t s2s_cp_lock;
137+
138+
/*
139+
* Version information
140+
*/
141+
bool *nfsd_versions;
142+
bool *nfsd4_minorversions;
134143
};
135144

136145
/* Simple check to find out if a given net was properly initialized */
137146
#define nfsd_netns_ready(nn) ((nn)->sessionid_hashtbl)
138147

148+
extern void nfsd_netns_free_versions(struct nfsd_net *nn);
149+
139150
extern unsigned int nfsd_net_id;
140151
#endif /* __NFSD_NETNS_H__ */

‎fs/nfsd/nfs3xdr.c‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ decode_filename(__be32 *p, char **namp, unsigned int *lenp)
9696
}
9797

9898
static __be32 *
99-
decode_sattr3(__be32 *p, struct iattr *iap)
99+
decode_sattr3(__be32 *p, struct iattr *iap, struct user_namespace *userns)
100100
{
101101
u32 tmp;
102102

@@ -107,12 +107,12 @@ decode_sattr3(__be32 *p, struct iattr *iap)
107107
iap->ia_mode = ntohl(*p++);
108108
}
109109
if (*p++) {
110-
iap->ia_uid = make_kuid(&init_user_ns, ntohl(*p++));
110+
iap->ia_uid = make_kuid(userns, ntohl(*p++));
111111
if (uid_valid(iap->ia_uid))
112112
iap->ia_valid |= ATTR_UID;
113113
}
114114
if (*p++) {
115-
iap->ia_gid = make_kgid(&init_user_ns, ntohl(*p++));
115+
iap->ia_gid = make_kgid(userns, ntohl(*p++));
116116
if (gid_valid(iap->ia_gid))
117117
iap->ia_valid |= ATTR_GID;
118118
}
@@ -165,12 +165,13 @@ static __be32 *
165165
encode_fattr3(struct svc_rqst *rqstp, __be32 *p, struct svc_fh *fhp,
166166
struct kstat *stat)
167167
{
168+
struct user_namespace *userns = nfsd_user_namespace(rqstp);
168169
struct timespec ts;
169170
*p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
170171
*p++ = htonl((u32) (stat->mode & S_IALLUGO));
171172
*p++ = htonl((u32) stat->nlink);
172-
*p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
173-
*p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
173+
*p++ = htonl((u32) from_kuid_munged(userns, stat->uid));
174+
*p++ = htonl((u32) from_kgid_munged(userns, stat->gid));
174175
if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
175176
p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
176177
} else {
@@ -325,7 +326,7 @@ nfs3svc_decode_sattrargs(struct svc_rqst *rqstp, __be32 *p)
325326
p = decode_fh(p, &args->fh);
326327
if (!p)
327328
return 0;
328-
p = decode_sattr3(p, &args->attrs);
329+
p = decode_sattr3(p, &args->attrs, nfsd_user_namespace(rqstp));
329330

330331
if ((args->check_guard = ntohl(*p++)) != 0) {
331332
struct timespec time;
@@ -455,7 +456,7 @@ nfs3svc_decode_createargs(struct svc_rqst *rqstp, __be32 *p)
455456
switch (args->createmode = ntohl(*p++)) {
456457
case NFS3_CREATE_UNCHECKED:
457458
case NFS3_CREATE_GUARDED:
458-
p = decode_sattr3(p, &args->attrs);
459+
p = decode_sattr3(p, &args->attrs, nfsd_user_namespace(rqstp));
459460
break;
460461
case NFS3_CREATE_EXCLUSIVE:
461462
args->verf = p;
@@ -476,7 +477,7 @@ nfs3svc_decode_mkdirargs(struct svc_rqst *rqstp, __be32 *p)
476477
if (!(p = decode_fh(p, &args->fh)) ||
477478
!(p = decode_filename(p, &args->name, &args->len)))
478479
return 0;
479-
p = decode_sattr3(p, &args->attrs);
480+
p = decode_sattr3(p, &args->attrs, nfsd_user_namespace(rqstp));
480481

481482
return xdr_argsize_check(rqstp, p);
482483
}
@@ -491,7 +492,7 @@ nfs3svc_decode_symlinkargs(struct svc_rqst *rqstp, __be32 *p)
491492
if (!(p = decode_fh(p, &args->ffh)) ||
492493
!(p = decode_filename(p, &args->fname, &args->flen)))
493494
return 0;
494-
p = decode_sattr3(p, &args->attrs);
495+
p = decode_sattr3(p, &args->attrs, nfsd_user_namespace(rqstp));
495496

496497
args->tlen = ntohl(*p++);
497498

@@ -519,7 +520,7 @@ nfs3svc_decode_mknodargs(struct svc_rqst *rqstp, __be32 *p)
519520

520521
if (args->ftype == NF3BLK || args->ftype == NF3CHR
521522
|| args->ftype == NF3SOCK || args->ftype == NF3FIFO)
522-
p = decode_sattr3(p, &args->attrs);
523+
p = decode_sattr3(p, &args->attrs, nfsd_user_namespace(rqstp));
523524

524525
if (args->ftype == NF3BLK || args->ftype == NF3CHR) {
525526
args->major = ntohl(*p++);

‎fs/nfsd/nfs4callback.c‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,10 +1123,11 @@ static void nfsd4_cb_done(struct rpc_task *task, void *calldata)
11231123
rpc_restart_call_prepare(task);
11241124
return;
11251125
case 1:
1126-
break;
1127-
case -1:
1128-
/* Network partition? */
1129-
nfsd4_mark_cb_down(clp, task->tk_status);
1126+
switch (task->tk_status) {
1127+
case -EIO:
1128+
case -ETIMEDOUT:
1129+
nfsd4_mark_cb_down(clp, task->tk_status);
1130+
}
11301131
break;
11311132
default:
11321133
BUG();

0 commit comments

Comments
 (0)