udf_sb_free_partitions() frees and NULLs sbi->s_partmaps but leaves sbi->s_partitions at its old count. udf_fill_super() retries udf_load_vrs() at several block sizes without resetting the partition state, so a crafted image can allocate the maps in one pass and fail, then in a later pass make udf_load_sequence() free them before parsing a reserve sequence that carries no Logical Volume Descriptor. The mount then continues with s_partmaps == NULL and a non-zero s_partitions, the "No partition found (2)" check passes, and the next statement dereferences the NULL array (udf_load_partdesc() walks the same pair): Oops: general protection fault, probably for non-canonical address ... KASAN: null-ptr-deref in range [0x0000000000000050-0x0000000000000057] RIP: 0010:udf_fill_super (fs/udf/super.c:2383) Call Trace: get_tree_bdev_flags (fs/super.c:1821) vfs_get_tree (fs/super.c:1881) fc_mount (fs/namespace.c:1282) path_mount (fs/namespace.c:3910 fs/namespace.c:3986 fs/namespace.c:4337) __x64_sys_mount (fs/namespace.c:4350 fs/namespace.c:4563 ...) do_syscall_64 (arch/x86/entry/syscall_64.c:61 ...) entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121) Kernel panic - not syncing: Fatal exception Reset s_partitions together with s_partmaps so the array and its count are always released as a pair. Cc: stable@vger.kernel.org Fixes: bff943af6fe3 ("udf: Fix memory leak when mounting") Reported-by: co+1911453fabc95dcf@bugs.sh Signed-off-by: Xiang Mei --- fs/udf/super.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/udf/super.c b/fs/udf/super.c index a81a8509524a..670b665880d6 100644 --- a/fs/udf/super.c +++ b/fs/udf/super.c @@ -380,6 +380,7 @@ static void udf_sb_free_partitions(struct super_block *sb) udf_free_partition(&sbi->s_partmaps[i]); kfree(sbi->s_partmaps); sbi->s_partmaps = NULL; + sbi->s_partitions = 0; } static int udf_show_options(struct seq_file *seq, struct dentry *root) -- 2.43.0