[Devel] [PATCH hci-8.2 1/8] ms/ext4: avoid potential buffer over-read in parse_apply_sb_mount_options()
Denis V. Lunev
den at openvz.org
Thu Nov 19 15:03:18 MSK 2026
From: Theodore Ts'o <tytso at mit.edu>
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 at vger.kernel.org
Fixes: 8b67f04ab9de ("ext4: Add mount options in superblock")
Reviewed-by: Jan Kara <jack at suse.cz>
Reviewed-by: Darrick J. Wong <djwong at kernel.org>
Signed-off-by: Theodore Ts'o <tytso at mit.edu>
Message-ID: <20250916-tune2fs-v2-1-d594dc7486f0 at mit.edu>
Signed-off-by: Theodore Ts'o <tytso at mit.edu>
(cherry picked from commit 8ecb790ea8c3fc69e77bace57f14cf0d7c177bd8)
https://virtuozzo.atlassian.net/browse/VSTOR-155988
Feature: fix ms/ext4
Signed-off-by: Denis V. Lunev <den at openvz.org>
---
fs/ext4/super.c | 17 +++++------------
1 file changed, 5 insertions(+), 12 deletions(-)
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index e450ea1df71d..b10bfec7499b 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -2494,7 +2494,7 @@ static int parse_apply_sb_mount_options(struct super_block *sb,
struct ext4_fs_context *m_ctx)
{
struct ext4_sb_info *sbi = EXT4_SB(sb);
- char *s_mount_opts = NULL;
+ char s_mount_opts[65];
struct ext4_fs_context *s_ctx = NULL;
struct fs_context *fc = NULL;
int ret = -ENOMEM;
@@ -2502,15 +2502,11 @@ static int parse_apply_sb_mount_options(struct super_block *sb,
if (!sbi->s_es->s_mount_opts[0])
return 0;
- s_mount_opts = kstrndup(sbi->s_es->s_mount_opts,
- sizeof(sbi->s_es->s_mount_opts),
- GFP_KERNEL);
- if (!s_mount_opts)
- return ret;
+ strscpy_pad(s_mount_opts, sbi->s_es->s_mount_opts);
fc = kzalloc(sizeof(struct fs_context), GFP_KERNEL);
if (!fc)
- goto out_free;
+ return -ENOMEM;
s_ctx = kzalloc(sizeof(struct ext4_fs_context), GFP_KERNEL);
if (!s_ctx)
@@ -2542,11 +2538,8 @@ static int parse_apply_sb_mount_options(struct super_block *sb,
ret = 0;
out_free:
- if (fc) {
- ext4_fc_free(fc);
- kfree(fc);
- }
- kfree(s_mount_opts);
+ ext4_fc_free(fc);
+ kfree(fc);
return ret;
}
--
2.55.0
More information about the Devel
mailing list