Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8100154imu; Tue, 4 Dec 2018 03:01:16 -0800 (PST) X-Google-Smtp-Source: AFSGD/XliIbtShce3V8KmcALFfAt6z0t3W4EIOhr2m6LOGnbto1J+sNZjNzK4n4ZG/DsyXwGjEVb X-Received: by 2002:a63:bc02:: with SMTP id q2mr16536047pge.116.1543921276744; Tue, 04 Dec 2018 03:01:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543921276; cv=none; d=google.com; s=arc-20160816; b=Dsxs45NB5qI4f9eNvuwv0qLeHeHOICMAmjFl4ATJcxKt9eC06f3RClAgOnK7mDjAOY KaqeRvkhdEYyUBZbHYhl5rOImmR1Ep0ApldBWo0fDryOEb5ggoIwAU4taLTt3U2az4ma Tow+p00AeD4OkzTWGd5+04/gF/dufP0LFBT1DoCJKnjUgRP4pjha6N2Tt5j50nUr+Yys PzbntFf4u0g3QhiJtORGa3OZeiFy5xgrgKI5VavppNATpgN9PJHw4I46aF2atp5lRKQl CLacZIOx2SSgjbe1lJ3oYNRzvxUixhFRCDQpVgqJ6Px5dTexU8RA2ii7Nza62okOv/er 9biQ== 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=TQgHayxZgryqsotuJLe9AiGwXwvovDzaH2tcR5m9i0Q=; b=cY3XI3e/yP0s+2YTxKOakKiI2uPmYL+bmPFRgmwLe+rcSzrR7xAY9V1NEeXI2eDfkz q97zuRPwwGlH9lCfG+l7Vpkif7J2KGhJExPAn+/5VPkxqtw6YqLeRCThiB+roqqSQRKF QF+Ls59GmpTWA0JPVB8qUu30zMjC/FGlsUDWO+GU2nlMwp26O4qVs6MWtdxBMIiegms8 yrJJvKT5ISutomqP3lDLAlgGc34e/8nEqEAA8UOBH7n2j5LoEbyKRIZn8v3Y3m+q7k7H s3v2goNCMSTq7G0el9n5844WkTbIMO2BYN7bekM9C2w6+uHHRGxUE6t0fCSeHv+VoC0r NCBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hu7K84Hd; 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 v25si14457925pgk.341.2018.12.04.03.01.00; Tue, 04 Dec 2018 03:01:16 -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=hu7K84Hd; 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 S1727191AbeLDK7s (ORCPT + 99 others); Tue, 4 Dec 2018 05:59:48 -0500 Received: from mail.kernel.org ([198.145.29.99]:44760 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727185AbeLDK7p (ORCPT ); Tue, 4 Dec 2018 05:59:45 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.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 0D4C52087F; Tue, 4 Dec 2018 10:59:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543921184; bh=FZlZSpNN0GhV+Cpypco6qSxAsNMs0ut3aXXbZjATTws=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hu7K84HdYlCvV2LwUFTfbl0+wYFaNHh2Erd+rNK2RhBuWGna8C/1tK6WaO4jNb+6E nIwbzQ+Jl5v+XQZlyOMvwrDhyZ35qVputmDDnxxMfjMCFYsdx7QyRJ5Rq8V4gbSK7P UDFWSi4c5mmYshKSerK+de+SmV6NWGuWCcw0KmNY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Qu Wenruo , Pan Bian , David Sterba Subject: [PATCH 4.19 078/139] btrfs: relocation: set trans to be NULL after ending transaction Date: Tue, 4 Dec 2018 11:49:19 +0100 Message-Id: <20181204103653.365230294@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181204103649.950154335@linuxfoundation.org> References: <20181204103649.950154335@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: Pan Bian commit 42a657f57628402c73237547f0134e083e2f6764 upstream. The function relocate_block_group calls btrfs_end_transaction to release trans when update_backref_cache returns 1, and then continues the loop body. If btrfs_block_rsv_refill fails this time, it will jump out the loop and the freed trans will be accessed. This may result in a use-after-free bug. The patch assigns NULL to trans after trans is released so that it will not be accessed. Fixes: 0647bf564f1 ("Btrfs: improve forever loop when doing balance relocation") CC: stable@vger.kernel.org # 4.4+ Reviewed-by: Qu Wenruo Signed-off-by: Pan Bian Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/relocation.c | 1 + 1 file changed, 1 insertion(+) --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -3963,6 +3963,7 @@ static noinline_for_stack int relocate_b restart: if (update_backref_cache(trans, &rc->backref_cache)) { btrfs_end_transaction(trans); + trans = NULL; continue; }