Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3219098imu; Sat, 24 Nov 2018 00:22:59 -0800 (PST) X-Google-Smtp-Source: AFSGD/WcWps0HFsyPvGvSLmGYkBNHjGfLC2j0xPtRLK+xHLf3jwM9PEly15aefddSxTweS/shhgv X-Received: by 2002:a63:7044:: with SMTP id a4mr16766295pgn.359.1543047779572; Sat, 24 Nov 2018 00:22:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543047779; cv=none; d=google.com; s=arc-20160816; b=kfp8KdiPi18C1t/p+LQZgFasZisaq+30643GsG5A7lv0FNpZP+i9oYuAIfisO3jkow Vlk9vCsmw1R/Hz7Y5kHi1iqmKLy6b+fqpgIWX7+VYrqaxuwRMmKQEqpYQ0EwAmHqPBY7 Lx116JY9Km36Kr2XoF2MC4D5+8jPtiwEH+v8/PB3c0b3vxesgX+hq2CfjlZdvUm6CJmW 1gtvmT97hMJtI0dw7tmU0kSQBaVqCdlUUDTb+/QXZTmbt35wc7cVyC8oEDAqjzwJKDl3 WUND0PYObAn9SItwCrBjnUufI9IhpZ7rdQu0XBZpgBSHpaDqXnvPCReYeUetp3Ly3S57 4d/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=icHIWunFbiRtJzIRcC0uS1zytXEq3qTYVVTD+GKmUy0=; b=fnZ6UcCcvTLL0Wr1vuBjlMYSbVtWct1P8gKggN7pBv7ERvypWqSHfZ8GnFZCvZp0gp tkhbzr/rSBZwFmSOdzZj6XJsLW3LM0t5NB1eLV+DJgOjNiSWJhxqAOK7mO5DoPLQlvJd ce3ELNlcocvnMaNLZKAWm5ZvcLgiJOFnNCmYRbp/C7T1stMwEjsLkZuRbBF/xfciKspa JkAlJj/bnf5WNkI5falBiwLciQinnKStqGvmiISseGGwHx9dqZScCoZvQVckVU5XFZt2 pFJNAOcf3E9kBZfSs6J5+t158oGcIQF5wdXtYkA76eDaKnVwGzak7wGFFliYkFf2tqSY 5uGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=TQlqsjtx; 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 e35si25855824pgb.548.2018.11.24.00.22.45; Sat, 24 Nov 2018 00:22:59 -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=@163.com header.s=s110527 header.b=TQlqsjtx; 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 S2409259AbeKWUyz (ORCPT + 99 others); Fri, 23 Nov 2018 15:54:55 -0500 Received: from m12-11.163.com ([220.181.12.11]:50115 "EHLO m12-11.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2393883AbeKWUyy (ORCPT ); Fri, 23 Nov 2018 15:54:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=icHIWunFbiRtJzIRcC 0uS1zytXEq3qTYVVTD+GKmUy0=; b=TQlqsjtxeKjYAoQxQEFGvnC4HVZlSNwam5 /9BdzFLK+IxiJiP1AWY4gI64CwRt6sk24sDle5FbatJ25sEWC0fsqXgX19MC9CNm J3hMJmjnr/m1n5RVMxqQ0Skz8bYMx1pOU+AAYZCpC0I4Gi2use9+PZEj4FYV21to I8GiXAKgk= Received: from bp.localdomain (unknown [106.120.213.96]) by smtp7 (Coremail) with SMTP id C8CowACnVJYG0vdbwcgtBg--.58364S3; Fri, 23 Nov 2018 18:10:18 +0800 (CST) From: Pan Bian To: Chris Mason , Josef Bacik , David Sterba Cc: Wang Shilong , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Pan Bian Subject: [PATCH] btrfs: relocation: set trans to be NULL after free Date: Fri, 23 Nov 2018 18:10:15 +0800 Message-Id: <1542967815-14547-1-git-send-email-bianpan2016@163.com> X-Mailer: git-send-email 2.7.4 X-CM-TRANSID: C8CowACnVJYG0vdbwcgtBg--.58364S3 X-Coremail-Antispam: 1Uf129KBjvdXoWrurWUtr13Zw45AFWUAryUAwb_yoWDWrX_WF 4xtrs2ywn5Xry3CFn0krs5JFZak34FgF1DWwn5t3yakay3ArZ0qr4DXws3Xrs8W398GryY qrZ5Zw18C34fWjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IUnsXo7UUUUU== X-Originating-IP: [106.120.213.96] X-CM-SenderInfo: held01tdqsiiqw6rljoofrz/1tbiDhMIclXlpkg5VwABsW Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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") Signed-off-by: Pan Bian --- fs/btrfs/relocation.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 924116f..a3f75b8 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -3959,6 +3959,7 @@ static noinline_for_stack int relocate_block_group(struct reloc_control *rc) restart: if (update_backref_cache(trans, &rc->backref_cache)) { btrfs_end_transaction(trans); + trans = NULL; continue; } -- 2.7.4