From: Richard Cochran <rcochran@linutronix.de>
To: <linux-kernel@vger.kernel.org>
Cc: <rt@linutronix.de>, Len Brown <lenb@kernel.org>,
linux-pm@vger.kernel.org
Subject: [PATCH 06/10] intel_idle: Avoid a double free of the per-CPU data.
Date: Tue, 29 Mar 2016 15:15:58 +0200 [thread overview]
Message-ID: <f99e3e5ea9cc8b2b18cb37e3ed10015833e257ec.1459257096.git.rcochran@linutronix.de> (raw)
In-Reply-To: <cover.1459257096.git.rcochran@linutronix.de>
The helper function, intel_idle_cpuidle_devices_uninit, frees the
globally allocated per-CPU data. However, this function is invoked
from the hot plug notifier callback at a time when freeing that data
is not safe.
If the call to cpuidle_register_driver() should fail (say, due to lack
of memory), then the driver will free its per-CPU region. On the
*next* CPU_ONLINE event, the driver will happily use the region again
and even free it again if the failure repeats.
This patch fixes the issue by moving the call to free_percpu() outside
of the helper function at the two call sites that actually need to
free the per-CPU data.
Cc: Len Brown <lenb@kernel.org>
Cc: linux-pm@vger.kernel.org
Signed-off-by: Richard Cochran <rcochran@linutronix.de>
---
drivers/idle/intel_idle.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/idle/intel_idle.c b/drivers/idle/intel_idle.c
index 5dd741f..0b56872 100644
--- a/drivers/idle/intel_idle.c
+++ b/drivers/idle/intel_idle.c
@@ -1002,7 +1002,7 @@ static int __init intel_idle_probe(void)
/*
* intel_idle_cpuidle_devices_uninit()
- * unregister, free cpuidle_devices
+ * Unregisters the cpuidle devices.
*/
static void intel_idle_cpuidle_devices_uninit(void)
{
@@ -1013,9 +1013,6 @@ static void intel_idle_cpuidle_devices_uninit(void)
dev = per_cpu_ptr(intel_idle_cpuidle_devices, i);
cpuidle_unregister_device(dev);
}
-
- free_percpu(intel_idle_cpuidle_devices);
- return;
}
/*
@@ -1231,6 +1228,7 @@ static int __init intel_idle_init(void)
if (retval) {
cpu_notifier_register_done();
cpuidle_unregister_driver(&intel_idle_driver);
+ free_percpu(intel_idle_cpuidle_devices);
return retval;
}
}
@@ -1253,6 +1251,7 @@ static void __exit intel_idle_exit(void)
cpu_notifier_register_done();
cpuidle_unregister_driver(&intel_idle_driver);
+ free_percpu(intel_idle_cpuidle_devices);
}
module_init(intel_idle_init);
--
2.1.4
next prev parent reply other threads:[~2016-03-29 13:16 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-29 13:15 [PATCH 00/10] intel_idle: Fix hot plug handling Richard Cochran
2016-03-29 13:15 ` [PATCH 01/10] intel_idle: remove useless return from void function Richard Cochran
2016-03-29 13:15 ` [PATCH 02/10] intel_idle: Fix a helper function's return value Richard Cochran
2016-03-29 13:15 ` [PATCH 03/10] intel_idle: Remove redundant initialization calls Richard Cochran
2016-03-29 13:15 ` [PATCH 04/10] intel_idle: Fix deallocation order on the driver exit path Richard Cochran
2016-03-29 13:15 ` [PATCH 05/10] intel_idle: Fix dangling registration on error path Richard Cochran
2016-03-29 13:15 ` Richard Cochran [this message]
2016-03-29 13:15 ` [PATCH 07/10] intel_idle: Setup the timer broadcast only on successful driver load Richard Cochran
2016-03-29 13:16 ` [PATCH 08/10] intel_idle: Don't overreact to a cpuidle registration failure Richard Cochran
2016-03-29 13:16 ` [PATCH 09/10] intel_idle: Propagate hot plug errors Richard Cochran
2016-03-29 13:16 ` [PATCH 10/10] intel_idle: Clean up all registered devices on exit Richard Cochran
2016-04-01 1:39 ` Len Brown
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=f99e3e5ea9cc8b2b18cb37e3ed10015833e257ec.1459257096.git.rcochran@linutronix.de \
--to=rcochran@linutronix.de \
--cc=lenb@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=rt@linutronix.de \
/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).