From: qiwuchen55@gmail.com
To: mmayer@broadcom.com, rjw@rjwysocki.net, viresh.kumar@linaro.org,
f.fainelli@gmail.com
Cc: bcm-kernel-feedback-list@broadcom.com, linux-pm@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
chenqiwu <chenqiwu@xiaomi.com>
Subject: [PATCH v2] cpufreq: brcmstb-avs-cpufreq: avoid potential stuck and UAF risk
Date: Sun, 5 Jan 2020 20:50:50 +0800 [thread overview]
Message-ID: <1578228650-17157-1-git-send-email-qiwuchen55@gmail.com> (raw)
From: chenqiwu <chenqiwu@xiaomi.com>
brcm_avs_cpufreq_get() calls cpufreq_cpu_get() to get cpufreq policy,
meanwhile, it also increments the kobject reference count of policy 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 percpu cpuhp thread deadly waits for
dropping of kobject refcount when percpu cpufreq policy free.
The call trace of stuck risk could be:
cpufreq_online() //If cpufreq online failed, goto out_free_policy.
->cpufreq_policy_free() //Do cpufreq_policy free.
->cpufreq_policy_put_kobj()
->kobject_put() //Skip if policy kfref count is not 1.
->cpufreq_sysfs_release()
->complete() //Complete policy->kobj_unregister.
->wait_for_completion() //Wait for policy->kobj_unregister.
A simple way to avoid this stuck risk is use cpufreq_cpu_get_raw()
instead of cpufreq_cpu_get(), since this can be easily exercised by
attempting to force an unbind of the CPUfreq driver.
Signed-off-by: chenqiwu <chenqiwu@xiaomi.com>
---
drivers/cpufreq/brcmstb-avs-cpufreq.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/cpufreq/brcmstb-avs-cpufreq.c b/drivers/cpufreq/brcmstb-avs-cpufreq.c
index 77b0e5d..6d2bf5c 100644
--- a/drivers/cpufreq/brcmstb-avs-cpufreq.c
+++ b/drivers/cpufreq/brcmstb-avs-cpufreq.c
@@ -452,8 +452,15 @@ 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 = cpufreq_cpu_get_raw(cpu);
+ struct private_data *priv;
+
+ if (!policy)
+ return 0;
+
+ priv = policy->driver_data;
+ if (!priv || !priv->base)
+ return 0;
return brcm_avs_get_frequency(priv->base);
}
--
1.9.1
next reply other threads:[~2020-01-05 12:50 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-05 12:50 qiwuchen55 [this message]
2020-01-06 5:56 ` [PATCH v2] cpufreq: brcmstb-avs-cpufreq: avoid potential stuck and UAF risk Viresh Kumar
2020-01-06 7:09 ` chenqiwu
2020-01-06 7:31 ` Viresh Kumar
2020-01-19 2:25 ` chenqiwu
2020-01-19 4:12 ` Florian Fainelli
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1578228650-17157-1-git-send-email-qiwuchen55@gmail.com \
--to=qiwuchen55@gmail.com \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=chenqiwu@xiaomi.com \
--cc=f.fainelli@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-pm@vger.kernel.org \
--cc=mmayer@broadcom.com \
--cc=rjw@rjwysocki.net \
--cc=viresh.kumar@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).