lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1579417750-21984-1-git-send-email-qiwuchen55@gmail.com>
Date:   Sun, 19 Jan 2020 15:09:10 +0800
From:   qiwuchen55@...il.com
To:     mmayer@...adcom.com, rjw@...ysocki.net, viresh.kumar@...aro.org,
        f.fainelli@...il.com
Cc:     bcm-kernel-feedback-list@...adcom.com, linux-pm@...r.kernel.org,
        linux-arm-kernel@...ts.infradead.org, linux-kernel@...r.kernel.org,
        chenqiwu <chenqiwu@...omi.com>
Subject: [PATCH v3] cpufreq: brcmstb-avs: fix imbalance of cpufreq policy refcount

From: chenqiwu <chenqiwu@...omi.com>

brcm_avs_cpufreq_get() calls cpufreq_cpu_get() to get the cpufreq policy,
meanwhile, it also increments the kobject reference count to mark it busy.
However, a corresponding call of cpufreq_cpu_put() is ignored to decrement
the kobject reference count back, which may lead to a potential stuck risk
that the cpuhp thread deadly waits for dropping of kobject refcount when
cpufreq policy free.

For fixing this bug, cpufreq_get_policy() is referenced to do a proper
cpufreq_cpu_get()/cpufreq_cpu_put() and fill a policy copy for the user.
If the policy return NULL, we just return 0 to hit the code path of
cpufreq_driver->get.

Signed-off-by: chenqiwu <chenqiwu@...omi.com>
---
 drivers/cpufreq/brcmstb-avs-cpufreq.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/cpufreq/brcmstb-avs-cpufreq.c b/drivers/cpufreq/brcmstb-avs-cpufreq.c
index 77b0e5d..ee0d404 100644
--- a/drivers/cpufreq/brcmstb-avs-cpufreq.c
+++ b/drivers/cpufreq/brcmstb-avs-cpufreq.c
@@ -452,8 +452,16 @@ static bool brcm_avs_is_firmware_loaded(struct private_data *priv)
 
 static unsigned int brcm_avs_cpufreq_get(unsigned int cpu)
 {
-	struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
-	struct private_data *priv = policy->driver_data;
+	struct cpufreq_policy policy;
+	struct private_data *priv;
+
+	/*
+	 * In case cpufreq policy has been released, just return 0.
+	 */
+	if (cpufreq_get_policy(&policy, cpu))
+		return 0;
+
+	priv = policy.driver_data;
 
 	return brcm_avs_get_frequency(priv->base);
 }
-- 
1.9.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ