squashfs: fix null-ptr-deref in squashfs_fill_super
Subsystems (2)
PATCH 1/1 squashfs: fix null-ptr-deref in squashfs_fill_super
When squashfs_read_table() returns an error or sb->s_magic != SQUASHFS_MAGIC, enters the error branch and calls msblk->thread_ops->destroy(msblk) to destroy msblk. However, msblk->thread_ops has not been initialized. Therefore, the following problem is triggered:
==================================================================
BUG: KASAN: null-ptr-deref in squashfs_fill_super+0xe7a/0x13b0 Read of size 8 at addr 0000000000000008 by task swapper/0/1 CPU: 0 PID: 1 Comm: swapper/0 Not tainted 6.1.0-rc3-next-20221031 #367 Call Trace: <TASK> dump_stack_lvl+0x73/0x9f print_report+0x743/0x759 kasan_report+0xc0/0x120 __asan_load8+0xd3/0x140 squashfs_fill_super+0xe7a/0x13b0 get_tree_bdev+0x27b/0x450 squashfs_get_tree+0x19/0x30 vfs_get_tree+0x49/0x150 path_mount+0xaae/0x1350 init_mount+0xad/0x100 do_mount_root+0xbc/0x1d0 mount_block_root+0x173/0x316 mount_root+0x223/0x236 prepare_namespace+0x1eb/0x237 kernel_init_freeable+0x528/0x576 kernel_init+0x29/0x250 ret_from_fork+0x1f/0x30 </TASK> ==================================================================
To solve this issue, msblk->thread_ops is initialized immediately after msblk is assigned a value.
--- fs/squashfs/super.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/squashfs/super.c +2 -1
@@ -197,6 +197,7 @@ static int squashfs_fill_super(struct super_block *sb, struct fs_context *fc)return -ENOMEM ; } msblk = sb->s_fs_info; + msblk->thread_ops = opts->thread_ops; msblk->panic_on_errors = (opts->errors == Opt_errors_panic);
@@ -231,7 +232,7 @@ static int squashfs_fill_super(struct super_block *sb, struct fs_context *fc) sb->s_bdev); goto failed_mount; } - msblk->thread_ops = opts->thread_ops; +if (opts->thread_num ==0 ) { msblk->max_thread_num = msblk->thread_ops->max_decompressors (); }else {
Signature · 1 line
2.31.1
Quoted 33 lines · Baokun Li
When
squashfs_read_table()returns an error orsb->s_magic != SQUASHFS_MAGIC, enters the error branch and callsmsblk->thread_ops->destroy(msblk)to destroy msblk. However,msblk->thread_opshas not been initialized. Therefore, the following problem is triggered:==================================================================
BUG: KASAN: null-ptr-deref in squashfs_fill_super+0xe7a/0x13b0 Read of size 8 at addr 0000000000000008 by task swapper/0/1 CPU: 0 PID: 1 Comm: swapper/0 Not tainted 6.1.0-rc3-next-20221031 #367 Call Trace: <TASK> dump_stack_lvl+0x73/0x9f print_report+0x743/0x759 kasan_report+0xc0/0x120 __asan_load8+0xd3/0x140 squashfs_fill_super+0xe7a/0x13b0 get_tree_bdev+0x27b/0x450 squashfs_get_tree+0x19/0x30 vfs_get_tree+0x49/0x150 path_mount+0xaae/0x1350 init_mount+0xad/0x100 do_mount_root+0xbc/0x1d0 mount_block_root+0x173/0x316 mount_root+0x223/0x236 prepare_namespace+0x1eb/0x237 kernel_init_freeable+0x528/0x576 kernel_init+0x29/0x250 ret_from_fork+0x1f/0x30 </TASK> ==================================================================
Quoted 6 lines
To solve this issue,
msblk->thread_opsis initialized immediately after msblk is assigned a value.Fixes b0645770d3c7 ("squashfs: add the mount parameter theads=<single|multi|percpu>")Signed-off-by Baokun Li <[email protected]>---
Thank you for helping to identify and fix this bug.
Quoted 25 lines
fs/squashfs/super.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)fs/squashfs/super.c +2
-1@@ -197,6 +197,7 @@ static int squashfs_fill_super(struct super_block *sb, struct fs_context *fc)return -ENOMEM ; } msblk = sb->s_fs_info; + msblk->thread_ops = opts->thread_ops; msblk->panic_on_errors = (opts->errors == Opt_errors_panic);@@ -231,7 +232,7 @@ static int squashfs_fill_super(struct super_block *sb, struct fs_context *fc) sb->s_bdev); goto failed_mount; } - msblk->thread_ops = opts->thread_ops; +if (opts->thread_num ==0 ) { msblk->max_thread_num = msblk->thread_ops->max_decompressors (); }else {
Quoted 33 lines · Baokun Li
When
squashfs_read_table()returns an error orsb->s_magic != SQUASHFS_MAGIC, enters the error branch and callsmsblk->thread_ops->destroy(msblk)to destroy msblk. However,msblk->thread_opshas not been initialized. Therefore, the following problem is triggered:==================================================================
BUG: KASAN: null-ptr-deref in squashfs_fill_super+0xe7a/0x13b0 Read of size 8 at addr 0000000000000008 by task swapper/0/1 CPU: 0 PID: 1 Comm: swapper/0 Not tainted 6.1.0-rc3-next-20221031 #367 Call Trace: <TASK> dump_stack_lvl+0x73/0x9f print_report+0x743/0x759 kasan_report+0xc0/0x120 __asan_load8+0xd3/0x140 squashfs_fill_super+0xe7a/0x13b0 get_tree_bdev+0x27b/0x450 squashfs_get_tree+0x19/0x30 vfs_get_tree+0x49/0x150 path_mount+0xaae/0x1350 init_mount+0xad/0x100 do_mount_root+0xbc/0x1d0 mount_block_root+0x173/0x316 mount_root+0x223/0x236 prepare_namespace+0x1eb/0x237 kernel_init_freeable+0x528/0x576 kernel_init+0x29/0x250 ret_from_fork+0x1f/0x30 </TASK> ==================================================================
Quoted 5 lines
To solve this issue,
msblk->thread_opsis initialized immediately after msblk is assigned a value.Fixes b0645770d3c7 ("squashfs: add the mount parameter theads=<single|multi|percpu>")Signed-off-by Baokun Li <[email protected]>
Quoted 25 lines
--
fs/squashfs/super.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)fs/squashfs/super.c +2
-1@@ -197,6 +197,7 @@ static int squashfs_fill_super(struct super_block *sb, struct fs_context *fc)return -ENOMEM ; } msblk = sb->s_fs_info; + msblk->thread_ops = opts->thread_ops; msblk->panic_on_errors = (opts->errors == Opt_errors_panic);@@ -231,7 +232,7 @@ static int squashfs_fill_super(struct super_block *sb, struct fs_context *fc) sb->s_bdev); goto failed_mount; } - msblk->thread_ops = opts->thread_ops; +if (opts->thread_num ==0 ) { msblk->max_thread_num = msblk->thread_ops->max_decompressors (); }else {