Skip to content

Commit a6e9455

Browse files
tytsogregkh
authored andcommitted
ext4: avoid potential buffer over-read in parse_apply_sb_mount_options()
commit 8ecb790ea8c3fc69e77bace57f14cf0d7c177bd8 upstream. 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: [email protected] Fixes: 8b67f04 ("ext4: Add mount options in superblock") Reviewed-by: Jan Kara <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Theodore Ts'o <[email protected]> Message-ID: <[email protected]> Signed-off-by: Theodore Ts'o <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 3ae197d commit a6e9455

1 file changed

Lines changed: 5 additions & 12 deletions

File tree

fs/ext4/super.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2469,23 +2469,19 @@ static int parse_apply_sb_mount_options(struct super_block *sb,
24692469
struct ext4_fs_context *m_ctx)
24702470
{
24712471
struct ext4_sb_info *sbi = EXT4_SB(sb);
2472-
char *s_mount_opts = NULL;
2472+
char s_mount_opts[65];
24732473
struct ext4_fs_context *s_ctx = NULL;
24742474
struct fs_context *fc = NULL;
24752475
int ret = -ENOMEM;
24762476

24772477
if (!sbi->s_es->s_mount_opts[0])
24782478
return 0;
24792479

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);
24852481

24862482
fc = kzalloc(sizeof(struct fs_context), GFP_KERNEL);
24872483
if (!fc)
2488-
goto out_free;
2484+
return -ENOMEM;
24892485

24902486
s_ctx = kzalloc(sizeof(struct ext4_fs_context), GFP_KERNEL);
24912487
if (!s_ctx)
@@ -2517,11 +2513,8 @@ static int parse_apply_sb_mount_options(struct super_block *sb,
25172513
ret = 0;
25182514

25192515
out_free:
2520-
if (fc) {
2521-
ext4_fc_free(fc);
2522-
kfree(fc);
2523-
}
2524-
kfree(s_mount_opts);
2516+
ext4_fc_free(fc);
2517+
kfree(fc);
25252518
return ret;
25262519
}
25272520

0 commit comments

Comments
 (0)