Return-Path: Received: from mail-pf0-f193.google.com ([209.85.192.193]:38200 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750714AbeDVEY4 (ORCPT ); Sun, 22 Apr 2018 00:24:56 -0400 Received: by mail-pf0-f193.google.com with SMTP id o76so1835057pfi.5 for ; Sat, 21 Apr 2018 21:24:56 -0700 (PDT) From: Harsh Shandilya To: stable@vger.kernel.org, tytso@mit.edu Cc: Harsh Shandilya Subject: [PATCH v3 3.18.y 2/3] ext4: fail ext4_iget for root directory if unallocated Date: Sun, 22 Apr 2018 09:54:06 +0530 Message-Id: <20180422042407.5820-3-harsh@prjkt.io> In-Reply-To: <20180422042407.5820-1-harsh@prjkt.io> References: <20180422042407.5820-1-harsh@prjkt.io> Sender: stable-owner@vger.kernel.org List-ID: From: Theodore Ts'o Commit 8e4b5eae5decd9dfe5a4ee369c22028f90ab4c44 upstream. 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 [harsh@prjkt.io: s/EFSCORRUPTED/EUCLEAN/ fs/ext4/inode.c] Signed-off-by: Harsh Shandilya --- fs/ext4/inode.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 77df898ed45b..d2ec9d2aa82b 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -4217,6 +4217,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 = -EUCLEAN; + 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.15.0.2308.g658a28aa74af