nilfs2: fix NULL pointer dereference at nilfs_bmap_lookup_at_level()
authorRyusuke Konishi <konishi.ryusuke@gmail.com>
Sun, 2 Oct 2022 03:08:04 +0000 (12:08 +0900)
committerAndrew Morton <akpm@linux-foundation.org>
Wed, 12 Oct 2022 02:05:45 +0000 (19:05 -0700)
If the i_mode field in inode of metadata files is corrupted on disk, it
can cause the initialization of bmap structure, which should have been
called from nilfs_read_inode_common(), not to be called.  This causes a
lockdep warning followed by a NULL pointer dereference at
nilfs_bmap_lookup_at_level().

This patch fixes these issues by adding a missing sanitiy check for the
i_mode field of metadata file's inode.

Link: https://lkml.kernel.org/r/20221002030804.29978-1-konishi.ryusuke@gmail.com
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Reported-by: syzbot+2b32eb36c1a825b7a74c@syzkaller.appspotmail.com
Reported-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Tested-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
fs/nilfs2/inode.c

index b074144..232dd7b 100644 (file)
@@ -455,6 +455,8 @@ int nilfs_read_inode_common(struct inode *inode,
        inode->i_atime.tv_nsec = le32_to_cpu(raw_inode->i_mtime_nsec);
        inode->i_ctime.tv_nsec = le32_to_cpu(raw_inode->i_ctime_nsec);
        inode->i_mtime.tv_nsec = le32_to_cpu(raw_inode->i_mtime_nsec);
+       if (nilfs_is_metadata_file_inode(inode) && !S_ISREG(inode->i_mode))
+               return -EIO; /* this inode is for metadata and corrupted */
        if (inode->i_nlink == 0)
                return -ESTALE; /* this inode is deleted */