Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp613004img; Fri, 22 Mar 2019 05:09:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqzwga8xXpnAt2a9zjj7BxYakvTgpK0giarQ5z1i3Q12s7B2BUmqDsVl2ldQuY9uJ3VFHgxx X-Received: by 2002:a63:5622:: with SMTP id k34mr8591597pgb.123.1553256596778; Fri, 22 Mar 2019 05:09:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553256596; cv=none; d=google.com; s=arc-20160816; b=mwwhJ8fo1/CLA7/PPUEvSNs8VRHq0JDdNFB/CNySdibdCGSHINOJj74+niIjo2bNKm 2X49SLU4lUzp9e455xk8mH0DMe1DQSfkhGYN3X6EO8JEtG2L819ZI5gIGQbR1FQpe0cl e3J+wHaQAHh8a3c5dOQhjgS6W7R+6ilKtmS4Ou6+2Pzci70fxr8caYGv5iMfJ9luTXJM EYYxOiOj2CUBtT1xMW+2CPrzjrBt39FSZbKDqUOk+sEd+cp5YqQdmdL6nUb1ZCzETksz 1TbSSzxyCHXMHguWniCK5P3VwU/zpn3s8VQwPKA+X9ufeiyy9r2eTUDmmeQyPOu2s4gN WdyA== 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=hu4RhjNqBmeKLO5gXGZdcUrc9v7WZfGU+glgY/h2O9c=; b=Vb5O6n6va0p/SA3c58fDysP0poWi8whW0/zT0XRCcRR+RokltIzEi0Z/GF0apXWjYN N9QiGJwYYo4sG00El/uYpsdo00tiCiZV8YvHypkLRo7mY0VEdZi5ucCz86UgrKKFyOMv p9wB1Zz6ODGE5aC0VNKStt4tNZlMhF/NMdnP2biidrQmPsWtdxNknulbmtYQfrK07jRx FCLpdacg+9jL2cVLuPq0NUrGSLrneMhSpf7h+tB6/fd5g9eKvQ8eyKglrlES2TGKDmVn a3NiibWmRvhs/9WVosIenvcezinvRWfgnHUIx3fnVP55LrsLBr9j63dMPZeop19bphdK sKjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yUDo0kLs; 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 o1si6086795pfe.194.2019.03.22.05.09.41; Fri, 22 Mar 2019 05:09:56 -0700 (PDT) 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=yUDo0kLs; 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 S2389224AbfCVMIz (ORCPT + 99 others); Fri, 22 Mar 2019 08:08:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:47264 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733201AbfCVMIx (ORCPT ); Fri, 22 Mar 2019 08:08:53 -0400 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 B1686206C0; Fri, 22 Mar 2019 12:08:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553256532; bh=TXbfJ18+Ne8Csn2xQgXuJbwMKqsMfMhIe+cROlOivJo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yUDo0kLsgeZc20CpmXmAa2PVdELKICqEruRy1dWherBGXpq2hRV+Bhr4JzBpgNBLC vo7j+AeUMioj6EkvTDGA/Lyo+fW7SP+mqNE5wD5QI6JggMNLbfLU3LyUzKVwfk9Bd6 c1MYAtUsJd8M794ByF/4NF1XQr3fD13OCNOjZZR8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "zhangyi (F)" , Theodore Tso , Jan Kara Subject: [PATCH 4.19 217/280] jbd2: clear dirty flag when revoking a buffer from an older transaction Date: Fri, 22 Mar 2019 12:16:10 +0100 Message-Id: <20190322111334.157103317@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322111306.356185024@linuxfoundation.org> References: <20190322111306.356185024@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: zhangyi (F) commit 904cdbd41d749a476863a0ca41f6f396774f26e4 upstream. Now, we capture a data corruption problem on ext4 while we're truncating an extent index block. Imaging that if we are revoking a buffer which has been journaled by the committing transaction, the buffer's jbddirty flag will not be cleared in jbd2_journal_forget(), so the commit code will set the buffer dirty flag again after refile the buffer. fsx kjournald2 jbd2_journal_commit_transaction jbd2_journal_revoke commit phase 1~5... jbd2_journal_forget belongs to older transaction commit phase 6 jbddirty not clear __jbd2_journal_refile_buffer __jbd2_journal_unfile_buffer test_clear_buffer_jbddirty mark_buffer_dirty Finally, if the freed extent index block was allocated again as data block by some other files, it may corrupt the file data after writing cached pages later, such as during unmount time. (In general, clean_bdev_aliases() related helpers should be invoked after re-allocation to prevent the above corruption, but unfortunately we missed it when zeroout the head of extra extent blocks in ext4_ext_handle_unwritten_extents()). This patch mark buffer as freed and set j_next_transaction to the new transaction when it already belongs to the committing transaction in jbd2_journal_forget(), so that commit code knows it should clear dirty bits when it is done with the buffer. This problem can be reproduced by xfstests generic/455 easily with seeds (3246 3247 3248 3249). Signed-off-by: zhangyi (F) Signed-off-by: Theodore Ts'o Reviewed-by: Jan Kara Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- fs/jbd2/transaction.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) --- a/fs/jbd2/transaction.c +++ b/fs/jbd2/transaction.c @@ -1576,14 +1576,21 @@ int jbd2_journal_forget (handle_t *handl /* However, if the buffer is still owned by a prior * (committing) transaction, we can't drop it yet... */ JBUFFER_TRACE(jh, "belongs to older transaction"); - /* ... but we CAN drop it from the new transaction if we - * have also modified it since the original commit. */ + /* ... but we CAN drop it from the new transaction through + * marking the buffer as freed and set j_next_transaction to + * the new transaction, so that not only the commit code + * knows it should clear dirty bits when it is done with the + * buffer, but also the buffer can be checkpointed only + * after the new transaction commits. */ - if (jh->b_next_transaction) { - J_ASSERT(jh->b_next_transaction == transaction); + set_buffer_freed(bh); + + if (!jh->b_next_transaction) { spin_lock(&journal->j_list_lock); - jh->b_next_transaction = NULL; + jh->b_next_transaction = transaction; spin_unlock(&journal->j_list_lock); + } else { + J_ASSERT(jh->b_next_transaction == transaction); /* * only drop a reference if this transaction modified