vfs: don't evict uninitialized inode
PATCH 1/1 vfs: don't evict uninitialized inode
iput() ends up calling ->evict() on new inode, which is not yet initialized by owning fs. So use destroy_inode() instead.
Add to sb->s_inodes list only after the inode has been inserted into the hash. The exact point at which the inode is added onto the sb list shouldn't matter as long as it is done while the inode is in the I_NEW state.
--- fs/inode.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
fs/inode.c +4 -2
@@ -1094,12 +1094,14 @@ struct inode *iget5_locked(struct super_block *sb, unsigned long hashval,struct inode *inode =ilookup5 (sb, hashval, test, data);if (!inode) { -struct inode *new =new_inode (sb); +struct inode *new =new_inode_pseudo (sb);if (new) { inode =inode_insert5 (new, hashval, test, set, data);if (unlikely (inode != new)) -iput (new); +destroy_inode (new); +else +inode_sb_list_add (inode); } }return inode;
Signature · 1 line
2.14.3
Al Viro
maintainerQuoted 11 lines · Miklos Szeredi
iput()ends up calling ->evict() on new inode, which is not yet initialized by owning fs. So usedestroy_inode()instead.Add to
sb->s_inodeslist only after the inode has been inserted into the hash. The exact point at which the inode is added onto the sb list shouldn't matter as long as it is done while the inode is in theI_NEWstate.Reported-by Al Viro <[email protected]>Signed-off-by Miklos Szeredi <[email protected]>Fixes 80ea09a002bf ("vfs: factor out inode_insert5()")
Check 22dc9a168272 (new primitive: discard_new_inode()) in vfs.git; IMO yours should go on top of that and I would seriously consider going for just alloc_inode() - to hell with new_inode_pseudo(). I_CREATING gives an easy way for insert_inode5() to decide whether we need to move into ->i_sb_list...