ext4: return an error when a journal block is not mapped
PATCH v2 1/1 ext4: return an error when a journal block is not mapped
If the internal journal inode contains a hole, ext4_map_blocks() returns
0. ext4_journal_bmap() logs "journal bmap failed" and aborts the journal, but also returns 0 and leaves *block unchanged.
jbd2_journal_bmap() takes that as success and uses the unchanged logical journal block number as a physical filesystem block number. Journal I/O can then overwrite filesystem blocks outside the journal despite the abort.
Return -EFSCORRUPTED for a hole, matching the error passed to jbd2_journal_abort(). Keep propagating negative mapping errors.
---
Changes in v2:
- Assign -EFSCORRUPTED to ret before aborting and returning (Markus, Jan).
- Add Reviewed-by tags from Jan Kara and Zhang Yi.
- Rebase onto v7.3-rc7.
v1: https://lore.kernel.org/r/[email protected]/
Found with an experimental clang that warns when a function returns 0 right after reporting a failure.
Recorded QEMU A/B testing used x86_64 kernels and a 1 KiB-block image with a hole in the journal inode starting at logical block 40. The unpatched kernel overwrote filesystem block 40, a reserved GDT block. With the patch, none of the marker blocks changed. There were three runs per kernel.
Both kernels logged the mapping failure and journal abort:
EXT4-fs (vda): journal bmap failed: block 40 ret 0 Aborting journal on device vda-8.
fs/ext4/super.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/ext4/super.c +3 -1
@@ -5967,7 +5967,9 @@ static int ext4_journal_bmap(journal_t *journal, sector_t *block)ext4_msg (journal->j_inode->i_sb,KERN_CRIT ,"journal bmap failed: block %llu ret %d\n" , *block, ret); -jbd2_journal_abort (journal, ret ? ret : -EFSCORRUPTED ); +if (!ret) + ret = -EFSCORRUPTED ; +jbd2_journal_abort (journal, ret);return ret; } *block = map.m_pblk;
base-commit: 24a19b953e2a3d0ea5a8c4951a0ab8f32720c907
Signature · 1 line
2.39.5 (Apple Git-154)
[email protected]
AI reviewSashiko has reviewed this patch and found no issues. It looks great!
Quoted 9 lines
If the internal journal inode contains a hole,
ext4_map_blocks()returns
0.ext4_journal_bmap()logs "journal bmap failed" and aborts the journal, but also returns 0 and leaves *block unchanged.
jbd2_journal_bmap()takes that as success and uses the unchanged logical journal block number as a physical filesystem block number. Journal I/O can then overwrite filesystem blocks outside the journal despite the abort.
Quoted 7 lines
Return
-EFSCORRUPTEDfor a hole, matching the error passed tojbd2_journal_abort(). Keep propagating negative mapping errors.Fixes 62913ae96de7 ("ext4, jbd2: add an optimized bmap for the journal inode")Assisted-by LLMSigned-off-by Karl Mehltretter <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 9 lines · Karl Mehltretter
If the internal journal inode contains a hole,
ext4_map_blocks()returns
0.ext4_journal_bmap()logs "journal bmap failed" and aborts the journal, but also returns 0 and leaves *block unchanged.
jbd2_journal_bmap()takes that as success and uses the unchanged logical journal block number as a physical filesystem block number. Journal I/O can then overwrite filesystem blocks outside the journal despite the abort.
Quoted 4 lines
Return
-EFSCORRUPTEDfor a hole, matching the error passed tojbd2_journal_abort(). Keep propagating negative mapping errors.Fixes 62913ae96de7 ("ext4, jbd2: add an optimized bmap for the journal inode")
A friendly ping on this ext4_journal_bmap() fix, which carries Reviewed-by tags from Jan Kara and Zhang Yi. Is anything else needed from my side?
Karl
Quoted 10 lines · Karl Mehltretter
If the internal journal inode contains a hole,
ext4_map_blocks()returns
0.ext4_journal_bmap()logs "journal bmap failed" and aborts the journal, but also returns 0 and leaves *block unchanged.
jbd2_journal_bmap()takes that as success and uses the unchanged logical journal block number as a physical filesystem block number. Journal I/O can then overwrite filesystem blocks outside the journal despite the abort.[...]
Applied, thanks!
[1/1] ext4: return an error when a journal block is not mapped
commit: 5fbfd161f88e6027338766014a268a19e4aa6607
Best regards,
Signature · 1 line
Theodore Ts'o <[email protected]>