Skip to content

Commit ccad447

Browse files
OjaswinMtytso
authored andcommitted
ext4: make block validity check resistent to sb bh corruption
Block validity checks need to be skipped in case they are called for journal blocks since they are part of system's protected zone. Currently, this is done by checking inode->ino against sbi->s_es->s_journal_inum, which is a direct read from the ext4 sb buffer head. If someone modifies this underneath us then the s_journal_inum field might get corrupted. To prevent against this, change the check to directly compare the inode with journal->j_inode. **Slight change in behavior**: During journal init path, check_block_validity etc might be called for journal inode when sbi->s_journal is not set yet. In this case we now proceed with ext4_inode_block_valid() instead of returning early. Since systems zones have not been set yet, it is okay to proceed so we can perform basic checks on the blocks. Suggested-by: Baokun Li <[email protected]> Reviewed-by: Baokun Li <[email protected]> Reviewed-by: Jan Kara <[email protected]> Reviewed-by: Zhang Yi <[email protected]> Signed-off-by: Ojaswin Mujoo <[email protected]> Link: https://patch.msgid.link/0c06bc9ebfcd6ccfed84a36e79147bf45ff5adc1.1743142920.git.ojaswin@linux.ibm.com Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 7e50bbb commit ccad447

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

fs/ext4/block_validity.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,9 @@ int ext4_check_blockref(const char *function, unsigned int line,
351351
{
352352
__le32 *bref = p;
353353
unsigned int blk;
354+
journal_t *journal = EXT4_SB(inode->i_sb)->s_journal;
354355

355-
if (ext4_has_feature_journal(inode->i_sb) &&
356-
(inode->i_ino ==
357-
le32_to_cpu(EXT4_SB(inode->i_sb)->s_es->s_journal_inum)))
356+
if (journal && inode == journal->j_inode)
358357
return 0;
359358

360359
while (bref < p+max) {

fs/ext4/inode.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,10 +384,11 @@ static int __check_block_validity(struct inode *inode, const char *func,
384384
unsigned int line,
385385
struct ext4_map_blocks *map)
386386
{
387-
if (ext4_has_feature_journal(inode->i_sb) &&
388-
(inode->i_ino ==
389-
le32_to_cpu(EXT4_SB(inode->i_sb)->s_es->s_journal_inum)))
387+
journal_t *journal = EXT4_SB(inode->i_sb)->s_journal;
388+
389+
if (journal && inode == journal->j_inode)
390390
return 0;
391+
391392
if (!ext4_inode_block_valid(inode, map->m_pblk, map->m_len)) {
392393
ext4_error_inode(inode, func, line, map->m_pblk,
393394
"lblock %lu mapped to illegal pblock %llu "

0 commit comments

Comments
 (0)