Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: 80ea09a002bf ("vfs: factor out inode_insert5()")
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

authored by

Miklos Szeredi and committed by
Al Viro
e950564b a6cbedfa

+6 -2
+6 -2
fs/inode.c
··· 1050 1050 { 1051 1051 struct hlist_head *head = inode_hashtable + hash(inode->i_sb, hashval); 1052 1052 struct inode *old; 1053 + bool creating = inode->i_state & I_CREATING; 1053 1054 1054 1055 again: 1055 1056 spin_lock(&inode_hash_lock); ··· 1084 1083 inode->i_state |= I_NEW; 1085 1084 hlist_add_head(&inode->i_hash, head); 1086 1085 spin_unlock(&inode->i_lock); 1086 + if (!creating) 1087 + inode_sb_list_add(inode); 1087 1088 unlock: 1088 1089 spin_unlock(&inode_hash_lock); 1089 1090 ··· 1120 1117 struct inode *inode = ilookup5(sb, hashval, test, data); 1121 1118 1122 1119 if (!inode) { 1123 - struct inode *new = new_inode(sb); 1120 + struct inode *new = alloc_inode(sb); 1124 1121 1125 1122 if (new) { 1123 + new->i_state = 0; 1126 1124 inode = inode_insert5(new, hashval, test, set, data); 1127 1125 if (unlikely(inode != new)) 1128 - iput(new); 1126 + destroy_inode(new); 1129 1127 } 1130 1128 } 1131 1129 return inode;