CVE-2025-21712: md/md-bitmap: Synchronize bitmap_get_stats() with bitmap lifetime
Description
===========
In the Linux kernel, the following vulnerability has been resolved:
md/md-bitmap: Synchronize bitmap_get_stats() with bitmap lifetime
After commit ec6bb299c7c3 ("md/md-bitmap: add 'sync_size' into struct md_bitmap_stats"), following panic is reported:
Oops: general protection fault, probably for non-canonical address RIP: 0010:bitmap_get_stats+0x2b/0xa0 Call Trace: <TASK> md_seq_show+0x2d2/0x5b0 seq_read_iter+0x2b9/0x470 seq_read+0x12f/0x180 proc_reg_read+0x57/0xb0 vfs_read+0xf6/0x380 ksys_read+0x6c/0xf0 do_syscall_64+0x82/0x170 entry_SYSCALL_64_after_hwframe+0x76/0x7e
Root cause is that bitmap_get_stats() can be called at anytime if mddev is still there, even if bitmap is destroyed, or not fully initialized. Deferenceing bitmap in this case can crash the kernel. Meanwhile, the above commit start to deferencing bitmap->storage, make the problem easier to trigger.
Fix the problem by protecting bitmap_get_stats() with bitmap_info.mutex.
The Linux kernel CVE team has assigned CVE-2025-21712 to this issue.
Affected and fixed versions
===========================
Issue introduced in 2.6.13 with commit 32a7627cf3a35396a8e834faf34e38ae9f3b1309 and fixed in 6.12.13 with commit 237e19519c8ff6949f0ef57c4a0243f5b2b0fa18 Issue introduced in 2.6.13 with commit 32a7627cf3a35396a8e834faf34e38ae9f3b1309 and fixed in 6.13.2 with commit 4e9316eee3885bfb311b4759513f2ccf37891c09 Issue introduced in 2.6.13 with commit 32a7627cf3a35396a8e834faf34e38ae9f3b1309 and fixed in 6.14-rc1 with commit 8d28d0ddb986f56920ac97ae704cc3340a699a30
Please see https://www.kernel.org for a full list of currently supported kernel versions by the kernel community.
Unaffected versions might change over time as fixes are backported to older supported kernel versions. The official CVE entry at
https://cve.org/CVERecord/?id=CVE-2025-21712
will be updated if fixes are backported, please check that for the most up to date information about this issue.
Affected files
==============
The file(s) affected by this issue are:
drivers/md/md-bitmap.c
drivers/md/md.c
Mitigation
==========
The Linux kernel CVE team recommends that you update to the latest stable kernel version for this, and many other bugfixes. Individual changes are never tested alone, but rather are part of a larger kernel release. Cherry-picking individual commits is not recommended or supported by the Linux kernel community at all. If however, updating to the latest release is impossible, the individual changes to resolve this issue can be found at these commits:
https://git.kernel.org/stable/c/237e19519c8ff6949f0ef57c4a0243f5b2b0fa18 https://git.kernel.org/stable/c/4e9316eee3885bfb311b4759513f2ccf37891c09 https://git.kernel.org/stable/c/8d28d0ddb986f56920ac97ae704cc3340a699a30