From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 665E93E832A; Wed, 20 May 2026 18:51:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779303086; cv=none; b=oyXOL8quNowD/sp11zbuZARB8P+Dg6Hsy7WUs9jtWsGgTeukAyvtlBpnh+ZIr9j0PQd2CczsVwryDj5K+f9REsJEBbx6rJcvw8xy5ETTB3GOr7qCw/5VZvvxfaDm3iH90tIo1RfgcQ/Vze6xz82qaLFpKTAI5zoFvUT1Oiiuc5M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779303086; c=relaxed/simple; bh=fzEWG5iVfCUfjWIK3+l/1Rpo+K3Wb52Dnc+VzD9QETM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ngo6NOqCKS2vMPX+AUGKd353BasJ6eb8xBT/pe0kpr7iHst6fgCn2kvUa71cVmpTbInnKrvnoneM+AC9HrCeeYLqArqR0LMtDC7WWlpQtPs/vyK1dBB3Kl3V4+9N7gc9kDKSjwi5kBikpQGDjTetDqnejuiTTrRWHNI4F/RBY8U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=E0q8DcWP; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="E0q8DcWP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 638C71F000E9; Wed, 20 May 2026 18:51:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1779303082; bh=eY7lvnb76pte6DyxKCbo+E/nwu9YzoHtjy3SPEq6sbg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=E0q8DcWP1Vo+Msb3yqNjT1DsqUcGtEt1LIaAv7LixrFhCURZr9fUoEMhEP/t4pbqv EJ8EimwmErq5VnBE+ib3ZAMSjCxppOfdOo5iVjFm/RV0/cA7kU1eDPxaxQ+WbHDot/ 6MaXZ0YQfMVrAHdA5e2i9SQIBtGL7HM50ZoZjeds= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Qu Wenruo , Guangshuo Li , David Sterba , Sasha Levin Subject: [PATCH 6.6 486/508] btrfs: fix double free in create_space_info_sub_group() error path Date: Wed, 20 May 2026 18:25:09 +0200 Message-ID: <20260520162109.124492088@linuxfoundation.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260520162058.573354582@linuxfoundation.org> References: <20260520162058.573354582@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Guangshuo Li [ Upstream commit a7449edf96143f192606ec8647e3167e1ecbd728 ] When kobject_init_and_add() fails, the call chain is: create_space_info_sub_group() -> btrfs_sysfs_add_space_info_type() -> kobject_init_and_add() -> failure -> kobject_put(&sub_group->kobj) -> space_info_release() -> kfree(sub_group) Then control returns to create_space_info_sub_group(), where: btrfs_sysfs_add_space_info_type() returns error -> kfree(sub_group) Thus, sub_group is freed twice. Keep parent->sub_group[index] = NULL for the failure path, but after btrfs_sysfs_add_space_info_type() has called kobject_put(), let the kobject release callback handle the cleanup. Fixes: f92ee31e031c ("btrfs: introduce btrfs_space_info sub-group") CC: stable@vger.kernel.org # 6.18+ Reviewed-by: Qu Wenruo Signed-off-by: Guangshuo Li Signed-off-by: David Sterba Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/space-info.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) --- a/fs/btrfs/space-info.c +++ b/fs/btrfs/space-info.c @@ -263,10 +263,8 @@ static int create_space_info_sub_group(s sub_group->subgroup_id = id; ret = btrfs_sysfs_add_space_info_type(sub_group); - if (ret) { - kfree(sub_group); + if (ret) parent->sub_group[index] = NULL; - } return ret; }