f2fs: avoid trying to get invalid block address
Jaegeuk Kim
maintainerPATCH 1/1 f2fs: avoid trying to get invalid block address
In f2fs_new_inode(), if we fail to get a new inode, we go iput(), followed by f2fs_evict_inode(). If the inode is not marked as bad, it'll try to call f2fs_remove_inode_page() which tries to read the inode block given node id. But, there's no block address allocated yet, which gives a chance to access a wrong block address, if the block device has some garbage data in NAT table.
We need to make sure NAT table should have zero data for all the unallocated node ids, but also would be better to take this unnecessary path as well. Let's mark the faild inode as bad.
--- fs/f2fs/namei.c | 1 + 1 file changed, 1 insertion(+)
fs/f2fs/namei.c +1 -0
@@ -341,6 +341,7 @@ static struct inode *f2fs_new_inode(struct mnt_idmap *idmap,trace_f2fs_new_inode (inode, err);dquot_drop (inode); inode->i_flags |=S_NOQUOTA ; +make_bad_inode (inode);if (nid_free)set_inode_flag (inode,FI_FREE_NID );clear_nlink (inode);
Signature · 1 line
2.48.0.rc2.279.g1de40edade-goog
Quoted 10 lines · On 1/18/25 06:09, Jaegeuk Kim via Linux-f2fs-devel wrote:
In
f2fs_new_inode(), if we fail to get a new inode, we goiput(), followed byf2fs_evict_inode(). If the inode is not marked as bad, it'll try to callf2fs_remove_inode_page()which tries to read the inode block given node id. But, there's no block address allocated yet, which gives a chance to access a wrong block address, if the block device has some garbage data in NAT table.We need to make sure NAT table should have zero data for all the unallocated node ids, but also would be better to take this unnecessary path as well. Let's mark the faild inode as bad.
Needs a fixes line?
Otherwise, it looks good to me.
Thanks,
Quoted 17 lines
Signed-off-by Jaegeuk Kim <[email protected]>--- fs/f2fs/namei.c | 1 + 1 file changed, 1 insertion(+)fs/f2fs/namei.c +1
-0@@ -341,6 +341,7 @@ static struct inode *f2fs_new_inode(struct mnt_idmap *idmap,trace_f2fs_new_inode (inode, err);dquot_drop (inode); inode->i_flags |=S_NOQUOTA ; +make_bad_inode (inode);if (nid_free)set_inode_flag (inode,FI_FREE_NID );clear_nlink (inode);
This patch was applied to jaegeuk/f2fs.git (dev) by Jaegeuk Kim <[email protected]>:
Hello:
This patch was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <[email protected]>:
Quoted 11 lines · On Fri, 17 Jan 2025 22:09:55 +0000 you wrote:
In
f2fs_new_inode(), if we fail to get a new inode, we goiput(), followed byf2fs_evict_inode(). If the inode is not marked as bad, it'll try to callf2fs_remove_inode_page()which tries to read the inode block given node id. But, there's no block address allocated yet, which gives a chance to access a wrong block address, if the block device has some garbage data in NAT table.We need to make sure NAT table should have zero data for all the unallocated node ids, but also would be better to take this unnecessary path as well. Let's mark the faild inode as bad.
[...]
Here is the summary with links:
- [f2fs-dev] f2fs: avoid trying to get invalid block address
https://git.kernel.org/jaegeuk/f2fs/c/e02938613eb2
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html