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 854C725B0BC; Sat, 30 May 2026 17:45:15 +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=1780163116; cv=none; b=AwHxIUyOY8TnnSH1ke2Qu4aKZt2KlPl8ujwNGgXVvOob0el4FPy5/rbZSgCnXIINoBSpRsO8tHrLVAug9N4YHhg0cYJ/XszjmCk1MGUW5LZHXyz08pm82X5grlOYiaHehI9Dwmu6vtIAqgFOUnazg5IFcQNE4pdcPPaKK0m9DSA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780163116; c=relaxed/simple; bh=0Xs0DVOwvvzyLUn9S9E43mBp5AeUPfKFEv/yjmw/qcE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZmY68VpVYN0d2oKay9705S156Bpu5EDOfWWkXm4k+oyRdrJnjWpy8Xi9hbkE3C9RvQwqpnp0NRHcSl3aDDR+BZWo5di8EnJXDSmO4tKrPuNGvM50Hf2If51cW2zWlEyCyrguNuxUlzxrDx9ARujVQgTxREnsEBn+EjVnJ+1AB9A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=L2Lal82j; 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="L2Lal82j" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8DD6B1F00893; Sat, 30 May 2026 17:45:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1780163115; bh=sAs+Qtma3DNUenqVBRgeL4c9rNc8WnxRUZzLJaz7RbQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=L2Lal82jepk45clMsDT6H4/lLDWQRKUYh7Y615Mc4h2nWYNzsBjwYGXW94lyulmgO X6j5XefGh7QihAHzXjw7SvZQhK7kxlcYi6hLGByFqNYUbcPcpFvRwPxF+ORHViQA0X yrkNEeFmubRaaMaNJ9Ak5l94ybHYaA7FERNf8oqs= 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 5.15 158/776] cpufreq: governor: fix double free in cpufreq_dbs_governor_init() error path Date: Sat, 30 May 2026 17:57:52 +0200 Message-ID: <20260530160244.554496856@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260530160240.228940103@linuxfoundation.org> References: <20260530160240.228940103@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 5.15-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);