Skip to content

Commit e950564

Browse files
Miklos SzerediAl Viro
authored andcommitted
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 if inode is not in I_CREATING state (meaning that it wasn't allocated with new_inode(), which already does the insertion). Reported-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com> Fixes: 80ea09a ("vfs: factor out inode_insert5()") Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent a6cbedf commit e950564

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

‎fs/inode.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,7 @@ struct inode *inode_insert5(struct inode *inode, unsigned long hashval,
10501050
{
10511051
struct hlist_head *head = inode_hashtable + hash(inode->i_sb, hashval);
10521052
struct inode *old;
1053+
bool creating = inode->i_state & I_CREATING;
10531054

10541055
again:
10551056
spin_lock(&inode_hash_lock);
@@ -1083,6 +1084,8 @@ struct inode *inode_insert5(struct inode *inode, unsigned long hashval,
10831084
inode->i_state |= I_NEW;
10841085
hlist_add_head(&inode->i_hash, head);
10851086
spin_unlock(&inode->i_lock);
1087+
if (!creating)
1088+
inode_sb_list_add(inode);
10861089
unlock:
10871090
spin_unlock(&inode_hash_lock);
10881091

@@ -1117,12 +1120,13 @@ struct inode *iget5_locked(struct super_block *sb, unsigned long hashval,
11171120
struct inode *inode = ilookup5(sb, hashval, test, data);
11181121

11191122
if (!inode) {
1120-
struct inode *new = new_inode(sb);
1123+
struct inode *new = alloc_inode(sb);
11211124

11221125
if (new) {
1126+
new->i_state = 0;
11231127
inode = inode_insert5(new, hashval, test, set, data);
11241128
if (unlikely(inode != new))
1125-
iput(new);
1129+
destroy_inode(new);
11261130
}
11271131
}
11281132
return inode;

0 commit comments

Comments
 (0)