From patchwork Tue Mar 24 13:11:05 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: 228895 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=-6.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, 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 4A445C2BAEE for ; Tue, 24 Mar 2020 13:13:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 24C8520A8B for ; Tue, 24 Mar 2020 13:13:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1585055635; bh=FDq4mdadFeIRuQ2rR1zm0FRF7qhn70FJTMxqAXXxdBo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=v8i2XF+0wB6lD3TNSsrnE6J+VvDZ7pgI1TuIqn+KMBHyoNWJKqn55raXUzW0HosWp 9PUjZCHKQni6LL1XPryNgQ8H/ma+ykTLe/xMCS9ymIF0LUOivKtR+8PanwelCUMuBx wqaE+kz7iuS3XhKxHGdQYogGcHwEjJuW1BokbPwA= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727354AbgCXNNy (ORCPT ); Tue, 24 Mar 2020 09:13:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:60232 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727940AbgCXNNv (ORCPT ); Tue, 24 Mar 2020 09:13:51 -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 8DCD3208D5; Tue, 24 Mar 2020 13:13:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1585055631; bh=FDq4mdadFeIRuQ2rR1zm0FRF7qhn70FJTMxqAXXxdBo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pyeCsoBCDTLhBHto4jS+/QJd43okMw4l0OULN3gIaJ+fmplqS4Pf4Hm58A96GTdH5 xAcXGTWLV/yRljlrH6e8nX78T95PIs89AZMqaqV8MxCAVfP/aOqWCjPIVpCnuHN/Cf tbMPTdwO4oCyNL1F1+00q2hylhhMm9VCVEF4/OlA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Filipe Manana , David Sterba Subject: [PATCH 4.19 44/65] btrfs: fix log context list corruption after rename whiteout error Date: Tue, 24 Mar 2020 14:11:05 +0100 Message-Id: <20200324130802.605551570@linuxfoundation.org> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200324130756.679112147@linuxfoundation.org> References: <20200324130756.679112147@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Filipe Manana commit 236ebc20d9afc5e9ff52f3cf3f365a91583aac10 upstream. During a rename whiteout, if btrfs_whiteout_for_rename() returns an error we can end up returning from btrfs_rename() with the log context object still in the root's log context list - this happens if 'sync_log' was set to true before we called btrfs_whiteout_for_rename() and it is dangerous because we end up with a corrupt linked list (root->log_ctxs) as the log context object was allocated on the stack. After btrfs_rename() returns, any task that is running btrfs_sync_log() concurrently can end up crashing because that linked list is traversed by btrfs_sync_log() (through btrfs_remove_all_log_ctxs()). That results in the same issue that commit e6c617102c7e4 ("Btrfs: fix log context list corruption after rename exchange operation") fixed. Fixes: d4682ba03ef618 ("Btrfs: sync log after logging new name") CC: stable@vger.kernel.org # 4.19+ Signed-off-by: Filipe Manana Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/inode.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -10015,6 +10015,10 @@ out_fail: ret = btrfs_sync_log(trans, BTRFS_I(old_inode)->root, &ctx); if (ret) commit_transaction = true; + } else if (sync_log) { + mutex_lock(&root->log_mutex); + list_del(&ctx.list); + mutex_unlock(&root->log_mutex); } if (commit_transaction) { ret = btrfs_commit_transaction(trans);