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 EBEA447F2CA for ; Fri, 15 May 2026 12:15:31 +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=1778847332; cv=none; b=klE2lr3C+JClIJHKjXrzORhDl4NqmDvUyASQYUmFwIxwh/PMS9AtDgBzmqDn95XtL5R8u3GpgXR7LRAoy4M27ypjRNjIZvlamW413b4u4NEignL3fOYxYPGUmK0qnGD2t5Ex15B6jwTK51XO5ZjuhGo8gCDiygJWEdk44iWSlGQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778847332; c=relaxed/simple; bh=kH6HmDnoVwwv9fhT3ERMfT0WKHG0GJUZlH7RW6sNuq8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aDwycqVfcHZMzpagTatGw0Yohmy2E19zSbf2IXIYfv4oknGJykXk11pFdShk5rOSGiZXplnEqgnyZ2cINO8ntXW3Hv+Cge8L7z4+fezQ6TllQZGpj3Gqho8nYbEzcCFmLrkWPM2Tq3LMNYmfdtTrVCHz22h5qe2xEGy6rAIS7TY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=I/UdHOUN; 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="I/UdHOUN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CE087C2BCB0; Fri, 15 May 2026 12:15:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778847331; bh=kH6HmDnoVwwv9fhT3ERMfT0WKHG0GJUZlH7RW6sNuq8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I/UdHOUNJYpU9lUCHiQy8IfuUU7FsSwtoqQ7tkfhUPvf8aQvyXdIF7adSM051vh23 7xCxR/0bwSy505Ki4cx530ns9DP/eLc6U64jf7EI5llYlpz9E3+jq1lE/zjSqZ6VWk 0oEel+N2UOM0FZHoi/RNzr1YIEZbH0dOGV/dcVFeNaJxhzn1kGOiiOeEV0XzkMNos0 fiG/H18iNl94BAGKjheg9AjE1F3wpgEI8EnITdc3kJ5kskpKEDiPsJD+555we/hhjn aoJapeJLF5+IuJeollTTX/fBgyZAxeUe9wr9x4kyMsNRccd4l3eVskgWgWAXI5uqVG nHXF1I2ANHJuQ== From: Sasha Levin To: stable@vger.kernel.org Cc: Guangshuo Li , Qu Wenruo , David Sterba , Sasha Levin Subject: [PATCH 6.12.y 2/2] btrfs: fix double free in create_space_info_sub_group() error path Date: Fri, 15 May 2026 08:15:28 -0400 Message-ID: <20260515121528.3130102-2-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260515121528.3130102-1-sashal@kernel.org> References: <2026051235-rockband-barrel-a707@gregkh> <20260515121528.3130102-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 d059bf5eaa098..2b71ed343b63d 100644 --- a/fs/btrfs/space-info.c +++ b/fs/btrfs/space-info.c @@ -266,10 +266,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