From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AD8D831B111; Mon, 29 Dec 2025 16:15:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767024907; cv=none; b=VU1YPriL5Zi3gJSck8TW3mlvgyar6K0NsQcwl8l+F4592ZoVIR+rCs9tutw74IonAl+YPGlK0hYdfDCBWdJzlpDxDR1hzDns2QMYkv37HyJiaTqAd4vU18Poq9k+BmVfBmT3DfnFr8gjR+yOV6kN9ejvxiP4mMOscc9/+Y6jxMw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767024907; c=relaxed/simple; bh=QIbaps/kJ996/UoZwwcEzGseo5TjrOh/N197LVSqW/g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=f0OftEZGcUAywwkMWT2OA7Z1Yy/QcgOgotcYExPfmtaii97zzSw05k028V/4gkXxY7eobmvReznOdJPa7Ylc6iuw8Q2aH776Ir6GRS0sMqrp59GBgDUhrtgJuHm/Z+cUJl5HD6AWoVn/F3qkFb9bAISQYj1lUEPqsdWMZFsTWeo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=lT4UVFE/; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="lT4UVFE/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C17EEC4CEF7; Mon, 29 Dec 2025 16:15:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1767024905; bh=QIbaps/kJ996/UoZwwcEzGseo5TjrOh/N197LVSqW/g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lT4UVFE/nYX/oltYIl7H2qkQNVsRKeU05E/m9cgVprzCMtqogQDo4JYjk3UQZlQgI TPt/PxdeRweQXn9PpBtleGYmWujOM6ajvbEo24ddg5ozX9jd8mj1xpItPOXKCARvQ1 iJT1qh14f1Z4cN5A8AEfsT8gaUvYUcZPRYp64Qew= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, syzbot+eadd98df8bceb15d7fed@syzkaller.appspotmail.com, Qu Wenruo , Deepanshu Kartikey , David Sterba , Sasha Levin Subject: [PATCH 6.18 006/430] btrfs: fix memory leak of fs_devices in degraded seed device path Date: Mon, 29 Dec 2025 17:06:48 +0100 Message-ID: <20251229160724.383926080@linuxfoundation.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251229160724.139406961@linuxfoundation.org> References: <20251229160724.139406961@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Deepanshu Kartikey [ 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: 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 Reviewed-by: Qu Wenruo Signed-off-by: Deepanshu Kartikey Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/volumes.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 2bec544d8ba30..48e717c105c35 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -7178,6 +7178,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.51.0