Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2297134ybl; Thu, 19 Dec 2019 11:10:49 -0800 (PST) X-Google-Smtp-Source: APXvYqy4ytQSb9ktRBZqZ9OOvLViNdS27AZIeOZ3+Tzq+H6jAwYSn14WzNFFtg6KgggNew4XyF2x X-Received: by 2002:a9d:4706:: with SMTP id a6mr9581341otf.331.1576782649653; Thu, 19 Dec 2019 11:10:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576782649; cv=none; d=google.com; s=arc-20160816; b=rCLzo07Lrdd1CdvldvBCc9CshcrCz1sj6OguBJ+2WoPf3MS0Rsy1JsNPunK9cPKhaF VOL04lSEYS+22LtIxMKGXHA8PtU6byIxu23BNI5mhbDqbbrpI8b8v9aNIFfo5Czb0sXx u13qa23s2Biyb4arM4W7nQ18/NsTaSXzWKt+oQWZTsnyJpRS2c/165xIMjVsyITUm1jm NCyWAmNIVtl34iL9pUEwN6Up8ijENgb5i2U0WCZVkPMHgISktzrlz5BmwOYI8o0inbZh GJnGvyOaDMyYi9Oatm5AHIwMh8JXzJBdxEMqkfPqJCYe3Yf05WSc/X1ix1NA1sEAr0YS +EuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=wljMrarODRYPSu5lMEZZ1EMbmwFk+rQNbguwczRXoXI=; b=rHJwWM/ty93jRusj+1o+rB8V1mCoX9xvFWECrTVu5CG4GjC7HbvcOYiE9zsRM8hf1z VirBkd6IesYjVSwRBhfvuzVQcjRPqaCSufx8XmCzRmH+kw+IppxGDhv0jiOmz1ao3GP8 jx6fOWeB1t1coTyLzF32YUfniwJ85ELsEClQ5hvZox8MKnT4sIzZn0tUWJhoB916uZ+r WiCgwxe3uNvTtQeTmymNnNw3BwptdbL+67gm5+2eF9ynI+tgooth11rE9zVwVsgnoDmb M2kuM/lpfeDz887RbJIMPu9A0So7q8OEjexMODur3dGK54oNnf0E1vRypRmiZbQgQN3H hS/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yarlFfTF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o5si1317719otl.185.2019.12.19.11.10.37; Thu, 19 Dec 2019 11:10:49 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yarlFfTF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728319AbfLSSkB (ORCPT + 99 others); Thu, 19 Dec 2019 13:40:01 -0500 Received: from mail.kernel.org ([198.145.29.99]:58476 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728304AbfLSSjz (ORCPT ); Thu, 19 Dec 2019 13:39:55 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 38252222C2; Thu, 19 Dec 2019 18:39:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576780794; bh=WQzeEBnJGmvKkMu+U3O5j7OyqmaBwhe4XyODa9qnvZQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yarlFfTF4ygeVc/Z8Cu50uu3hhbDbhSq15w8RKXrBIxPT4r0JVnzWaWVNj6NfJ3La 0Rh+2i/sAL0iyvkUmVn0ZFq2WBoJbRSe7Lwlnroo82SbtFgVnQDhdsEJDIVST8i9/B PmPwycRhhd+hNIQ9rAz8wlzw6Z3/IfhAVg8H79XU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dmitry Monakhov , Jan Kara Subject: [PATCH 4.4 121/162] quota: Check that quota is not dirty before release Date: Thu, 19 Dec 2019 19:33:49 +0100 Message-Id: <20191219183215.133351362@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191219183150.477687052@linuxfoundation.org> References: <20191219183150.477687052@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dmitry Monakhov commit df4bb5d128e2c44848aeb36b7ceceba3ac85080d upstream. There is a race window where quota was redirted once we drop dq_list_lock inside dqput(), but before we grab dquot->dq_lock inside dquot_release() TASK1 TASK2 (chowner) ->dqput() we_slept: spin_lock(&dq_list_lock) if (dquot_dirty(dquot)) { spin_unlock(&dq_list_lock); dquot->dq_sb->dq_op->write_dquot(dquot); goto we_slept if (test_bit(DQ_ACTIVE_B, &dquot->dq_flags)) { spin_unlock(&dq_list_lock); dquot->dq_sb->dq_op->release_dquot(dquot); dqget() mark_dquot_dirty() dqput() goto we_slept; } So dquot dirty quota will be released by TASK1, but on next we_sleept loop we detect this and call ->write_dquot() for it. XFSTEST: https://github.com/dmonakhov/xfstests/commit/440a80d4cbb39e9234df4d7240aee1d551c36107 Link: https://lore.kernel.org/r/20191031103920.3919-2-dmonakhov@openvz.org CC: stable@vger.kernel.org Signed-off-by: Dmitry Monakhov Signed-off-by: Jan Kara Signed-off-by: Greg Kroah-Hartman --- fs/ocfs2/quota_global.c | 2 +- fs/quota/dquot.c | 2 +- include/linux/quotaops.h | 10 ++++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) --- a/fs/ocfs2/quota_global.c +++ b/fs/ocfs2/quota_global.c @@ -714,7 +714,7 @@ static int ocfs2_release_dquot(struct dq mutex_lock(&dquot->dq_lock); /* Check whether we are not racing with some other dqget() */ - if (atomic_read(&dquot->dq_count) > 1) + if (dquot_is_busy(dquot)) goto out; /* Running from downconvert thread? Postpone quota processing to wq */ if (current == osb->dc_task) { --- a/fs/quota/dquot.c +++ b/fs/quota/dquot.c @@ -472,7 +472,7 @@ int dquot_release(struct dquot *dquot) mutex_lock(&dquot->dq_lock); /* Check whether we are not racing with some other dqget() */ - if (atomic_read(&dquot->dq_count) > 1) + if (dquot_is_busy(dquot)) goto out_dqlock; mutex_lock(&dqopt->dqio_mutex); if (dqopt->ops[dquot->dq_id.type]->release_dqblk) { --- a/include/linux/quotaops.h +++ b/include/linux/quotaops.h @@ -54,6 +54,16 @@ static inline struct dquot *dqgrab(struc atomic_inc(&dquot->dq_count); return dquot; } + +static inline bool dquot_is_busy(struct dquot *dquot) +{ + if (test_bit(DQ_MOD_B, &dquot->dq_flags)) + return true; + if (atomic_read(&dquot->dq_count) > 1) + return true; + return false; +} + void dqput(struct dquot *dquot); int dquot_scan_active(struct super_block *sb, int (*fn)(struct dquot *dquot, unsigned long priv),