hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/mm/shmem.c
....@@ -285,10 +285,10 @@
285285 ino_t ino;
286286
287287 if (!(sb->s_flags & SB_KERNMOUNT)) {
288
- raw_spin_lock(&sbinfo->stat_lock);
288
+ spin_lock(&sbinfo->stat_lock);
289289 if (sbinfo->max_inodes) {
290290 if (!sbinfo->free_inodes) {
291
- raw_spin_unlock(&sbinfo->stat_lock);
291
+ spin_unlock(&sbinfo->stat_lock);
292292 return -ENOSPC;
293293 }
294294 sbinfo->free_inodes--;
....@@ -311,7 +311,7 @@
311311 }
312312 *inop = ino;
313313 }
314
- raw_spin_unlock(&sbinfo->stat_lock);
314
+ spin_unlock(&sbinfo->stat_lock);
315315 } else if (inop) {
316316 /*
317317 * __shmem_file_setup, one of our callers, is lock-free: it
....@@ -326,14 +326,13 @@
326326 * to worry about things like glibc compatibility.
327327 */
328328 ino_t *next_ino;
329
-
330329 next_ino = per_cpu_ptr(sbinfo->ino_batch, get_cpu());
331330 ino = *next_ino;
332331 if (unlikely(ino % SHMEM_INO_BATCH == 0)) {
333
- raw_spin_lock(&sbinfo->stat_lock);
332
+ spin_lock(&sbinfo->stat_lock);
334333 ino = sbinfo->next_ino;
335334 sbinfo->next_ino += SHMEM_INO_BATCH;
336
- raw_spin_unlock(&sbinfo->stat_lock);
335
+ spin_unlock(&sbinfo->stat_lock);
337336 if (unlikely(is_zero_ino(ino)))
338337 ino++;
339338 }
....@@ -349,9 +348,9 @@
349348 {
350349 struct shmem_sb_info *sbinfo = SHMEM_SB(sb);
351350 if (sbinfo->max_inodes) {
352
- raw_spin_lock(&sbinfo->stat_lock);
351
+ spin_lock(&sbinfo->stat_lock);
353352 sbinfo->free_inodes++;
354
- raw_spin_unlock(&sbinfo->stat_lock);
353
+ spin_unlock(&sbinfo->stat_lock);
355354 }
356355 }
357356
....@@ -1493,10 +1492,10 @@
14931492 {
14941493 struct mempolicy *mpol = NULL;
14951494 if (sbinfo->mpol) {
1496
- raw_spin_lock(&sbinfo->stat_lock); /* prevent replace/use races */
1495
+ spin_lock(&sbinfo->stat_lock); /* prevent replace/use races */
14971496 mpol = sbinfo->mpol;
14981497 mpol_get(mpol);
1499
- raw_spin_unlock(&sbinfo->stat_lock);
1498
+ spin_unlock(&sbinfo->stat_lock);
15001499 }
15011500 return mpol;
15021501 }
....@@ -3425,6 +3424,8 @@
34253424 unsigned long long size;
34263425 char *rest;
34273426 int opt;
3427
+ kuid_t kuid;
3428
+ kgid_t kgid;
34283429
34293430 opt = fs_parse(fc, shmem_fs_parameters, param, &result);
34303431 if (opt < 0)
....@@ -3460,14 +3461,32 @@
34603461 ctx->mode = result.uint_32 & 07777;
34613462 break;
34623463 case Opt_uid:
3463
- ctx->uid = make_kuid(current_user_ns(), result.uint_32);
3464
- if (!uid_valid(ctx->uid))
3464
+ kuid = make_kuid(current_user_ns(), result.uint_32);
3465
+ if (!uid_valid(kuid))
34653466 goto bad_value;
3467
+
3468
+ /*
3469
+ * The requested uid must be representable in the
3470
+ * filesystem's idmapping.
3471
+ */
3472
+ if (!kuid_has_mapping(fc->user_ns, kuid))
3473
+ goto bad_value;
3474
+
3475
+ ctx->uid = kuid;
34663476 break;
34673477 case Opt_gid:
3468
- ctx->gid = make_kgid(current_user_ns(), result.uint_32);
3469
- if (!gid_valid(ctx->gid))
3478
+ kgid = make_kgid(current_user_ns(), result.uint_32);
3479
+ if (!gid_valid(kgid))
34703480 goto bad_value;
3481
+
3482
+ /*
3483
+ * The requested gid must be representable in the
3484
+ * filesystem's idmapping.
3485
+ */
3486
+ if (!kgid_has_mapping(fc->user_ns, kgid))
3487
+ goto bad_value;
3488
+
3489
+ ctx->gid = kgid;
34713490 break;
34723491 case Opt_huge:
34733492 ctx->huge = result.uint_32;
....@@ -3563,10 +3582,9 @@
35633582 struct shmem_options *ctx = fc->fs_private;
35643583 struct shmem_sb_info *sbinfo = SHMEM_SB(fc->root->d_sb);
35653584 unsigned long inodes;
3566
- struct mempolicy *mpol = NULL;
35673585 const char *err;
35683586
3569
- raw_spin_lock(&sbinfo->stat_lock);
3587
+ spin_lock(&sbinfo->stat_lock);
35703588 inodes = sbinfo->max_inodes - sbinfo->free_inodes;
35713589 if ((ctx->seen & SHMEM_SEEN_BLOCKS) && ctx->blocks) {
35723590 if (!sbinfo->max_blocks) {
....@@ -3611,15 +3629,14 @@
36113629 * Preserve previous mempolicy unless mpol remount option was specified.
36123630 */
36133631 if (ctx->mpol) {
3614
- mpol = sbinfo->mpol;
3632
+ mpol_put(sbinfo->mpol);
36153633 sbinfo->mpol = ctx->mpol; /* transfers initial ref */
36163634 ctx->mpol = NULL;
36173635 }
3618
- raw_spin_unlock(&sbinfo->stat_lock);
3619
- mpol_put(mpol);
3636
+ spin_unlock(&sbinfo->stat_lock);
36203637 return 0;
36213638 out:
3622
- raw_spin_unlock(&sbinfo->stat_lock);
3639
+ spin_unlock(&sbinfo->stat_lock);
36233640 return invalfc(fc, "%s", err);
36243641 }
36253642
....@@ -3736,7 +3753,7 @@
37363753 sbinfo->mpol = ctx->mpol;
37373754 ctx->mpol = NULL;
37383755
3739
- raw_spin_lock_init(&sbinfo->stat_lock);
3756
+ spin_lock_init(&sbinfo->stat_lock);
37403757 if (percpu_counter_init(&sbinfo->used_blocks, 0, GFP_KERNEL))
37413758 goto failed;
37423759 spin_lock_init(&sbinfo->shrinklist_lock);
....@@ -4103,7 +4120,7 @@
41034120 .name = "tmpfs",
41044121 .init_fs_context = ramfs_init_fs_context,
41054122 .parameters = ramfs_fs_parameters,
4106
- .kill_sb = kill_litter_super,
4123
+ .kill_sb = ramfs_kill_sb,
41074124 .fs_flags = FS_USERNS_MOUNT,
41084125 };
41094126