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 X-Spam-Level: X-Spam-Status: No, score=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 68B67C433EF for ; Fri, 10 Sep 2021 00:44:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5331461108 for ; Fri, 10 Sep 2021 00:44:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240999AbhIJAqF (ORCPT ); Thu, 9 Sep 2021 20:46:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:48344 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234088AbhIJAWo (ORCPT ); Thu, 9 Sep 2021 20:22:44 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A17DA603E7; Fri, 10 Sep 2021 00:21:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631233294; bh=x8DmX0JJlAaaCUxQ6s8Diga+hLfcIwvUCgSvchGtlM4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qMIc6rUmaKWWoo85D9UFCQ653WDfdkj4bAZ1QnnC94kw51HaQ8NjqcaZuv3srD9aS 5an4mJ1Pe7AYmhHRQavRIv3Kp1xQ7Kc+wycFXrwOSgVz9UIP9fbT4i+gBFLFLAzC9S RgZcpQQ+4UpwxW5X1UqUOmaJVQZwrF9wZsKJ6HoWfMleboSpOl6aC250IIqlzr96mX mumWgO1cVmF7ym05iJZ4v+8zdseisW2VTGGDTnTEARcYn+fVWqKvWE9SrPIznfEZQ9 bPhw1WJ2o1mfEgTPklfYEMJLychk8R9hF4A0My98QbtDa3EfgtvuXIk6SoB3RUP1Bp ouSKUf1hysapw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Jan Kara , Theodore Ts'o , Sasha Levin , linux-ext4@vger.kernel.org Subject: [PATCH AUTOSEL 5.10 48/53] ext4: Make sure quota files are not grabbed accidentally Date: Thu, 9 Sep 2021 20:20:23 -0400 Message-Id: <20210910002028.175174-48-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210910002028.175174-1-sashal@kernel.org> References: <20210910002028.175174-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Jan Kara [ Upstream commit bd2c38cf1726ea913024393a0d11f2e2a3f4c180 ] If ext4 filesystem is corrupted so that quota files are linked from directory hirerarchy, bad things can happen. E.g. quota files can get corrupted or deleted. Make sure we are not grabbing quota file inodes when we expect normal inodes. Signed-off-by: Jan Kara Signed-off-by: Theodore Ts'o Link: https://lore.kernel.org/r/20210812133122.26360-1-jack@suse.cz Signed-off-by: Sasha Levin --- fs/ext4/inode.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 18a5321b5ef3..b90493875174 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -4604,6 +4604,7 @@ struct inode *__ext4_iget(struct super_block *sb, unsigned long ino, struct ext4_iloc iloc; struct ext4_inode *raw_inode; struct ext4_inode_info *ei; + struct ext4_super_block *es = EXT4_SB(sb)->s_es; struct inode *inode; journal_t *journal = EXT4_SB(sb)->s_journal; long ret; @@ -4614,9 +4615,12 @@ struct inode *__ext4_iget(struct super_block *sb, unsigned long ino, projid_t i_projid; if ((!(flags & EXT4_IGET_SPECIAL) && - (ino < EXT4_FIRST_INO(sb) && ino != EXT4_ROOT_INO)) || + ((ino < EXT4_FIRST_INO(sb) && ino != EXT4_ROOT_INO) || + ino == le32_to_cpu(es->s_usr_quota_inum) || + ino == le32_to_cpu(es->s_grp_quota_inum) || + ino == le32_to_cpu(es->s_prj_quota_inum))) || (ino < EXT4_ROOT_INO) || - (ino > le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count))) { + (ino > le32_to_cpu(es->s_inodes_count))) { if (flags & EXT4_IGET_HANDLE) return ERR_PTR(-ESTALE); __ext4_error(sb, function, line, EFSCORRUPTED, 0, -- 2.30.2