CVE-2024-50118 Information
Description
In the Linux kernel the following vulnerability has been resolved:
btrfs: reject ro->rw reconfiguration if there are hard ro requirements
[BUG] Syzbot reports the following crash:
BTRFS info (device loop0 state MCS): disabling free space tree
BTRFS info (device loop0 state MCS): clearing compat-ro feature flag for FREE_SPACE_TREE (0x1)
BTRFS info (device loop0 state MCS): clearing compat-ro feature flag for FREE_SPACE_TREE_VALID (0x2)
Oops: general protection fault probably for non-canonical address 0xdffffc0000000003: 0000 [1] PREEMPT SMP KASAN NOPTI
KASAN: null-ptr-deref in range [0x0000000000000018-0x000000000000001f]
Hardware name: QEMU Standard PC (Q35 + ICH9 2009) BIOS 1.16.3-debian-1.16.3-2~bpo12+1 04/01/2014
RIP: 0010:backup_super_roots fs/btrfs/disk-io.c:1691 [inline]
RIP: 0010:write_all_supers+0x97a/0x40f0 fs/btrfs/disk-io.c:4041
Call Trace:
[CAUSE] To support mounting different subvolume with different RO/RW flags for the new mount APIs btrfs introduced two workaround to support this feature:
-
Skip mount option/feature checks if we are mounting a different subvolume
-
Reconfigure the fs to RW if the initial mount is RO
Combining these two we can have the following sequence:
-
Mount the fs rorescue=allclear_cachespace_cache=v1 rescue=all will mark the fs as hard read-only so no v2 cache clearing will happen.
-
Mount a subvolume rw of the same fs. We go into btrfs_get_tree_subvol() but fc_mount() returns EBUSY because our new fc is RW different from the original fs.
Now we enter btrfs_reconfigure_for_mount() which switches the RO flag first so that we can grab the existing fs_info. Then we reconfigure the fs to RW.
-
During reconfiguration option/features check is skipped This means we will restart the v2 cache clearing and convert back to v1 cache. This will trigger fs writes and since the original fs has escue=all\n option it skips the csum tree read.
And eventually causing NULL pointer dereference in super block writeback.
[FIX] For reconfiguration caused by different subvolume RO/RW flags ensure we always run btrfs_check_options() to ensure we have proper hard RO requirements met.
In fact the function btrfs_check_options() doesn’t really do many complex checks but hard RO requirement and some feature dependency checks thus there is no special reason not to do the check for mount reconfiguration.
Reference
https://git.kernel.org/stable/c/23724398b55d9570f6ae79dd2ea026fff8896bf1 https://git.kernel.org/stable/c/3c36a72c1d27de6618c1c480c793d9924640f5bb
Share on: