From patchwork Tue Nov 3 20:36:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 317107 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=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, 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 6D9D2C2D0A3 for ; Tue, 3 Nov 2020 21:04:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 20AA820757 for ; Tue, 3 Nov 2020 21:04:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604437493; bh=FDgL0XsLhpdRFS4u/BcWRFfU2xZXVTDuou3wCX2E7rE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=O0sPskhHywhrdZJ2YDpfdjTMp1f+WEqRiqEqOAXYippfcwWUc5CAtFajAbv65007M 6KgcGMhW2V1Q9r+Q02cNOXLnqWTZDbSXLHA02xFJDneVhrydjFyP5chRLkEGyugE1P VXOAic/QRzYImzvb0stQLaMHZ6h61il4z92HxuCo= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732165AbgKCVEw (ORCPT ); Tue, 3 Nov 2020 16:04:52 -0500 Received: from mail.kernel.org ([198.145.29.99]:43068 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388033AbgKCVEv (ORCPT ); Tue, 3 Nov 2020 16:04:51 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 64F9220658; Tue, 3 Nov 2020 21:04:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604437490; bh=FDgL0XsLhpdRFS4u/BcWRFfU2xZXVTDuou3wCX2E7rE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AximMhgpPhEecMF5Kxu7qZ9y5oxqx6oYLtixLdWQ+Qv7uynla6FESsaCeA47nx5zA 3y8r1ZrhCmp1rp4mlMnNJkbxNBlbLznplHen3J7g9c19WlZipeAPJxynfWmR3STJeO GB0S9oquU5rvdQigABwkFGgx/fHZM5837RTvzC8w= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andreas Dilger , Ritesh Harjani , Jan Kara , Theodore Tso , Sasha Levin Subject: [PATCH 4.19 100/191] ext4: Detect already used quota file early Date: Tue, 3 Nov 2020 21:36:32 +0100 Message-Id: <20201103203243.088642273@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203232.656475008@linuxfoundation.org> References: <20201103203232.656475008@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@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? */