Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp655339img; Fri, 22 Mar 2019 06:02:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqzHaOxohVLR5oVgGb+6qnQPJGwedpBFJglf32Jv1jkehw/FzOKWQd5LXjxhufdK1ljtd4Ej X-Received: by 2002:a63:614c:: with SMTP id v73mr8906495pgb.395.1553259752412; Fri, 22 Mar 2019 06:02:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553259752; cv=none; d=google.com; s=arc-20160816; b=oi6yyjeyrrRmJmYTSWqX5445JlQFnHreSFkUrLt7G0d1RKT0d06rpmEWjR0YTu901j 9RKFj76wbfU2oYCxrBXxsvBAGcyPSbZgiNdJGaTyYUowKQGjrF03wc97lXS/HUzzN0Zs uQznW+vW6ErWoF1KWNSHBH+UO2ucwuio2SQzJXHJKxNRruY5jvKJc9qjO4Dw2pQJC+3J 7WAQYUahf6hMP1dqNLo9L02LnFnFHrOGhsHXxWrbmKW1AsABOmeI2r0KGIGCB80f1SiK rEVxwQ8C95C81AYPUh68U6GkiAoakuzgidSjwCcw2vDtr6bAf/40hLOpLRnTzgy9VvQZ aVcg== 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=iPAKILfmW6d2L16F2HrdtKoBvKvZLyjxrwcPcbMZhQY=; b=W0XEU0CGUt9tPRRzA/SsnJXPnsQPlh7NMfdzRhkNftMOpEoaJrhZcM2PYfd+q2udV7 0K+G4lv+QI8/V5QUUY22upjfxbr2PlOs1FhjSkYcxT1XfAVr5Og+SJu2ckTlYQYCxmmC QOYvHv3dT8uRIPVRvdocyJY1/xcYQ5+ZCM3zpUa3nU/SyEo7FFLTJciz7w6HUnxpHHep Xtsf3gw6Yhw8m8uuV9qRUyOIM7TAyf1phsK5a91KyI0FzcAHzsVCTQz9CPQyOfQM2gxt bxlnGmvCrUhejiW2c2xK/1BLs6V5wxQeCrRPfd75OQMc+PtpkNnOF9k0zCX1rcB5j594 17qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=kmaECnyH; 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 z5si6423262pgb.415.2019.03.22.06.02.16; Fri, 22 Mar 2019 06:02:32 -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=kmaECnyH; 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 S1731798AbfCVNAZ (ORCPT + 99 others); Fri, 22 Mar 2019 09:00:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:47042 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731778AbfCVLoK (ORCPT ); Fri, 22 Mar 2019 07:44:10 -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 8B7722082C; Fri, 22 Mar 2019 11:44:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553255050; bh=bnElGUEyDqT7w21LibJwWQE3ork/EX6RXX5JdWdZ8pg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kmaECnyHz0ScX8AqjFcMC636VzUPWj1h/h0gN02xZhiBV5owHPqqhoy9mhJUgqT7X CXAMe4uYypZYLuqmVcwUy+p3Q2y2kVHa87N/Zu5q3Sn9thirU4nZij+na/yTmn+okT 9NeJqsWv+hmBq7rirOpnGofKmYHz/CieWjfyI9RE= 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.9 091/118] jbd2: clear dirty flag when revoking a buffer from an older transaction Date: Fri, 22 Mar 2019 12:16:03 +0100 Message-Id: <20190322111223.031212401@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322111215.873964544@linuxfoundation.org> References: <20190322111215.873964544@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.9-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 @@ -1568,14 +1568,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