From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C61CEC6FD1C for ; Tue, 14 Mar 2023 12:47:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232214AbjCNMq6 (ORCPT ); Tue, 14 Mar 2023 08:46:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230515AbjCNMp6 (ORCPT ); Tue, 14 Mar 2023 08:45:58 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E91271E1CC; Tue, 14 Mar 2023 05:44:46 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id F158461766; Tue, 14 Mar 2023 12:43:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 83405C433EF; Tue, 14 Mar 2023 12:43:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678797831; bh=B8XwBF9cJj831K0nVxQgB0VN3wH53KaNqjdKN0CyaqI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sipWRw++tBldiRNs4JBcj+5vSnk6lo5Qv/Qe3wKUnmhDyt8+++2Ox7eiuEsw++oqT Cd61/+ZRxr9BtNQuih8PI0iCaJiF8Ku8SuZ8mZRJu80wngJrRvdj8mXyjmyo7CytZl kO4+Fw6b9TEKmDBrLv1DSjYVz+dABX7tFrz3LxWqh7+6E7q1icZEeB1J+eujG29yoB sh73KW9g2cQgcY3Mo1fzszPG46AKcpggWV2lxUcRV0udwuQydTwZuTvlcSYNyav47+ YBStPOh71L7qfCxTvVRmbTQqxtpF+lPboEEp1iOSeCxsOuhzC/Ln9yM7/42uT1gp6Q /uJDVRpc4jrlA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Baokun Li , =?UTF-8?q?Lu=C3=ADs=20Henriques?= , Theodore Ts'o , Jan Kara , Sasha Levin , adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org Subject: [PATCH AUTOSEL 5.15 04/10] ext4: fail ext4_iget if special inode unallocated Date: Tue, 14 Mar 2023 08:43:38 -0400 Message-Id: <20230314124344.471127-4-sashal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230314124344.471127-1-sashal@kernel.org> References: <20230314124344.471127-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Baokun Li [ Upstream commit 5cd740287ae5e3f9d1c46f5bfe8778972fd6d3fe ] In ext4_fill_super(), EXT4_ORPHAN_FS flag is cleared after ext4_orphan_cleanup() is executed. Therefore, when __ext4_iget() is called to get an inode whose i_nlink is 0 when the flag exists, no error is returned. If the inode is a special inode, a null pointer dereference may occur. If the value of i_nlink is 0 for any inodes (except boot loader inodes) got by using the EXT4_IGET_SPECIAL flag, the current file system is corrupted. Therefore, make the ext4_iget() function return an error if it gets such an abnormal special inode. Link: https://bugzilla.kernel.org/show_bug.cgi?id=199179 Link: https://bugzilla.kernel.org/show_bug.cgi?id=216541 Link: https://bugzilla.kernel.org/show_bug.cgi?id=216539 Reported-by: Luís Henriques Suggested-by: Theodore Ts'o Signed-off-by: Baokun Li Reviewed-by: Jan Kara Link: https://lore.kernel.org/r/20230107032126.4165860-2-libaokun1@huawei.com Signed-off-by: Theodore Ts'o Signed-off-by: Sasha Levin --- fs/ext4/inode.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 0a63863bc58c1..374256e0ce326 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -4631,13 +4631,6 @@ 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, function, line, 0, - "iget: root inode unallocated"); - ret = -EFSCORRUPTED; - goto bad_inode; - } - if ((flags & EXT4_IGET_HANDLE) && (raw_inode->i_links_count == 0) && (raw_inode->i_mode == 0)) { ret = -ESTALE; @@ -4710,11 +4703,16 @@ struct inode *__ext4_iget(struct super_block *sb, unsigned long ino, * NeilBrown 1999oct15 */ if (inode->i_nlink == 0) { - if ((inode->i_mode == 0 || + if ((inode->i_mode == 0 || flags & EXT4_IGET_SPECIAL || !(EXT4_SB(inode->i_sb)->s_mount_state & EXT4_ORPHAN_FS)) && ino != EXT4_BOOT_LOADER_INO) { - /* this inode is deleted */ - ret = -ESTALE; + /* this inode is deleted or unallocated */ + if (flags & EXT4_IGET_SPECIAL) { + ext4_error_inode(inode, function, line, 0, + "iget: special inode unallocated"); + ret = -EFSCORRUPTED; + } else + ret = -ESTALE; goto bad_inode; } /* The only unlinked inodes we let through here have -- 2.39.2