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=-13.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 350ECC63699 for ; Tue, 27 Oct 2020 00:06:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EF40520791 for ; Tue, 27 Oct 2020 00:06:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603757161; bh=jvrQeHg/oQEgAi5597Y8RqY/n70i6FEULjgF1fYF0WU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=PdcJju3e2VWPRmVhmuvqwlheXLbXz1bPNnOY7k0luJ24NUfUbR6+BKUf4IhIcf0Fe WwEC8bPEQ7a+54iLH0XiLjg5GHh9OKqy4HUJDwEQtpBnCNyg5RZdpQYCoPt7j9dqle 7EevU/ALGLfYKby98qw74OPvJvH7b34+88lAwP0M= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2438646AbgJ0AF7 (ORCPT ); Mon, 26 Oct 2020 20:05:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:54116 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2438167AbgJ0AFO (ORCPT ); Mon, 26 Oct 2020 20:05:14 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B657E20882; Tue, 27 Oct 2020 00:05:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603757113; bh=jvrQeHg/oQEgAi5597Y8RqY/n70i6FEULjgF1fYF0WU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bv5DZY/hL4JNPElJWH2hYgVrTSTbwiTIenZGyNpfX27v9Y3+kxIFWZmbjJdhYT5+G 4DOwQ5bLZw/bjnQMipEchIW5LFJuS64hWP78fZ7VQGMZ65V621+8JdpdAVzdl5csl/ CU3Ylycc3j+a2pPziQh3SX/z0szxYgx6V5aRx5oY= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Jan Kara , Andreas Dilger , Ritesh Harjani , Theodore Ts'o , Sasha Levin , linux-ext4@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 49/60] ext4: Detect already used quota file early Date: Mon, 26 Oct 2020 20:04:04 -0400 Message-Id: <20201027000415.1026364-49-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201027000415.1026364-1-sashal@kernel.org> References: <20201027000415.1026364-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 e0770e91424f694b461141cbc99adf6b23006b60 ] When we try to use file already used as a quota file again (for the same or different quota type), strange things can happen. At the very least lockdep annotations may be wrong but also inode flags may be wrongly set / reset. When the file is used for two quota types at once we can even corrupt the file and likely crash the kernel. Catch all these cases by checking whether passed file is already used as quota file and bail early in that case. This fixes occasional generic/219 failure due to lockdep complaint. Reviewed-by: Andreas Dilger Reported-by: Ritesh Harjani Signed-off-by: Jan Kara Link: https://lore.kernel.org/r/20201015110330.28716-1-jack@suse.cz Signed-off-by: Theodore Ts'o Signed-off-by: Sasha Levin --- fs/ext4/super.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 0c15ff19acbd4..16ea7cfd130c0 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -5752,6 +5752,11 @@ static int ext4_quota_on(struct super_block *sb, int type, int format_id, /* Quotafile not on the same filesystem? */ if (path->dentry->d_sb != sb) return -EXDEV; + + /* Quota already enabled for this file? */ + if (IS_NOQUOTA(d_inode(path->dentry))) + return -EBUSY; + /* Journaling quota? */ if (EXT4_SB(sb)->s_qf_names[type]) { /* Quotafile not in fs root? */ -- 2.25.1