From 583f6af930da2eeae2a3a8b2d99b700cf4a6cb61 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Thu, 29 Mar 2018 21:56:09 -0400 Subject: [PATCH] ext4: fail ext4_iget for root directory if unallocated If the root directory has an i_links_count of zero, then when the file system is mounted, then when ext4_fill_super() notices the problem and tries to call iput() the root directory in the error return path, ext4_evict_inode() will try to free the inode on disk, before all of the file system structures are set up, and this will result in an OOPS caused by a NULL pointer dereference. This issue has been assigned CVE-2018-1092. https://bugzilla.kernel.org/show_bug.cgi?id=199179 https://bugzilla.redhat.com/show_bug.cgi?id=1560777 Reported-by: Wen Xu Signed-off-by: Theodore Ts'o Cc: stable@vger.kernel.org (cherry picked from commit 8e4b5eae5decd9dfe5a4ee369c22028f90ab4c44) Orabug: 29048557 CVE: CVE-2018-1092 Reviewed-by: Darren Kenny Signed-off-by: Allen Pais The current patch borrows EFSBADCRC & EFSCORRUPTED flags from the patch below 6a797d27: ext4: call out CRC and corruption errors with specific error codes Signed-off-by: Brian Maly --- fs/ext4/ext4.h | 3 +++ fs/ext4/inode.c | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 0db69ab59cdf..d3ccdf3f2795 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -3171,4 +3171,7 @@ static inline void ext4_clear_io_unwritten_flag(ext4_io_end_t *io_end) #endif /* __KERNEL__ */ +#define EFSBADCRC EBADMSG /* Bad CRC detected */ +#define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */ + #endif /* _EXT4_H */ diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 52b6edde511b..a71df7f34c3f 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -4156,6 +4156,12 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino) goto bad_inode; raw_inode = ext4_raw_inode(&iloc); + if ((ino == EXT4_ROOT_INO) && (raw_inode->i_links_count == 0)) { + EXT4_ERROR_INODE(inode, "root inode unallocated"); + ret = -EFSCORRUPTED; + goto bad_inode; + } + if (EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE) { ei->i_extra_isize = le16_to_cpu(raw_inode->i_extra_isize); if (EXT4_GOOD_OLD_INODE_SIZE + ei->i_extra_isize > -- 2.50.1