Skip to content

Commit 0f66676

Browse files
deepanshu406opsiff
authored andcommitted
btrfs: fix memory leak of fs_devices in degraded seed device path
[ Upstream commit b57f2ddd28737db6ff0e9da8467f0ab9d707e997 ] 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: 5f37583 ("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 Reviewed-by: Qu Wenruo <wqu@suse.com> Signed-off-by: Deepanshu Kartikey <kartikey406@gmail.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com> Signed-off-by: Sasha Levin <sashal@kernel.org> (cherry picked from commit c0c0951b9cd4f4440f3d9f17a806122b045bf1f5) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
1 parent c94b15c commit 0f66676

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

fs/btrfs/volumes.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6966,6 +6966,7 @@ static struct btrfs_fs_devices *open_seed_devices(struct btrfs_fs_info *fs_info,
69666966

69676967
fs_devices->seeding = true;
69686968
fs_devices->opened = 1;
6969+
list_add(&fs_devices->seed_list, &fs_info->fs_devices->seed_list);
69696970
return fs_devices;
69706971
}
69716972

0 commit comments

Comments
 (0)