ext4: fix iloc.bh leak in ext4_fc_replay_inode() error paths
Baokun Li
reviewerPATCH 1/1 ext4: fix iloc.bh leak in ext4_fc_replay_inode() error paths
During code review, Joseph found that ext4_fc_replay_inode() calls ext4_get_fc_inode_loc() to get the inode location, which holds a reference to iloc.bh that must be released via brelse().
However, several error paths jump to the 'out' label without releasing iloc.bh:
- ext4_handle_dirty_metadata() failure
- sync_dirty_buffer() failure
- ext4_mark_inode_used() failure
- ext4_iget() failure
Fix this by introducing an 'out_brelse' label placed just before the existing 'out' label to ensure iloc.bh is always released.
Additionally, make ext4_fc_replay_inode() propagate errors properly instead of always returning 0.
--- fs/ext4/fast_commit.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
fs/ext4/fast_commit.c +8 -5
@@ -1613,19 +1613,21 @@ static int ext4_fc_replay_inode(struct super_block *sb,/* Immediately update the inode on disk. */ ret =ext4_handle_dirty_metadata (NULL ,NULL , iloc.bh);if (ret) - goto out; + goto out_brelse; ret =sync_dirty_buffer (iloc.bh);if (ret) - goto out; + goto out_brelse; ret =ext4_mark_inode_used (sb, ino);if (ret) - goto out; + goto out_brelse;/* Given that we just wrote the inode on disk, this SHOULD succeed. */ inode =ext4_iget (sb, ino,EXT4_IGET_NORMAL );if (IS_ERR (inode)) {ext4_debug ("Inode not found." ); -return -EFSCORRUPTED ; + inode =NULL ; + ret = -EFSCORRUPTED ; + goto out_brelse; }/*
@@ -1642,13 +1644,14 @@ static int ext4_fc_replay_inode(struct super_block *sb,ext4_inode_csum_set (inode,ext4_raw_inode (&iloc),EXT4_I (inode)); ret =ext4_handle_dirty_metadata (NULL ,NULL , iloc.bh);sync_dirty_buffer (iloc.bh); +out_brelse:brelse (iloc.bh); out:iput (inode);if (!ret)blkdev_issue_flush (sb->s_bdev); -return 0 ; +return ret; }/*
Signature · 1 line
2.43.7
Quoted 15 lines · Baokun Li
During code review, Joseph found that
ext4_fc_replay_inode()callsext4_get_fc_inode_loc()to get the inode location, which holds a reference to iloc.bh that must be released viabrelse().However, several error paths jump to the 'out' label without releasing iloc.bh:
-
ext4_handle_dirty_metadata()failure
-sync_dirty_buffer()failure
-ext4_mark_inode_used()failure
-ext4_iget()failureFix this by introducing an '
out_brelse' label placed just before the existing 'out' label to ensure iloc.bh is always released.
Quoted 6 lines
Additionally, make
ext4_fc_replay_inode()propagate errors properly instead of always returning 0.Reported-by Joseph Qi <[email protected]>Fixes 8016e29f4362 ("ext4: fast commit recovery path")Signed-off-by Baokun Li <[email protected]>
Looks good. Feel free to add:
Honza
Quoted 53 lines
--- fs/ext4/fast_commit.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)fs/ext4/fast_commit.c +8
-5@@ -1613,19 +1613,21 @@ static int ext4_fc_replay_inode(struct super_block *sb,/* Immediately update the inode on disk. */ ret =ext4_handle_dirty_metadata (NULL ,NULL , iloc.bh);if (ret) - goto out; + goto out_brelse; ret =sync_dirty_buffer (iloc.bh);if (ret) - goto out; + goto out_brelse; ret =ext4_mark_inode_used (sb, ino);if (ret) - goto out; + goto out_brelse;/* Given that we just wrote the inode on disk, this SHOULD succeed. */ inode =ext4_iget (sb, ino,EXT4_IGET_NORMAL );if (IS_ERR (inode)) {ext4_debug ("Inode not found." ); -return -EFSCORRUPTED ; + inode =NULL ; + ret = -EFSCORRUPTED ; + goto out_brelse; }/* @@ -1642,13 +1644,14 @@ static int ext4_fc_replay_inode(struct super_block *sb,ext4_inode_csum_set (inode,ext4_raw_inode (&iloc),EXT4_I (inode)); ret =ext4_handle_dirty_metadata (NULL ,NULL , iloc.bh);sync_dirty_buffer (iloc.bh); +out_brelse:brelse (iloc.bh); out:iput (inode);if (!ret)blkdev_issue_flush (sb->s_bdev); -return 0 ; +return ret; }/* Signature · 1 line
2.43.7
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 15 lines · Baokun Li
During code review, Joseph found that
ext4_fc_replay_inode()callsext4_get_fc_inode_loc()to get the inode location, which holds a reference to iloc.bh that must be released viabrelse().However, several error paths jump to the 'out' label without releasing iloc.bh:
-
ext4_handle_dirty_metadata()failure
-sync_dirty_buffer()failure
-ext4_mark_inode_used()failure
-ext4_iget()failureFix this by introducing an '
out_brelse' label placed just before the existing 'out' label to ensure iloc.bh is always released.
Quoted 6 lines
Additionally, make
ext4_fc_replay_inode()propagate errors properly instead of always returning 0.Reported-by Joseph Qi <[email protected]>Fixes 8016e29f4362 ("ext4: fast commit recovery path")Signed-off-by Baokun Li <[email protected]>
Looks good to me.
Quoted 50 lines
--- fs/ext4/fast_commit.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)fs/ext4/fast_commit.c +8
-5@@ -1613,19 +1613,21 @@ static int ext4_fc_replay_inode(struct super_block *sb,/* Immediately update the inode on disk. */ ret =ext4_handle_dirty_metadata (NULL ,NULL , iloc.bh);if (ret) - goto out; + goto out_brelse; ret =sync_dirty_buffer (iloc.bh);if (ret) - goto out; + goto out_brelse; ret =ext4_mark_inode_used (sb, ino);if (ret) - goto out; + goto out_brelse;/* Given that we just wrote the inode on disk, this SHOULD succeed. */ inode =ext4_iget (sb, ino,EXT4_IGET_NORMAL );if (IS_ERR (inode)) {ext4_debug ("Inode not found." ); -return -EFSCORRUPTED ; + inode =NULL ; + ret = -EFSCORRUPTED ; + goto out_brelse; }/* @@ -1642,13 +1644,14 @@ static int ext4_fc_replay_inode(struct super_block *sb,ext4_inode_csum_set (inode,ext4_raw_inode (&iloc),EXT4_I (inode)); ret =ext4_handle_dirty_metadata (NULL ,NULL , iloc.bh);sync_dirty_buffer (iloc.bh); +out_brelse:brelse (iloc.bh); out:iput (inode);if (!ret)blkdev_issue_flush (sb->s_bdev); -return 0 ; +return ret; }/*
Quoted 8 lines · Baokun Li
During code review, Joseph found that
ext4_fc_replay_inode()callsext4_get_fc_inode_loc()to get the inode location, which holds a reference to iloc.bh that must be released viabrelse().However, several error paths jump to the 'out' label without releasing iloc.bh:
[...]
Applied, thanks!
[1/1] ext4: fix iloc.bh leak in ext4_fc_replay_inode() error paths
commit: ec0a7500d8eace5b4f305fa0c594dd148f0e8d29
Best regards,
Signature · 1 line
Theodore Ts'o <[email protected]>