Re: [PATCH] btrfs: fix extent changeset leak in encoded writes

From: David Sterba

Date: Fri Jul 31 2026 - 11:14:21 EST


On Fri, Jul 31, 2026 at 12:56:20PM +0100, Filipe Manana wrote:
> On Fri, Jul 31, 2026 at 12:52 PM Breno Leitao <leitao@xxxxxxxxxx> wrote:
> >
> > Investigating some machines with kmemleak, I am constantly seeing
> > the following memory leak that seems real.
> >
> > kmemleak: unreferenced object 0xffff88869f7d01c0 (size 64):
> > kmemleak: comm "btrfs", pid 1613416, jiffies 4316358595
> > kmemleak: backtrace (crc ab59040a):
> > kmemleak: __kmalloc_cache_noprof
> > kmemleak: qgroup_reserve_data
> > kmemleak: btrfs_qgroup_reserve_data
> > kmemleak: btrfs_do_encoded_write
> > kmemleak: btrfs_do_write_iter
> > kmemleak: btrfs_ioctl_encoded_write
> > kmemleak: btrfs_ioctl
> > kmemleak: ... and 2 more object(s) with the same backtrace
> >
> > and
> >
> > kmemleak: unreferenced object 0xffff88830d94edc0 (size 64):
> > kmemleak: comm "btrfs", pid 1613416, jiffies 4316358595
> > <snip>
> > kmemleak: ... and 2 more object(s) with the same backtrace
> >
> > Looking at the code, it seems we don't free data_reserved, but
> > we should (!?). I was able to come up with a xfstest test that exposes
> > the kmemleak above:
> >
> > https://github.com/leitao/xfstest/commit/81c83a3fbb20b4ad695055ede7fcb73d3ffa2e52
> >
> > Free the changeset on the way out, as every other caller of
> > btrfs_qgroup_reserve_data() already does.
> >
> > Fixes: 7c0c7269f7b5 ("btrfs: add BTRFS_IOC_ENCODED_WRITE")
> > Cc: stable@xxxxxxxxxxxxxxx
> > Signed-off-by: Breno Leitao <leitao@xxxxxxxxxx>
>
> This is already fixed here:
>
> https://lore.kernel.org/linux-btrfs/20260727115352.12622-1-dmantipov@xxxxxxxxx/

Will be sent next week.