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 1ABE1386550; Wed, 8 Apr 2026 18:19:35 +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=1775672375; cv=none; b=cPj2YmMrERHUcONtKBq/tVC0pwsKE+gWCob5r7WOoGeUZJXJfV40b3nlH26CG3x87bMUQ4YhHhsE7KYMmeg6YGTbxqxjKQhO3oQYk7DPm2rjgUroHGoJLPzG9DQYCwZQXJVTrUj7AKaPA/yb9/tO49S+Jwf+FuY5VFIXlhXFO64= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775672375; c=relaxed/simple; bh=DeHRFftgx8ajOeWAs5b0dQyaQF6qo7IAP9Utl/w34Oo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=akT8njaWRUAhc+xmhNJwU9/bYUjAJUqfiPPDrQ/C3HCUXUKpIVFNuFJB49TVdSVZnETT8IuuBghSkwVo9obG64f4TmxOGggRS56TyqVp/tvfsmmhoCGr9CxY/t6yCCfCdOF73eVsv7D2GuWdLv6rgVyRCFb2xJATY6nZh5Ni1MA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=AwQfD5ny; 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="AwQfD5ny" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7D627C19425; Wed, 8 Apr 2026 18:19:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1775672375; bh=DeHRFftgx8ajOeWAs5b0dQyaQF6qo7IAP9Utl/w34Oo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AwQfD5nyxlKljqNEsEOdYHvQN7oDoXsbWvpRS30UDw3DPxPbXtZBZOUDgIFpJb0UM lSy4h8TmscS19j/Q1fqObhLJvWTGWjZuqhQHbgbPTOXUBrLVm2+MA35/FvzVHJZi2x rAZI1R4XSQ4cIY6aghP3rlUJn6aBWJOxq8yIf0ug= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Guangshuo Li , Zhongqiu Han , Viresh Kumar , "Rafael J. Wysocki" , Sasha Levin Subject: [PATCH 6.1 294/312] cpufreq: governor: fix double free in cpufreq_dbs_governor_init() error path Date: Wed, 8 Apr 2026 20:03:31 +0200 Message-ID: <20260408175944.748148093@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260408175933.715315542@linuxfoundation.org> References: <20260408175933.715315542@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.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Guangshuo Li [ Upstream commit 6dcf9d0064ce2f3e3dfe5755f98b93abe6a98e1e ] When kobject_init_and_add() fails, cpufreq_dbs_governor_init() calls kobject_put(&dbs_data->attr_set.kobj). The kobject release callback cpufreq_dbs_data_release() calls gov->exit(dbs_data) and kfree(dbs_data), but the current error path then calls gov->exit(dbs_data) and kfree(dbs_data) again, causing a double free. Keep the direct kfree(dbs_data) for the gov->init() failure path, but after kobject_init_and_add() has been called, let kobject_put() handle the cleanup through cpufreq_dbs_data_release(). Fixes: 4ebe36c94aed ("cpufreq: Fix kobject memleak") Signed-off-by: Guangshuo Li Reviewed-by: Zhongqiu Han Acked-by: Viresh Kumar Cc: All applicable Link: https://patch.msgid.link/20260401024535.1395801-1-lgs201920130244@gmail.com Signed-off-by: Rafael J. Wysocki Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/cpufreq/cpufreq_governor.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/drivers/cpufreq/cpufreq_governor.c +++ b/drivers/cpufreq/cpufreq_governor.c @@ -468,13 +468,13 @@ int cpufreq_dbs_governor_init(struct cpu /* Failure, so roll back. */ pr_err("initialization failed (dbs_data kobject init error %d)\n", ret); - kobject_put(&dbs_data->attr_set.kobj); - policy->governor_data = NULL; if (!have_governor_per_policy()) gov->gdbs_data = NULL; - gov->exit(dbs_data); + + kobject_put(&dbs_data->attr_set.kobj); + goto free_policy_dbs_info; free_dbs_data: kfree(dbs_data);