hc
2024-05-14 bedbef8ad3e75a304af6361af235302bcc61d06b
kernel/fs/nfsd/nfs4idmap.c
....@@ -65,6 +65,7 @@
6565 u32 id;
6666 char name[IDMAP_NAMESZ];
6767 char authname[IDMAP_NAMESZ];
68
+ struct rcu_head rcu_head;
6869 };
6970
7071 /* Common entry handling */
....@@ -82,14 +83,14 @@
8283 new->type = itm->type;
8384
8485 strlcpy(new->name, itm->name, sizeof(new->name));
85
- strlcpy(new->authname, itm->authname, sizeof(new->name));
86
+ strlcpy(new->authname, itm->authname, sizeof(new->authname));
8687 }
8788
8889 static void
8990 ent_put(struct kref *ref)
9091 {
9192 struct ent *map = container_of(ref, struct ent, h.ref);
92
- kfree(map);
93
+ kfree_rcu(map, rcu_head);
9394 }
9495
9596 static struct cache_head *
....@@ -119,6 +120,12 @@
119120 hash ^= 1;
120121
121122 return hash;
123
+}
124
+
125
+static int
126
+idtoname_upcall(struct cache_detail *cd, struct cache_head *h)
127
+{
128
+ return sunrpc_cache_pipe_upcall_timeout(cd, h);
122129 }
123130
124131 static void
....@@ -161,7 +168,7 @@
161168 ent->id);
162169 if (test_bit(CACHE_VALID, &h->flags))
163170 seq_printf(m, " %s", ent->name);
164
- seq_printf(m, "\n");
171
+ seq_putc(m, '\n');
165172 return 0;
166173 }
167174
....@@ -183,6 +190,7 @@
183190 .hash_size = ENT_HASHMAX,
184191 .name = "nfs4.idtoname",
185192 .cache_put = ent_put,
193
+ .cache_upcall = idtoname_upcall,
186194 .cache_request = idtoname_request,
187195 .cache_parse = idtoname_parse,
188196 .cache_show = idtoname_show,
....@@ -264,8 +272,8 @@
264272 static struct ent *
265273 idtoname_lookup(struct cache_detail *cd, struct ent *item)
266274 {
267
- struct cache_head *ch = sunrpc_cache_lookup(cd, &item->h,
268
- idtoname_hash(item));
275
+ struct cache_head *ch = sunrpc_cache_lookup_rcu(cd, &item->h,
276
+ idtoname_hash(item));
269277 if (ch)
270278 return container_of(ch, struct ent, h);
271279 else
....@@ -292,6 +300,12 @@
292300 nametoid_hash(struct ent *ent)
293301 {
294302 return hash_str(ent->name, ENT_HASHBITS);
303
+}
304
+
305
+static int
306
+nametoid_upcall(struct cache_detail *cd, struct cache_head *h)
307
+{
308
+ return sunrpc_cache_pipe_upcall_timeout(cd, h);
295309 }
296310
297311 static void
....@@ -332,7 +346,7 @@
332346 ent->name);
333347 if (test_bit(CACHE_VALID, &h->flags))
334348 seq_printf(m, " %u", ent->id);
335
- seq_printf(m, "\n");
349
+ seq_putc(m, '\n');
336350 return 0;
337351 }
338352
....@@ -346,6 +360,7 @@
346360 .hash_size = ENT_HASHMAX,
347361 .name = "nfs4.nametoid",
348362 .cache_put = ent_put,
363
+ .cache_upcall = nametoid_upcall,
349364 .cache_request = nametoid_request,
350365 .cache_parse = nametoid_parse,
351366 .cache_show = nametoid_show,
....@@ -422,8 +437,8 @@
422437 static struct ent *
423438 nametoid_lookup(struct cache_detail *cd, struct ent *item)
424439 {
425
- struct cache_head *ch = sunrpc_cache_lookup(cd, &item->h,
426
- nametoid_hash(item));
440
+ struct cache_head *ch = sunrpc_cache_lookup_rcu(cd, &item->h,
441
+ nametoid_hash(item));
427442 if (ch)
428443 return container_of(ch, struct ent, h);
429444 else
....@@ -633,7 +648,7 @@
633648 return nfserr_inval;
634649
635650 status = do_name_to_id(rqstp, IDMAP_TYPE_USER, name, namelen, &id);
636
- *uid = make_kuid(&init_user_ns, id);
651
+ *uid = make_kuid(nfsd_user_namespace(rqstp), id);
637652 if (!uid_valid(*uid))
638653 status = nfserr_badowner;
639654 return status;
....@@ -650,7 +665,7 @@
650665 return nfserr_inval;
651666
652667 status = do_name_to_id(rqstp, IDMAP_TYPE_GROUP, name, namelen, &id);
653
- *gid = make_kgid(&init_user_ns, id);
668
+ *gid = make_kgid(nfsd_user_namespace(rqstp), id);
654669 if (!gid_valid(*gid))
655670 status = nfserr_badowner;
656671 return status;
....@@ -659,13 +674,13 @@
659674 __be32 nfsd4_encode_user(struct xdr_stream *xdr, struct svc_rqst *rqstp,
660675 kuid_t uid)
661676 {
662
- u32 id = from_kuid(&init_user_ns, uid);
677
+ u32 id = from_kuid_munged(nfsd_user_namespace(rqstp), uid);
663678 return encode_name_from_id(xdr, rqstp, IDMAP_TYPE_USER, id);
664679 }
665680
666681 __be32 nfsd4_encode_group(struct xdr_stream *xdr, struct svc_rqst *rqstp,
667682 kgid_t gid)
668683 {
669
- u32 id = from_kgid(&init_user_ns, gid);
684
+ u32 id = from_kgid_munged(nfsd_user_namespace(rqstp), gid);
670685 return encode_name_from_id(xdr, rqstp, IDMAP_TYPE_GROUP, id);
671686 }