fs/9p: fix uninitialized values during inode evict
authorEric Van Hensbergen <ericvh@kernel.org>
Tue, 19 Mar 2024 13:50:32 +0000 (13:50 +0000)
committerEric Van Hensbergen <ericvh@kernel.org>
Mon, 25 Mar 2024 14:16:06 +0000 (14:16 +0000)
If an iget fails due to not being able to retrieve information
from the server then the inode structure is only partially
initialized.  When the inode gets evicted, references to
uninitialized structures (like fscache cookies) were being
made.

This patch checks for a bad_inode before doing anything other
than clearing the inode from the cache.  Since the inode is
bad, it shouldn't have any state associated with it that needs
to be written back (and there really isn't a way to complete
those anyways).

Reported-by: syzbot+eb83fe1cce5833cd66a0@syzkaller.appspotmail.com
Signed-off-by: Eric Van Hensbergen <ericvh@kernel.org>
fs/9p/vfs_inode.c

index 360a5304ec03ce53e5bab61e2177a5f325569ebf..b01b1bbf24937168f6fdabe920ddbad0bae3e5d9 100644 (file)
@@ -344,17 +344,21 @@ void v9fs_evict_inode(struct inode *inode)
        struct v9fs_inode __maybe_unused *v9inode = V9FS_I(inode);
        __le32 __maybe_unused version;
 
-       truncate_inode_pages_final(&inode->i_data);
+       if (!is_bad_inode(inode)) {
+               truncate_inode_pages_final(&inode->i_data);
 
-       version = cpu_to_le32(v9inode->qid.version);
-       netfs_clear_inode_writeback(inode, &version);
+               version = cpu_to_le32(v9inode->qid.version);
+               netfs_clear_inode_writeback(inode, &version);
 
-       clear_inode(inode);
-       filemap_fdatawrite(&inode->i_data);
+               clear_inode(inode);
+               filemap_fdatawrite(&inode->i_data);
 
 #ifdef CONFIG_9P_FSCACHE
-       fscache_relinquish_cookie(v9fs_inode_cookie(v9inode), false);
+               if (v9fs_inode_cookie(v9inode))
+                       fscache_relinquish_cookie(v9fs_inode_cookie(v9inode), false);
 #endif
+       } else
+               clear_inode(inode);
 }
 
 struct inode *v9fs_fid_iget(struct super_block *sb, struct p9_fid *fid)