Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3852821ybz; Mon, 20 Apr 2020 10:37:31 -0700 (PDT) X-Google-Smtp-Source: APiQypIYOGFMGt2Z3qhTrxzfXrxk8+Jm26B/2K1SrVDyzcmLuVcsPaea716gD6/DrcCNJoNZys8k X-Received: by 2002:a05:6402:22ba:: with SMTP id cx26mr11959155edb.198.1587404251271; Mon, 20 Apr 2020 10:37:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587404251; cv=none; d=google.com; s=arc-20160816; b=i4oGzvnZHWflKjKbKayGg3o0rm2wbu6HMcVTpen6hiQb5+XLbQvNZX2AWgO6pxdEuq GXlWniGcwxrSypnGh6tzIXEuOVc8pU3lz2Ef1ZrIgmh+LLrRRAbYUug2RtgoWNsdjMVb P9eRS3eOE2qgs+JHB+tBxfvKEyAVdvK4dIqF/dAguuUTeUNL6vQ4zb/nXjlZdl+++a10 bGtFMfgXRPe259gH97qFF7g+RxbAQLvNLJyBLFXPoDiy467zgFrL9VkfxqlXFCuDloRe xaEbGvvNeRafyxEvvCP2q/7DMUnxTkPdtHqUHERi4v/Lo8yNhnOAYp4PQF0v8EWN3UNi GPGQ== 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:cc:to:subject :message-id:date:from:reply-to:in-reply-to:references:mime-version :dkim-signature; bh=5n0ZpPXe9GxzwLdXMf5YrkeqFKsYHpJZC/15y27E0lk=; b=pHheF4l3pNOMVzCHvpuoYwgNb6ZP/yQ/LmpnFqSHg/h4TPRu3pxwkZ63lyJHDseGns 1wncdOzx5fHAw9LM6UOeIOyubL3/+IeU1UpuU7o0sk3FrLHFORSmzcV7JJMckFvFv/HV rztgDYV2QIdsXNHnHZW4RBwqCrmWIwPx2oZYgKTWAXupYmOjFef5pNa+NjxezThHq2Ru W+O0ktD6jIFtvBYP3hcyIlyyymUN4VgLX4PdFjz0ABXosH1sJ4FF42/k3MGAsGOBsMQk ZovikDfLjuiKWSmFQP+LairC1gh3En3agyIy70Xw+CxuXyofbbFxg3O8Lk6Nq+grDJq6 f0rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=BolIF1k9; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id pv24si957692ejb.244.2020.04.20.10.37.08; Mon, 20 Apr 2020 10:37:31 -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=@gmail.com header.s=20161025 header.b=BolIF1k9; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726798AbgDTRgI (ORCPT + 99 others); Mon, 20 Apr 2020 13:36:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1725774AbgDTRgI (ORCPT ); Mon, 20 Apr 2020 13:36:08 -0400 Received: from mail-vs1-xe42.google.com (mail-vs1-xe42.google.com [IPv6:2607:f8b0:4864:20::e42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2F5DC061A0C; Mon, 20 Apr 2020 10:36:07 -0700 (PDT) Received: by mail-vs1-xe42.google.com with SMTP id m24so3520470vsq.10; Mon, 20 Apr 2020 10:36:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:reply-to:from:date:message-id :subject:to:cc:content-transfer-encoding; bh=5n0ZpPXe9GxzwLdXMf5YrkeqFKsYHpJZC/15y27E0lk=; b=BolIF1k99WxEtleR/CBlGdyEsqXp4swwaSKBcOQaUgaoJUNm0ZUQm8WA88c3s/GZ5B lAi65pA+eL4ky0bHhoLXE8dP+PugBA9in2FEmJL6hyUAPunN23n+A/0tCjZLsvw+uJjB zfV3TBNOelZIlrxq1qlG+L91XVSXROfnTE9MRBMqFKnN+Ie0ZCP+o+Pp0X2YV2yIhIWO o1z/2bbFFw5m4Ev2/Eb0vxuIXFU3SEw1jxAf1RwIzhJcn0R+EEggMt4PYnNhQyEjx67q eAH4SrGvbk2xiX1wNT/d5XUEp/lZpBpB3uLNWGdN8bt/o04VKkyTPnsXCSfoXLijOqsZ 4F2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:reply-to :from:date:message-id:subject:to:cc:content-transfer-encoding; bh=5n0ZpPXe9GxzwLdXMf5YrkeqFKsYHpJZC/15y27E0lk=; b=TepofHGogsC8jBy1R8pN6im9mj/2npxvkwuf8pc6tYHndOvQRKqT8lQb/07eTQzZ6O H7dW8OGOPBJaIgp1HFrbXNa9xpUnySondGzBj+/K6PMs53OyzkDuWIpdHMwWb5OxN32f 4LF7MOwdz5lvcMhwueexKF10a4Hh5YktMn7I2a7mh6nUa1S27oO3FIcYgw8Yqr8Ri8Ca 7Ze04JVuR8MF45Yzled6LigiyOVy0HzvO57f7poIa9FPqd4aHfB+fX9BejJ+LkvYedA6 abSKWvc2wpHnLm9LxhRw5vu6pMUPqqzEv5TDqOZ91/8BvvbxIab3F2TNMt039s2mEXY5 ILqA== X-Gm-Message-State: AGi0PuaFgjCQ33QQBXjwilBpzl4WS/pGisDTeYYfCRX4Uje5hY9NF0gE 51u5QGeAiCuFNJ2qKwcrm7gMGCicA/zJR6bGPZI= X-Received: by 2002:a67:f4ce:: with SMTP id s14mr10626206vsn.99.1587404167159; Mon, 20 Apr 2020 10:36:07 -0700 (PDT) MIME-Version: 1.0 References: <1587361180-83334-1-git-send-email-xiyuyang19@fudan.edu.cn> In-Reply-To: Reply-To: fdmanana@gmail.com From: Filipe Manana Date: Mon, 20 Apr 2020 18:35:56 +0100 Message-ID: Subject: Re: [PATCH] btrfs: Fix refcnt leak in btrfs_recover_relocation To: Xiyu Yang Cc: Chris Mason , Josef Bacik , David Sterba , Jeff Mahoney , linux-btrfs , linux-kernel@vger.kernel.org, yuanxzhang@fudan.edu.cn, kjlu@umn.edu, Xin Tan Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 20, 2020 at 6:34 PM Filipe Manana wrote: > > On Mon, Apr 20, 2020 at 6:50 AM Xiyu Yang wrote= : > > > > btrfs_recover_relocation() invokes btrfs_join_transaction(), which join= s > > a btrfs_trans_handle object into transactions and returns a reference o= f > > it with increased refcount to "trans". > > > > When btrfs_recover_relocation() returns, "trans" becomes invalid, so th= e > > 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 refcn= t > > 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 > > Reviewed-by: Filipe Manana > > Looks good, thanks. Btw, the subject could be more clear. Instead of "btrfs: Fix refcnt leak in btrfs_recover_relocation" something like "btrfs: fix transaction leak in ..." David can probably fixup that when he picks the patch. Thanks. > > > --- > > 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 *r= oot) > > if (IS_ERR(fs_root)) { > > err =3D PTR_ERR(fs_root); > > list_add_tail(&reloc_root->root_list, &reloc_ro= ots); > > + btrfs_end_transaction(trans); > > goto out_free; > > } > > > > -- > > 2.7.4 > > > > > -- > Filipe David Manana, > > =E2=80=9CWhether you think you can, or you think you can't =E2=80=94 you'= re right.=E2=80=9D --=20 Filipe David Manana, =E2=80=9CWhether you think you can, or you think you can't =E2=80=94 you're= right.=E2=80=9D