HIGH
f2fs Compress UAF
CVE-2026-31702
CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H
KernelScan AI6.9MEDIUM
01Description
In the Linux kernel, the following vulnerability has been resolved: f2fs: fix use-after-free of sbi in f2fs_compress_write_end_io() In f2fs_compress_write_end_io(), dec_page_count(sbi, type) can bring the F2FS_WB_CP_DATA counter to zero, unblocking f2fs_wait_on_all_pages() in f2fs_put_super() on a concurrent unmount CPU. The unmount path then proceeds to call f2fs_destroy_page_array_cache(sbi), which destroys sbi->page_array_slab via kmem_cache_destroy(), and eventually kfree(sbi). Meanwhile, the bio completion callback is still executing: when it reaches page_array_free(sbi, ...), it dereferences sbi->page_array_slab — a destroyed slab cache — to call kmem_cache_free(), causing a use-after-free. This is the same class of bug as CVE-2026-23234 (which fixed the equivalent race in f2fs_write_end_io() in data.c), but in the compressed writeback completion path that was not covered by that fix. Fix this by moving dec_page_count() to after page_array_free(), so that all sbi accesses complete before the counter decrement that can unblock unmount. For non-last folios (where atomic_dec_return on cic->pending_pages is nonzero), dec_page_count is called immediately before returning — page_array_free is not reached on this path, so there is no post-decrement sbi access. For the last folio, page_array_free runs while the F2FS_WB_CP_DATA counter is still nonzero (this folio has not yet decremented it), keeping sbi alive, and dec_page_count runs as the final operation.
02KernelScan AI Analysis
Risk summary
Local users with low privileges can trigger a use-after-free vulnerability in F2FS compressed file writeback, potentially leading to kernel memory corruption and privilege escalation. The bug occurs when filesystem unmount races with compressed data writeback completion, causing access to freed superblock structures.
Vulnerability analysis
The vulnerability is a classic use-after-free race condition between F2FS filesystem unmount and compressed writeback completion. In f2fs_compress_write_end_io(), calling dec_page_count() can decrement the F2FS_WB_CP_DATA counter to zero, which unblocks f2fs_wait_on_all_pages() in the unmount path on another CPU. The unmount then proceeds to destroy sbi->page_array_slab and free the superblock (sbi), while the bio completion callback is still executing. When the callback later calls page_array_free(), it dereferences the already-freed sbi->page_array_slab, causing a use-after-free. The fix reorders operations to ensure dec_page_count() is called last, after all sbi accesses complete, preventing the race window. This requires write access to an F2FS filesystem with compression enabled, making it locally exploitable by users who can write to such filesystems.
03Fix Versions
| Branch | Fixed in | Patch commit |
|---|---|---|
| 6.1 | 6.1.175 | 57bc678f36ac |
| 6.12 | 6.12.84 | f5154cf3ce1c |
| 6.18 | 6.18.25 | c76cf339b879 |
| 6.6 | 6.6.136 | ef57cd3329b4 |
| 7.0 | 7.0.2 | 2c97dcb6147c |
| mainline | 7.1-rc1 | 39d4ee19c1e7 |