CVE-2025-39879
Severity CVSS v4.0:
Pending analysis
Type:
Unavailable / Other
Publication date:
23/09/2025
Last modified:
23/09/2025
Description
In the Linux kernel, the following vulnerability has been resolved:<br />
<br />
ceph: always call ceph_shift_unused_folios_left()<br />
<br />
The function ceph_process_folio_batch() sets folio_batch entries to<br />
NULL, which is an illegal state. Before folio_batch_release() crashes<br />
due to this API violation, the function ceph_shift_unused_folios_left()<br />
is supposed to remove those NULLs from the array.<br />
<br />
However, since commit ce80b76dd327 ("ceph: introduce<br />
ceph_process_folio_batch() method"), this shifting doesn&#39;t happen<br />
anymore because the "for" loop got moved to ceph_process_folio_batch(),<br />
and now the `i` variable that remains in ceph_writepages_start()<br />
doesn&#39;t get incremented anymore, making the shifting effectively<br />
unreachable much of the time.<br />
<br />
Later, commit 1551ec61dc55 ("ceph: introduce ceph_submit_write()<br />
method") added more preconditions for doing the shift, replacing the<br />
`i` check (with something that is still just as broken):<br />
<br />
- if ceph_process_folio_batch() fails, shifting never happens<br />
<br />
- if ceph_move_dirty_page_in_page_array() was never called (because<br />
ceph_process_folio_batch() has returned early for some of various<br />
reasons), shifting never happens<br />
<br />
- if `processed_in_fbatch` is zero (because ceph_process_folio_batch()<br />
has returned early for some of the reasons mentioned above or<br />
because ceph_move_dirty_page_in_page_array() has failed), shifting<br />
never happens<br />
<br />
Since those two commits, any problem in ceph_process_folio_batch()<br />
could crash the kernel, e.g. this way:<br />
<br />
BUG: kernel NULL pointer dereference, address: 0000000000000034<br />
#PF: supervisor write access in kernel mode<br />
#PF: error_code(0x0002) - not-present page<br />
PGD 0 P4D 0<br />
Oops: Oops: 0002 [#1] SMP NOPTI<br />
CPU: 172 UID: 0 PID: 2342707 Comm: kworker/u778:8 Not tainted 6.15.10-cm4all1-es #714 NONE<br />
Hardware name: Dell Inc. PowerEdge R7615/0G9DHV, BIOS 1.6.10 12/08/2023<br />
Workqueue: writeback wb_workfn (flush-ceph-1)<br />
RIP: 0010:folios_put_refs+0x85/0x140<br />
Code: 83 c5 01 39 e8 7e 76 48 63 c5 49 8b 5c c4 08 b8 01 00 00 00 4d 85 ed 74 05 41 8b 44 ad 00 48 8b 15 b0 ><br />
RSP: 0018:ffffb880af8db778 EFLAGS: 00010207<br />
RAX: 0000000000000001 RBX: 0000000000000000 RCX: 0000000000000003<br />
RDX: ffffe377cc3b0000 RSI: 0000000000000000 RDI: ffffb880af8db8c0<br />
RBP: 0000000000000000 R08: 000000000000007d R09: 000000000102b86f<br />
R10: 0000000000000001 R11: 00000000000000ac R12: ffffb880af8db8c0<br />
R13: 0000000000000000 R14: 0000000000000000 R15: ffff9bd262c97000<br />
FS: 0000000000000000(0000) GS:ffff9c8efc303000(0000) knlGS:0000000000000000<br />
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033<br />
CR2: 0000000000000034 CR3: 0000000160958004 CR4: 0000000000770ef0<br />
PKRU: 55555554<br />
Call Trace:<br />
<br />
ceph_writepages_start+0xeb9/0x1410<br />
<br />
The crash can be reproduced easily by changing the<br />
ceph_check_page_before_write() return value to `-E2BIG`.<br />
<br />
(Interestingly, the crash happens only if `huge_zero_folio` has<br />
already been allocated; without `huge_zero_folio`,<br />
is_huge_zero_folio(NULL) returns true and folios_put_refs() skips NULL<br />
entries instead of dereferencing them. That makes reproducing the bug<br />
somewhat unreliable. See<br />
https://lore.kernel.org/20250826231626.218675-1-max.kellermann@ionos.com<br />
for a discussion of this detail.)<br />
<br />
My suggestion is to move the ceph_shift_unused_folios_left() to right<br />
after ceph_process_folio_batch() to ensure it always gets called to<br />
fix up the illegal folio_batch state.