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 E17973D5661 for ; Fri, 15 May 2026 12:06:18 +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=1778846779; cv=none; b=BqYZR/uy6pANUYHvF9rJ6OS0sxBgl/T4Jy4hiPbxKrTMWfJFLEAMKsKYu2fMtaxi/Canb6Wi3ZfqDPJMqckmodVpfpClOPD3altL6obQW9GOuJPSFTb9YCtQJkwErlGTh8lZh9ICCt9y1sXmcaqIPDJe3IxJuBwG0ss8y3iLcYc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778846779; c=relaxed/simple; bh=vHBmHCjTdxWDsJifO8AmXGn+foRLqLIXDLjUI1ENqGw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sodPwhbXphrzPZFzUySpEgrdNEzG4LcEVMogVzH7Szt7a0ESpyr4xxHLAwIEyrcD5m4yN3wUuv/bHe4byB6wQLCMua2G3na+7I/moJiX2SuYnYbrtAdCq7kV/TuHGvcRApSix0sNO/0HyYdXeFVVpzZlsCwwDm/1uw6aK8O958c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gDgIlxb3; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="gDgIlxb3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 37831C2BCB8; Fri, 15 May 2026 12:06:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778846778; bh=vHBmHCjTdxWDsJifO8AmXGn+foRLqLIXDLjUI1ENqGw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gDgIlxb3wdBgxAx9an0I912lPYDKFTh6o3FkEzki2PIvxiQJ64IsLHxjMY9PlMtnL I2XArV3lItoNQEo728QGNke2LsiA3+eqLEXF+L52610lPydnRdxcYzNT9I363SZ9+o xe+CAtTRUJ8aHwXJWcDRtKNfwsHTLf/6HsApSRnKiwWiD9zx5qBecVXv7COP/vb0Gz 11fkG58XN1MdKMEKCcRcytVLiUKQLGad/3S07IaMXCGPrfYTAGCdyjRhOa/VTrukPE t4u7ltwJixAjxC7fSAZ45N2UyoGeWmZHzPTxz/JUG8wdl/yT8+P7/kIvzI5RdMLt+U VjXlzq1P5caTA== From: Sasha Levin To: stable@vger.kernel.org Cc: Guangshuo Li , Qu Wenruo , David Sterba , Sasha Levin Subject: [PATCH 6.18.y 2/2] btrfs: fix double free in create_space_info_sub_group() error path Date: Fri, 15 May 2026 08:06:15 -0400 Message-ID: <20260515120615.3073340-2-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260515120615.3073340-1-sashal@kernel.org> References: <2026051234-decidable-catalyst-a4ae@gregkh> <20260515120615.3073340-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- fs/btrfs/space-info.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c index c4a50550672da..b3ff2e1da89ba 100644 --- a/fs/btrfs/space-info.c +++ b/fs/btrfs/space-info.c @@ -276,10 +276,8 @@ static int create_space_info_sub_group(struct btrfs_space_info *parent, u64 flag 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; } -- 2.53.0