Re: [PATCH] btrfs: Fix root reference leak in handle_indirect_tree_backref()

From: David Sterba

Date: Mon Sep 21 2026 - 08:41:22 EST


On Fri, Sep 18, 2026 at 12:13:42PM -0700, Boris Burkov wrote:
> On Wed, Sep 16, 2026 at 05:13:19PM +0000, Wentao Liang wrote:
> > handle_indirect_tree_backref() walks up the tree from @cur, storing the
> > reference returned by btrfs_get_fs_root() in lower->root when the top
> > of the searched path is reached, and dropping it once a node already in
> > the backref cache is found. If the walk instead reaches
> > BTRFS_MAX_LEVEL without hitting either of those two exits, the
> > reference is neither stored nor dropped and is leaked on return.
>
> Are you able to reproduce this bug? If so, can you include that
> information in the commit message.

A filesystem with a tree of maximum height consumes a lot of metadata
space and in practice it's difficult to create one. For completeness the
check could be there, we have other impossible condition checks
elsewhere too.