From nobody Tue Sep 16 05:49:14 2025 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 87EF2C54EBF for ; Fri, 6 Jan 2023 10:22:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233701AbjAFKWp (ORCPT ); Fri, 6 Jan 2023 05:22:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232327AbjAFKWi (ORCPT ); Fri, 6 Jan 2023 05:22:38 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B98866086D; Fri, 6 Jan 2023 02:22:36 -0800 (PST) Received: from dggpeml500021.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4NpK692HZyzqTKJ; Fri, 6 Jan 2023 18:17:53 +0800 (CST) Received: from huawei.com (10.175.127.227) by dggpeml500021.china.huawei.com (7.185.36.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Fri, 6 Jan 2023 18:22:34 +0800 From: Baokun Li To: CC: , , , , , , , , =?UTF-8?q?Lu=C3=ADs=20Henriques?= Subject: [PATCH 1/2] ext4: fail ext4_iget if special inode unallocated Date: Fri, 6 Jan 2023 18:47:05 +0800 Message-ID: <20230106104706.2410740-2-libaokun1@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230106104706.2410740-1-libaokun1@huawei.com> References: <20230106104706.2410740-1-libaokun1@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpeml500021.china.huawei.com (7.185.36.21) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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=3D199179 Link: https://bugzilla.kernel.org/show_bug.cgi?id=3D216541 Link: https://bugzilla.kernel.org/show_bug.cgi?id=3D216539 Reported-by: Lu=C3=ADs Henriques Suggested-by: Theodore Ts'o Signed-off-by: Baokun Li --- fs/ext4/inode.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 9d9f414f99fe..3f7cfa91ba89 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -4872,13 +4872,6 @@ struct inode *__ext4_iget(struct super_block *sb, un= signed long ino, goto bad_inode; raw_inode =3D ext4_raw_inode(&iloc); =20 - if ((ino =3D=3D EXT4_ROOT_INO) && (raw_inode->i_links_count =3D=3D 0)) { - ext4_error_inode(inode, function, line, 0, - "iget: root inode unallocated"); - ret =3D -EFSCORRUPTED; - goto bad_inode; - } - if ((flags & EXT4_IGET_HANDLE) && (raw_inode->i_links_count =3D=3D 0) && (raw_inode->i_mode =3D=3D 0)) { ret =3D -ESTALE; @@ -4951,10 +4944,13 @@ struct inode *__ext4_iget(struct super_block *sb, u= nsigned long ino, * NeilBrown 1999oct15 */ if (inode->i_nlink =3D=3D 0) { - if ((inode->i_mode =3D=3D 0 || + if ((inode->i_mode =3D=3D 0 || (flags & EXT4_IGET_SPECIAL) || !(EXT4_SB(inode->i_sb)->s_mount_state & EXT4_ORPHAN_FS)) && ino !=3D EXT4_BOOT_LOADER_INO) { /* this inode is deleted */ + if (flags & EXT4_IGET_SPECIAL) + ext4_error_inode(inode, function, line, 0, + "iget: special inode unallocated"); ret =3D -ESTALE; goto bad_inode; } --=20 2.31.1