CVE-2026-64593: btrfs: do not trim a device which is not writeable
In the Linux kernel, the following vulnerability has been resolved:
btrfs: do not trim a device which is not writeable
[BUG] There is a bug report that btrfs/242 can randomly fail with the following NULL pointer dereference:
run fstests btrfs/242 at 2026-06-01 10:25:08 BTRFS: device fsid d4d7f234-487c-4787-88e4-47a8b68c9874 devid 1 transid 9 /dev/sdc (8:32) scanned by mount (122609) BTRFS info (device sdc): first mount of filesystem d4d7f234-487c-4787-88e4-47a8b68c9874 BTRFS info (device sdc): using crc32c checksum algorithm BTRFS warning (device sdc): devid 2 uuid fbe72d72-3272-482d-80fb-ab88ed398192 is missing BTRFS warning (device sdc): devid 2 uuid fbe72d72-3272-482d-80fb-ab88ed398192 is missing BTRFS info (device sdc): allowing degraded mounts BTRFS info (device sdc): turning on async discard BTRFS info (device sdc): enabling free space tree Unable to handle kernel NULL pointer dereference at virtual address 0000000000000018 user pgtable: 4k pages, 48-bit VAs, pgdp=000000013fd6b000 CPU: 4 UID: 0 PID: 122625 Comm: fstrim Not tainted 7.0.10-2-default #1 PREEMPT(full) openSUSE Tumbleweed e9a5f6b24978fba3bf015a992f865837fdfff3dd Hardware name: QEMU KVM Virtual Machine, BIOS edk2-20250812-19.fc42 08/12/2025 pstate: 01400005 (nzcv daif +PAN -UAO -TCO +DIT -SSBS BTYPE=--) pc : btrfstrimfs+0x34c/0xa00 [btrfs] lr : btrfstrimfs+0x1f0/0xa00 [btrfs] Call trace: btrfstrimfs+0x34c/0xa00 [btrfs f02c1d570ceea621c69d302ba75dd61868083840] (P) btrfsioctlfitrim+0xe8/0x178 [btrfs f02c1d570ceea621c69d302ba75dd61868083840] btrfsioctl+0xdd4/0x2bd8 [btrfs f02c1d570ceea621c69d302ba75dd61868083840] arm64sysioctl+0xac/0x108 invokesyscall.constprop.0+0x5c/0xd0 el0svccommon.constprop.0+0x40/0xf0 doel0svc+0x24/0x40 el0svc+0x40/0x1d0 el0t64synchandler+0xa0/0xe8 el0t64sync+0x1b0/0x1b8 Code: 17ffff83 f94017e0 f9002be0 f9402ea0 (f9400c00) ---[ end trace 0000000000000000 ]---
Also the reporter is very kind to test the following ASSERT() added to btrfstrimfreeextentsthrottle():
ASSERT(device->bdev, "devid=%llu path=%s devstate=0x%lx\n", device->devid, btrfsdevname(device), device->devstate);
And it shows the following output:
assertion failed: device->bdev, in extent-tree.c:6630 (devid=2 path=/dev/sdd devstate=0x82)
Which means the device->bdev is NULL, and the devstate is BTRFSDEVSTATEINFSMETADATA | BTRFSDEVSTATEITEMFOUND, without BTRFSDEVSTATEWRITEABLE flag set.
[CAUSE] The pc points to the following call chain:
btrfstrimfs() |- btrfstrimfreeextents() |- btrfstrimfreeextentsthrottle() |- bdevmaxdiscardsectors(device->bdev)
So the NULL pointer dereference is caused by device->bdev being NULL.
This looks impossible by a quick glance, as just before calling btrfstrimfreeextentsthrottle(), we have skipped any device that has BTRFSDEVSTATEMISSING flag set.
However in this particular case, there is a window where the missing device is later re-scanned, causing btrfs to remove the BTRFSDEVSTATEMISSING flag:
btrfscontrolioctl() |- btrfsscanonedevice() |- devicelistadd() |- rcuassignpointer(device->name, name); | This updates the missing device's path to the new good path. | |- clearbit(BTRFSDEVSTATEMISSING, &device->devstate) This removes the BTRFSDEVSTATEMISSING flag.
This allows the missing device to re-appear and clear the BTRFSDEVSTATEMISSING flag. However the device still does not have the BTRFSDEVSTATEWRITEABLE flag set, nor is its bdev pointer updated.
The bdev pointer remains NULL, triggering the crash later.
[FIX] This is a big de-synchronization between BTRFSDEVSTATEMISSING and device->bdev pointer, and shows a gap in btrfs's re-appearing-device handling.
The proper handling of re-appearing device will need quite some extra work, which is out of the context of this small ---truncated---
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
linux kernel btrfsto a version that resolves this vulnerability.Fixed in 7.0.10-2-defaultPatch btrfs: do not trim a device which is not writeable
Event History
Frequently Asked Questions
What is the severity of CVE-2026-64593?
CVE-2026-64593 has been rated with a risk score of 22, indicating a significant severity level.
How do I fix CVE-2026-64593?
To mitigate CVE-2026-64593, update your Linux kernel to the latest patched version where this vulnerability has been resolved.
What systems are affected by CVE-2026-64593?
CVE-2026-64593 affects systems running the vulnerable versions of the Linux kernel using the btrfs filesystem.
What is the main problem caused by CVE-2026-64593?
The main issue with CVE-2026-64593 is a NULL pointer dereference that can occur when attempting to trim a non-writable btrfs device.
Is there a workaround for CVE-2026-64593 until a fix is applied?
As an immediate workaround for CVE-2026-64593, avoid performing trimming operations on devices that are not confirmed to be writable.