CVE-2026-139012: f2fs: compress: fix to handle race between truncate and writeback
In the Linux kernel, the following vulnerability has been resolved:
f2fs: compress: fix to handle race between truncate and writeback
fsstress reports a kernel BUG in f2fstruncatepartialcluster():
kernel BUG at fs/f2fs/compress.c:1238! RIP: 0010:f2fstruncatepartialcluster+0x292/0x2a0 Call Trace: <TASK> f2fstruncate+0xf6/0x210 f2fssetattr+0x6b7/0x770 notifychange+0x33b/0x520 dotruncate+0xc2/0xf0 vfstruncate+0x153/0x1d0 ksystruncate+0x78/0xd0 x64systruncate+0x16/0x20 dosyscall64+0xbe/0x540
The root cause is that Thread A (truncate) and Thread B (background writeback or fsync) can race as follows:
Thread A Thread B - f2fssetattr - f2fstruncate - f2fstruncateblocks - f2fstruncatepartialcluster - f2fsiscompressedcluster return 1 - f2fswritecachepages - f2fswritemultipages - f2fswriterawpages - f2fswritesingledatapage dn.datablkaddr != COMPRESSADDR (cluster converted to normal) - f2fspreparecompressoverwrite - f2fsiscompressedcluster return 0 - return 0 - f2fsbugon(sbi, err == 0): BUG!
Writeback path does not acquire igcrwsem or filemapinvalidatelock. When a compressed cluster fails compression during writeback, it is overwritten with raw data blocks. If Thread A checked f2fsiscompressedcluster() before the conversion, but calls f2fspreparecompressoverwrite() after the conversion, f2fspreparecompressoverwrite() returns 0 because the cluster is no longer a compressed cluster.
To fix this, remove the f2fsbugon() and retry checking the cluster status when f2fspreparecompressoverwrite() returns 0, so that it can fall back to f2fsdotruncateblocks() to handle it as a normal cluster.
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Compensating control
In F2FS truncate handling, remove f2fs_bug_on() and, when f2fs_prepare_compress_overwrite() returns 0, retry checking the cluster status and fall back to f2fs_do_truncate_blocks() to handle it as a normal cluster.
Event History
Frequently Asked Questions
What conditions are required to trigger this issue?
The race requires a truncate operation to overlap with background writeback or fsync on an F2FS compressed cluster. The failure can occur when compression fails during writeback and the cluster is converted to a normal cluster while truncation still treats it as compressed.
How can I tell whether this issue has occurred?
Affected systems may report a kernel BUG in f2fs_truncate_partial_cluster() at fs/f2fs/compress.c:1238. The call trace can include f2fs_truncate, f2fs_setattr, notify_change, do_truncate, and vfs_truncate.