ntfs3: fix double free of sbi->options->nls and clarify ownership of fc->fs_private
PATCH 1/1 ntfs3: fix double free of sbi->options->nls and clarify ownership of fc->fs_private
commit 02f312754c87 ("ntfs3: fix use-after-free of sbi->options in cmp_fnames") introduced a use-after-free bug due to improper handling of sbi->options in error paths. This resulted in crashes when superblock cleanup is performed in ntfs_put_super.
This patch ensures that the options structure and its subfields are properly freed, preventing the memory corruption and use-after-free errors.
--- fs/ntfs3/super.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/ntfs3/super.c +3 -2
@@ -705,7 +705,7 @@ static void ntfs_put_super(struct super_block *sb)if (sbi->options) {unload_nls (sbi->options->nls); -kfree (sbi->options->nls); +kfree (sbi->options->nls_name);kfree (sbi->options); sbi->options =NULL ; }
@@ -1246,6 +1246,7 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc) } } sbi->options = options; + fc->fs_private =NULL ; sb->s_flags |=SB_NODIRATIME ; sb->s_magic =0x7366746e ;// "ntfs" sb->s_op = &ntfs_sops;
@@ -1671,7 +1672,7 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc) out:if (sbi && sbi->options) {unload_nls (sbi->options->nls); -kfree (sbi->options->nls); +kfree (sbi->options->nls_name);kfree (sbi->options); sbi->options =NULL ; }
Signature · 1 line
2.43.0
Quoted 35 lines · YangWen
commit
02f312754c87("ntfs3: fix use-after-free ofsbi->optionsincmp_fnames") introduced a use-after-free bug due to improper handling ofsbi->optionsin error paths. This resulted in crashes when superblock cleanup is performed inntfs_put_super.This patch ensures that the options structure and its subfields are properly freed, preventing the memory corruption and use-after-free errors.
Reported-by [email protected]Signed-off-by YangWen <[email protected]>--- fs/ntfs3/super.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)fs/ntfs3/super.c +2
-1@@ -705,7 +705,7 @@ static void ntfs_put_super(struct super_block *sb)if (sbi->options) {unload_nls (sbi->options->nls); -kfree (sbi->options->nls); +kfree (sbi->options->nls_name);kfree (sbi->options); sbi->options =NULL ; }@@ -1246,6 +1246,7 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc) } } sbi->options = options; + fc->fs_private =NULL ; sb->s_flags |=SB_NODIRATIME ; sb->s_magic =0x7366746e ;// "ntfs" sb->s_op = &ntfs_sops;
fs/ntfs3/super.c static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc) · line 1678
Quoted 8 lines
fs/ntfs3/super.c +1
-1@@ -1671,7 +1672,7 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc) out:if (sbi && sbi->options) {unload_nls (sbi->options->nls); -kfree (sbi->options->nls); +kfree (sbi->options->nls_name);kfree (sbi->options); sbi->options =NULL ; }
Applied to my tree with added "Fixes:" and "Closes:" tags, thanks for the patch.
Regards,
Konstantin