In the Linux kernel, the following vulnerability has been resolved:
btrfs: fix double accounting race when btrfsrundelalloc_range() failed
[BUG] When running btrfs with block size (4K) smaller than page size (64K, aarch64), there is a very high chance to crash the kernel at generic/750, with the following messages: (before the call traces, there are 3 extra debug messages added)
BTRFS warning (device dm-3): read-write for sector size 4096 with page size 65536 is experimental BTRFS info (device dm-3): checking UUID tree hrtimer: interrupt took 5451385 ns BTRFS error (device dm-3): cowfilerange failed, root=4957 inode=257 start=1605632 len=69632: -28 BTRFS error (device dm-3): rundelallocnocow failed, root=4957 inode=257 start=1605632 len=69632: -28 BTRFS error (device dm-3): failed to run delalloc range, root=4957 ino=257 folio=1572864 submitbitmap=8-15 start=1605632 len=69632: -28 ------------[ cut here ]------------ WARNING: CPU: 2 PID: 3020984 at ordered-data.c:360 canfinishorderedextent+0x370/0x3b8 [btrfs] CPU: 2 UID: 0 PID: 3020984 Comm: kworker/u24:1 Tainted: G OE 6.13.0-rc1-custom+ #89 Tainted: [O]=OOTMODULE, [E]=UNSIGNEDMODULE Hardware name: QEMU KVM Virtual Machine, BIOS unknown 2/2/2022 Workqueue: eventsunbound btrfsasyncreclaimdataspace [btrfs] pc : canfinishorderedextent+0x370/0x3b8 [btrfs] lr : canfinishorderedextent+0x1ec/0x3b8 [btrfs] Call trace: canfinishorderedextent+0x370/0x3b8 [btrfs] (P) canfinishorderedextent+0x1ec/0x3b8 [btrfs] (L) btrfsmarkorderediofinished+0x130/0x2b8 [btrfs] extentwritepage+0x10c/0x3b8 [btrfs] extentwritecachepages+0x21c/0x4e8 [btrfs] btrfswritepages+0x94/0x160 [btrfs] dowritepages+0x74/0x190 filemapfdatawritewbc+0x74/0xa0 startdelallocinodes+0x17c/0x3b0 [btrfs] btrfsstartdelallocroots+0x17c/0x288 [btrfs] shrinkdelalloc+0x11c/0x280 [btrfs] flushspace+0x288/0x328 [btrfs] btrfsasyncreclaimdataspace+0x180/0x228 [btrfs] processonework+0x228/0x680 workerthread+0x1bc/0x360 kthread+0x100/0x118 retfromfork+0x10/0x20 ---[ end trace 0000000000000000 ]--- BTRFS critical (device dm-3): bad ordered extent accounting, root=4957 ino=257 OE offset=1605632 OE len=16384 todec=16384 left=0 BTRFS critical (device dm-3): bad ordered extent accounting, root=4957 ino=257 OE offset=1622016 OE len=12288 todec=12288 left=0 Unable to handle kernel NULL pointer dereference at virtual address 0000000000000008 BTRFS critical (device dm-3): bad ordered extent accounting, root=4957 ino=257 OE offset=1634304 OE len=8192 todec=4096 left=0 CPU: 1 UID: 0 PID: 3286940 Comm: kworker/u24:3 Tainted: G W OE 6.13.0-rc1-custom+ #89 Hardware name: QEMU KVM Virtual Machine, BIOS unknown 2/2/2022 Workqueue: btrfsworkhelper [btrfs] (btrfs-endio-write) pstate: 404000c5 (nZcv daIF +PAN -UAO -TCO -DIT -SSBS BTYPE=--) pc : processonework+0x110/0x680 lr : workerthread+0x1bc/0x360 Call trace: processonework+0x110/0x680 (P) workerthread+0x1bc/0x360 (L) workerthread+0x1bc/0x360 kthread+0x100/0x118 retfromfork+0x10/0x20 Code: f84086a1 f9000fe1 53041c21 b9003361 (f9400661) ---[ end trace 0000000000000000 ]--- Kernel panic - not syncing: Oops: Fatal exception SMP: stopping secondary CPUs SMP: failed to stop secondary CPUs 2-3 Dumping ftrace buffer: (ftrace buffer empty) Kernel Offset: 0x275bb9540000 from 0xffff800080000000 PHYSOFFSET: 0xffff8fbba0000000 CPU features: 0x100,00000070,00801250,8201720b
[CAUSE] The above warning is triggered immediately after the delalloc range failure, this happens in the following sequence:
Range [1568K, 1636K) is dirty
1536K 1568K 1600K 1636K 1664K | |/////////|////////| |
Where 1536K, 1600K and 1664K are page boundaries (64K page size)
Enter extent_writepage() for page 1536K
Enter rundelallocnocow() with locke ---truncated---