* [PATCH] btrfs: fix memory leak of fs_devices in degraded seed device path
@ 2025-12-10 13:28 Deepanshu Kartikey
2025-12-11 18:48 ` David Sterba
2025-12-11 23:55 ` Qu Wenruo
0 siblings, 2 replies; 3+ messages in thread
From: Deepanshu Kartikey @ 2025-12-10 13:28 UTC (permalink / raw)
To: clm, dsterba, miaox
Cc: linux-btrfs, linux-kernel, Deepanshu Kartikey,
syzbot+eadd98df8bceb15d7fed
In open_seed_devices(), when find_fsid() fails and we're in DEGRADED
mode, a new fs_devices is allocated via alloc_fs_devices() but is never
added to the seed_list before returning. This contrasts with the normal
path where fs_devices is properly added via list_add().
If any error occurs later in read_one_dev() or btrfs_read_chunk_tree(),
the cleanup code iterates seed_list to free seed devices, but this
orphaned fs_devices is never found and never freed, causing a memory
leak. Any devices allocated via add_missing_dev() and attached to this
fs_devices are also leaked.
Fix this by adding the newly allocated fs_devices to seed_list in the
degraded path, consistent with the normal path.
Fixes: 5f37583569442 ("Btrfs: move the missing device to its own fs device list")
Reported-by: syzbot+eadd98df8bceb15d7fed@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=eadd98df8bceb15d7fed
Tested-by: syzbot+eadd98df8bceb15d7fed@syzkaller.appspotmail.com
Signed-off-by: Deepanshu Kartikey <kartikey406@gmail.com>
---
fs/btrfs/volumes.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index ae1742a35e76..13c514684cfb 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -7128,6 +7128,7 @@ static struct btrfs_fs_devices *open_seed_devices(struct btrfs_fs_info *fs_info,
fs_devices->seeding = true;
fs_devices->opened = 1;
+ list_add(&fs_devices->seed_list, &fs_info->fs_devices->seed_list);
return fs_devices;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] btrfs: fix memory leak of fs_devices in degraded seed device path
2025-12-10 13:28 [PATCH] btrfs: fix memory leak of fs_devices in degraded seed device path Deepanshu Kartikey
@ 2025-12-11 18:48 ` David Sterba
2025-12-11 23:55 ` Qu Wenruo
1 sibling, 0 replies; 3+ messages in thread
From: David Sterba @ 2025-12-11 18:48 UTC (permalink / raw)
To: Deepanshu Kartikey
Cc: clm, dsterba, miaox, linux-btrfs, linux-kernel,
syzbot+eadd98df8bceb15d7fed
On Wed, Dec 10, 2025 at 06:58:07PM +0530, Deepanshu Kartikey wrote:
> In open_seed_devices(), when find_fsid() fails and we're in DEGRADED
> mode, a new fs_devices is allocated via alloc_fs_devices() but is never
> added to the seed_list before returning. This contrasts with the normal
> path where fs_devices is properly added via list_add().
>
> If any error occurs later in read_one_dev() or btrfs_read_chunk_tree(),
> the cleanup code iterates seed_list to free seed devices, but this
> orphaned fs_devices is never found and never freed, causing a memory
> leak. Any devices allocated via add_missing_dev() and attached to this
> fs_devices are also leaked.
>
> Fix this by adding the newly allocated fs_devices to seed_list in the
> degraded path, consistent with the normal path.
>
> Fixes: 5f37583569442 ("Btrfs: move the missing device to its own fs device list")
> Reported-by: syzbot+eadd98df8bceb15d7fed@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=eadd98df8bceb15d7fed
> Tested-by: syzbot+eadd98df8bceb15d7fed@syzkaller.appspotmail.com
> Signed-off-by: Deepanshu Kartikey <kartikey406@gmail.com>
Reviewed-by: David Sterba <dsterba@suse.com>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] btrfs: fix memory leak of fs_devices in degraded seed device path
2025-12-10 13:28 [PATCH] btrfs: fix memory leak of fs_devices in degraded seed device path Deepanshu Kartikey
2025-12-11 18:48 ` David Sterba
@ 2025-12-11 23:55 ` Qu Wenruo
1 sibling, 0 replies; 3+ messages in thread
From: Qu Wenruo @ 2025-12-11 23:55 UTC (permalink / raw)
To: Deepanshu Kartikey, clm, dsterba, miaox
Cc: linux-btrfs, linux-kernel, syzbot+eadd98df8bceb15d7fed
在 2025/12/10 23:58, Deepanshu Kartikey 写道:
> In open_seed_devices(), when find_fsid() fails and we're in DEGRADED
> mode, a new fs_devices is allocated via alloc_fs_devices() but is never
> added to the seed_list before returning. This contrasts with the normal
> path where fs_devices is properly added via list_add().
>
> If any error occurs later in read_one_dev() or btrfs_read_chunk_tree(),
> the cleanup code iterates seed_list to free seed devices, but this
> orphaned fs_devices is never found and never freed, causing a memory
> leak. Any devices allocated via add_missing_dev() and attached to this
> fs_devices are also leaked.
>
> Fix this by adding the newly allocated fs_devices to seed_list in the
> degraded path, consistent with the normal path.
>
> Fixes: 5f37583569442 ("Btrfs: move the missing device to its own fs device list")
> Reported-by: syzbot+eadd98df8bceb15d7fed@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=eadd98df8bceb15d7fed
> Tested-by: syzbot+eadd98df8bceb15d7fed@syzkaller.appspotmail.com
> Signed-off-by: Deepanshu Kartikey <kartikey406@gmail.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Thanks,
Qu
> ---
> fs/btrfs/volumes.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index ae1742a35e76..13c514684cfb 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -7128,6 +7128,7 @@ static struct btrfs_fs_devices *open_seed_devices(struct btrfs_fs_info *fs_info,
>
> fs_devices->seeding = true;
> fs_devices->opened = 1;
> + list_add(&fs_devices->seed_list, &fs_info->fs_devices->seed_list);
> return fs_devices;
> }
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-12-11 23:55 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-10 13:28 [PATCH] btrfs: fix memory leak of fs_devices in degraded seed device path Deepanshu Kartikey
2025-12-11 18:48 ` David Sterba
2025-12-11 23:55 ` Qu Wenruo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox