CVE-2026-138875: jbd2: don't advance j_fc_off before the buffer is recorded
In the Linux kernel, the following vulnerability has been resolved:
jbd2: don't advance jfcoff before the buffer is recorded
jbd2fcgetbuf() increments journal->jfcoff before jbd2journalbmap() and getblk() have had a chance to fail. When either does, the slot jfcwbuf[fcoff] is never assigned, but jfcoff already counts it.
ext4 then fails the fast commit and falls back, and the fallback path reaches jbd2fcreleasebufs() via ext4fccommit -> jbd2fcendcommitfallback -> jbd2fcendcommit -> ext4fccleanup. That walks down from jfcoff - 1 and putbh()es every slot until it sees NULL, so it also touches the slot that was never written. jfcwbuf comes from a plain kmalloc() and is never zeroed, so a slot used for the first time holds uninitialised heap data.
Advance jfcoff only after the buffer head has been stored. That restores the invariant that jfcoff covers exactly the filled slots, which is what jbd2fcreleasebufs() relies on: the live buffers of the current fast commit sit above the NULLs the previous one released, so stopping at the first NULL is correct.
Reproduced on a KASAN kernel with an ext4 fastcommit filesystem on a loop device, truncating the backing file under the live mount so that only the journal's fast-commit region falls past the end of the device. getblk() then fails for the first fast-commit block while the rest of the journal is still addressable, so the journal is not aborted and the fast commit reaches the fallback path. jfcwbuf was poisoned to make the read of the never-written slot visible:
BUG: KASAN: wild-memory-access in jbd2fcreleasebufs+0x6b/0xd0 Write of size 4 at addr 5a5a5a5a5a5a5ab2 by task sync/961 jbd2fcreleasebufs+0x6b/0xd0 ext4fccleanup+0x97/0x830 jbd2fcendcommit+0x37/0xc0 ext4fccommit+0x524/0x560 ext4syncfile+0x3c4/0x4b0 x64sysfsync+0x20/0x30
With this patch the same run leaves jfcoff at 0 across repeated getblk() failures and completes cleanly.