Skip to content

Commit 0c98c8e

Browse files
ZhaoLong Wangakpm00
authored andcommitted
tmpfs: fix the issue that the mount and remount results are inconsistent.
An undefined-behavior issue has not been completely fixed since commit d14f5ef ("tmpfs: fix undefined-behaviour in shmem_reconfigure()"). In the commit, check in the shmem_reconfigure() is added in remount process to avoid the Ubsan problem. However, the check is not added to the mount process. It causes inconsistent results between mount and remount. The operations to reproduce the problem in user mode as follows: If nr_blocks is set to 0x8000000000000000, the mounting is successful. # mount tmpfs /dev/shm/ -t tmpfs -o nr_blocks=0x8000000000000000 However, when -o remount is used, the mount fails because of the check in the shmem_reconfigure() # mount tmpfs /dev/shm/ -t tmpfs -o remount,nr_blocks=0x8000000000000000 mount: /dev/shm: mount point not mounted or bad option. Therefore, add checks in the shmem_parse_one() function and remove the check in shmem_reconfigure() to avoid this problem. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: ZhaoLong Wang <[email protected]> Cc: Luo Meng <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: Yu Kuai <[email protected]> Cc: Zhihao Cheng <[email protected]> Cc: Zhang Yi <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 07313a2 commit 0c98c8e

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

mm/shmem.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3392,7 +3392,7 @@ static int shmem_parse_one(struct fs_context *fc, struct fs_parameter *param)
33923392
break;
33933393
case Opt_nr_blocks:
33943394
ctx->blocks = memparse(param->string, &rest);
3395-
if (*rest)
3395+
if (*rest || ctx->blocks > S64_MAX)
33963396
goto bad_value;
33973397
ctx->seen |= SHMEM_SEEN_BLOCKS;
33983398
break;
@@ -3514,10 +3514,7 @@ static int shmem_reconfigure(struct fs_context *fc)
35143514

35153515
raw_spin_lock(&sbinfo->stat_lock);
35163516
inodes = sbinfo->max_inodes - sbinfo->free_inodes;
3517-
if (ctx->blocks > S64_MAX) {
3518-
err = "Number of blocks too large";
3519-
goto out;
3520-
}
3517+
35213518
if ((ctx->seen & SHMEM_SEEN_BLOCKS) && ctx->blocks) {
35223519
if (!sbinfo->max_blocks) {
35233520
err = "Cannot retroactively limit size";

0 commit comments

Comments
 (0)