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

Configure Feed

Select the types of activity you want to include in your feed.

ext4: avoid potential buffer over-read in parse_apply_sb_mount_options()

Unlike other strings in the ext4 superblock, we rely on tune2fs to
make sure s_mount_opts is NUL terminated. Harden
parse_apply_sb_mount_options() by treating s_mount_opts as a potential
__nonstring.

Cc: stable@vger.kernel.org
Fixes: 8b67f04ab9de ("ext4: Add mount options in superblock")
Reviewed-by: Jan Kara <jack@suse.cz>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Message-ID: <20250916-tune2fs-v2-1-d594dc7486f0@mit.edu>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>

+5 -12
+5 -12
fs/ext4/super.c
··· 2469 2469 struct ext4_fs_context *m_ctx) 2470 2470 { 2471 2471 struct ext4_sb_info *sbi = EXT4_SB(sb); 2472 - char *s_mount_opts = NULL; 2472 + char s_mount_opts[65]; 2473 2473 struct ext4_fs_context *s_ctx = NULL; 2474 2474 struct fs_context *fc = NULL; 2475 2475 int ret = -ENOMEM; ··· 2477 2477 if (!sbi->s_es->s_mount_opts[0]) 2478 2478 return 0; 2479 2479 2480 - s_mount_opts = kstrndup(sbi->s_es->s_mount_opts, 2481 - sizeof(sbi->s_es->s_mount_opts), 2482 - GFP_KERNEL); 2483 - if (!s_mount_opts) 2484 - return ret; 2480 + strscpy_pad(s_mount_opts, sbi->s_es->s_mount_opts); 2485 2481 2486 2482 fc = kzalloc(sizeof(struct fs_context), GFP_KERNEL); 2487 2483 if (!fc) 2488 - goto out_free; 2484 + return -ENOMEM; 2489 2485 2490 2486 s_ctx = kzalloc(sizeof(struct ext4_fs_context), GFP_KERNEL); 2491 2487 if (!s_ctx) ··· 2513 2517 ret = 0; 2514 2518 2515 2519 out_free: 2516 - if (fc) { 2517 - ext4_fc_free(fc); 2518 - kfree(fc); 2519 - } 2520 - kfree(s_mount_opts); 2520 + ext4_fc_free(fc); 2521 + kfree(fc); 2521 2522 return ret; 2522 2523 } 2523 2524