Skip to content

Commit

Permalink
vfs: don't evict uninitialized inode
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Miklos Szeredi <[email protected]>
Fixes: 80ea09a ("vfs: factor out inode_insert5()")
Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
Miklos Szeredi authored and Al Viro committed Aug 3, 2018
1 parent a6cbedf commit e950564
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions fs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,7 @@ struct inode *inode_insert5(struct inode *inode, unsigned long hashval,
{
struct hlist_head *head = inode_hashtable + hash(inode->i_sb, hashval);
struct inode *old;
bool creating = inode->i_state & I_CREATING;

again:
spin_lock(&inode_hash_lock);
Expand Down Expand Up @@ -1083,6 +1084,8 @@ struct inode *inode_insert5(struct inode *inode, unsigned long hashval,
inode->i_state |= I_NEW;
hlist_add_head(&inode->i_hash, head);
spin_unlock(&inode->i_lock);
if (!creating)
inode_sb_list_add(inode);
unlock:
spin_unlock(&inode_hash_lock);

Expand Down Expand Up @@ -1117,12 +1120,13 @@ 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 = alloc_inode(sb);

if (new) {
new->i_state = 0;
inode = inode_insert5(new, hashval, test, set, data);
if (unlikely(inode != new))
iput(new);
destroy_inode(new);
}
}
return inode;
Expand Down

0 comments on commit e950564

Please sign in to comment.