Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3274158ybz; Sun, 19 Apr 2020 22:42:52 -0700 (PDT) X-Google-Smtp-Source: APiQypKGztqRY9iYeNlHCABSYl0hpm5aO5UyA02R5JUQPnfeZUuSjID3F91tUlRQqBti5aF9Qsfb X-Received: by 2002:a17:906:90cc:: with SMTP id v12mr14504164ejw.211.1587361372557; Sun, 19 Apr 2020 22:42:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587361372; cv=none; d=google.com; s=arc-20160816; b=ur7dxmf8sH+fUIARC28vDZEhQxrpCC0aewryjQybe4n+mpXyEK99coUCzH43Z1AJA6 8VfsuX1OK8bdVKu8+wE74/Uj27j68ebNIeD3tlDNhmDzfQRQARXH/8MPWFkB3Dv7As7L NZ9GQfzOHNVFzG8dYRDgH8T0nDOtdEX7JmJWe2jXLBt3KdJ/mqebzWSviw2OWaFCQiM3 MNQqZ10qYiIUGSCcydRnVPSlpXCP+6xeXqkPIULZuGtoGm5jrB04VSf+OdW+p9miJIs4 vCC+2PQ4qd+VdmNXPC79kg8Vo7gMExvEk78B27F9lakp06SPv0B+XQl1YQFaMW82Xg6M Qt8w== 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=DjbzqYNqeqnbjCD12TkNbwM+GA7agGlpqtiuflvqEeQ=; b=VKe3RuUPgTbJTvASiu27n2HngQ7MAgtUadWpEqiTGB8ympXQtOmEH5D+7EjJAtrLW2 0Zg0gebQEybXUo8x7mi3bQut0IOLk1y+YURJTOdJbzbSFhuUfh6NC73nHKQm4fONesNy CUGc7PDZOv95S+fG+7o/18YoaCmp29dYSSVCY/LKrp+ja4bY52IbzhaHghNawN/mEKMr LWkwPv1r6cbKRrlFECkZJL50q90hlD4fdktU0FOE4mc5INYOtZky66RW+h+HJUnbabqV /Gy+Ym7AvW5ZNwrrkKmdOb2y0OiqVXdQpwXf4poNTTTYe8oZ/AWKLEhbsLzTQTO9XJu2 KYtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fudan.edu.cn header.s=dkim header.b=kQyQgJig; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fudan.edu.cn Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w24si18466643ejn.277.2020.04.19.22.42.29; Sun, 19 Apr 2020 22:42:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@fudan.edu.cn header.s=dkim header.b=kQyQgJig; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fudan.edu.cn Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725991AbgDTFky (ORCPT + 99 others); Mon, 20 Apr 2020 01:40:54 -0400 Received: from mail.fudan.edu.cn ([202.120.224.10]:35491 "EHLO fudan.edu.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725865AbgDTFky (ORCPT ); Mon, 20 Apr 2020 01:40:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fudan.edu.cn; s=dkim; h=Received:From:To:Cc:Subject:Date: Message-Id; bh=DjbzqYNqeqnbjCD12TkNbwM+GA7agGlpqtiuflvqEeQ=; b=k QyQgJig8hKn5pXyORfGGMB5fbkIDU/UUr9OUc6iZFYW6poCBKP8a+pWLSG/fOyAb mUua/+BkruHG1HZE6h3rWG1wl5BUTY+BE5IVtTvL37K8RvoL3rSzx1/QKo+r2kIo p5Cp77xV8SyL/bq+w90f0op7nze1W9NBqWMfiyFqyY= Received: from localhost.localdomain (unknown [120.229.255.67]) by app1 (Coremail) with SMTP id XAUFCgBXSHW6NZ1evHYWAA--.63135S3; Mon, 20 Apr 2020 13:40:12 +0800 (CST) From: Xiyu Yang To: Chris Mason , Josef Bacik , David Sterba , Jeff Mahoney , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Cc: yuanxzhang@fudan.edu.cn, kjlu@umn.edu, Xiyu Yang , Xin Tan Subject: [PATCH] btrfs: Fix refcnt leak in btrfs_recover_relocation Date: Mon, 20 Apr 2020 13:39:39 +0800 Message-Id: <1587361180-83334-1-git-send-email-xiyuyang19@fudan.edu.cn> X-Mailer: git-send-email 2.7.4 X-CM-TRANSID: XAUFCgBXSHW6NZ1evHYWAA--.63135S3 X-Coremail-Antispam: 1UD129KBjvJXoW7tr4xKF1rKw4kKw4ruF48JFb_yoW8Gr4fpr 47Cw1Fgry5tw1kArsxKan5Cr1fGa1DWw18GrsYgws5Xws3J3WSya4jvwnrtry8tr1qqw4U XrsY9rW5Arn8C3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9Y14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26F4U JVW0owA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oV Cq3wAac4AC62xK8xCEY4vEwIxC4wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC 0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr 1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IE rcIFxwACI402YVCY1x02628vn2kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7x kEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E 67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCw CI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6Fyj6rWU JwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCT nIWIevJa73UjIFyTuYvjfUOlksUUUUU X-CM-SenderInfo: irzsiiysuqikmy6i3vldqovvfxof0/ Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org btrfs_recover_relocation() invokes btrfs_join_transaction(), which joins a btrfs_trans_handle object into transactions and returns a reference of it with increased refcount to "trans". When btrfs_recover_relocation() returns, "trans" becomes invalid, so the refcount should be decreased to keep refcount balanced. The reference counting issue happens in one exception handling path of btrfs_recover_relocation(). When read_fs_root() failed, the refcnt increased by btrfs_join_transaction() is not decreased, causing a refcnt leak. Fix this issue by calling btrfs_end_transaction() on this error path when read_fs_root() failed. Fixes: 79787eaab461 ("btrfs: replace many BUG_ONs with proper error handling") Signed-off-by: Xiyu Yang Signed-off-by: Xin Tan --- fs/btrfs/relocation.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 995d4b8b1cfd..46a451594c7a 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -4606,6 +4606,7 @@ int btrfs_recover_relocation(struct btrfs_root *root) if (IS_ERR(fs_root)) { err = PTR_ERR(fs_root); list_add_tail(&reloc_root->root_list, &reloc_roots); + btrfs_end_transaction(trans); goto out_free; } -- 2.7.4