Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp579980img; Fri, 22 Mar 2019 04:27:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqw/2Z7tKX/8HjgXQ4HJGt9Rr+tNDjmxijybgrltaaGuCPxx7eBxyoqf+SigSyVDLOdHWCpR X-Received: by 2002:a63:4e5b:: with SMTP id o27mr8492668pgl.204.1553254078622; Fri, 22 Mar 2019 04:27:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553254078; cv=none; d=google.com; s=arc-20160816; b=eS6ERldnkNxIme/QPiVP38LTZs3PsyCDD/zSIi/huEZ5Yrxp/UJddb0sBcwCwKzeQ8 cwuvZBGYHOx2g8yyh1O7aK9tXTEKniziZ+GVK99i7dcBih8eCbNcGa76HkV4qbMjJaYa 1Lycv+iWkwOArzIusmpjLf1c6oA9SsnrOaz4Vwpm6m7pe90Lz4D+vMCOaAL0ep1KnrwJ ap56JXHBf3sWyKqD7a+tG+wVeyt5KQ9SQ5HSKuN56Z5pM6/jDZ2YtNFLax0nkdL7goet 93t2BHw/l+MYw1GeyjfFrUb7YxehH/2BUeGIBwKrGxjvueWBgadC7Hk4UuxLevn1LlZg bM6w== 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=EOl6VuZAEDxpSR7tbf6hXlma4XPoA4cqT4NCVn+1PHY=; b=T8FqwWpSk2jb/x3xtQ1ecwSmeViAYkBLxbDHTtuiZV7zwkxy7Wt5LVtr4S9EGGEgdX dXiO/u79EyBmFXyPwfFFeF5Rd2nIYGEq1fiEWuZp08rBTx0Fk6llxnL211h04LufEsp3 N+WszzRV0zw7c7dEsP8KohryoLAiZJhw4+wTKAeNx7QCfQWol1YXc+EnVClNhHMSLSq2 h170BXmYiAeKt6oAGUGutwn6QRnBpsbyJnRt/F9aGuU1wamgomeFPue1Gcbkyh5tWAvS Pk7JW26gKmGE/usxC4y4Rw/8YkYG3I0hO1tTqM37rAZWT/VV1d/QcZcgfOAVjPjqfulT pB3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="PjH44T/t"; 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 t23si6390361pgv.63.2019.03.22.04.27.41; Fri, 22 Mar 2019 04:27:58 -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="PjH44T/t"; 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 S1729369AbfCVLZ7 (ORCPT + 99 others); Fri, 22 Mar 2019 07:25:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:53568 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727904AbfCVLZ6 (ORCPT ); Fri, 22 Mar 2019 07:25:58 -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 DE404218B0; Fri, 22 Mar 2019 11:25:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553253957; bh=BIwZQAgvAnuHma6nyVqHMimjZ6ojK2I8nmW2OjQ5CW4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PjH44T/t+nv/ekxG1Yk4s2BGEjOvL1sinlmEtc2EBcuh5pvMBOSVQr7gU8kKYgtuX 4i0lF3Xj9ULxgwrxkS90bEolxtht9aTwd3kPpMeBRAKp3s+PFraK5MiNQd10UdKEbo u//Imt/oSl1EsKYztddAm43isl9Y60iJJwEnMHmY= 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 3.18 123/134] jbd2: clear dirty flag when revoking a buffer from an older transaction Date: Fri, 22 Mar 2019 12:15:36 +0100 Message-Id: <20190322111219.326191364@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322111210.465931067@linuxfoundation.org> References: <20190322111210.465931067@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 3.18-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 @@ -1473,14 +1473,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