Skip to contentSkip to conversation

cpuidle: Prevent null pointer dereference in cpuidle_coupled_cpu_notify

PATCH Applied Jon Medhurst (Tixy) 2 participants 2 messages Aug 14, 2012 – Aug 15, 2012 CPU idle time management framework

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpuidle: Prevent null pointer dereference in cpuidle_coupled_cpu_notify

When a kernel is built to support multiple hardware types it's possible that CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED is set but the hardware the kernel is run on doesn't support cpuidle and therefore doesn't load a driver for it. In this case, when the system is shut down, cpuidle_coupled_cpu_notify() gets called with cpuidle_devices set to NULL. There are quite possibly other circumstances where this situation can also occur and we should check for it.

---

Would a better fix be to delay registering the notifier until cpuidle_coupled_register_device() is called? Though following through with that logic would require unregistering the notifier when cpuidle driver is unregistered and it still seems possible that there would still be a window of opportunity for things to go wrong.

 drivers/cpuidle/coupled.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cpuidle/coupled.c +1 -1
index 2c9bf26..c78a5ff 100644
@@ -681,7 +681,7 @@ static int cpuidle_coupled_cpu_notify(struct notifier_block *nb,
 	mutex_lock(&cpuidle_lock);
 
 	dev = per_cpu(cpuidle_devices, cpu);
-	if (!dev->coupled)
+	if (!dev || !dev->coupled)
 		goto out;
 
 	switch (action & ~CPU_TASKS_FROZEN) {
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 9 lines · Jon Medhurst (Tixy)

When a kernel is built to support multiple hardware types it's possible that CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED is set but the hardware the kernel is run on doesn't support cpuidle and therefore doesn't load a driver for it. In this case, when the system is shut down, cpuidle_coupled_cpu_notify() gets called with cpuidle_devices set to NULL. There are quite possibly other circumstances where this situation can also occur and we should check for it.

Applied to the linux-next branch of the linux-pm.git tree as v3.6 material.

Thanks,
Rafael

Quoted 26 lines

---

Would a better fix be to delay registering the notifier until cpuidle_coupled_register_device() is called? Though following through with that logic would require unregistering the notifier when cpuidle driver is unregistered and it still seems possible that there would still be a window of opportunity for things to go wrong.

 drivers/cpuidle/coupled.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cpuidle/coupled.c +1 -1
index 2c9bf26..c78a5ff 100644
@@ -681,7 +681,7 @@ static int cpuidle_coupled_cpu_notify(struct notifier_block *nb,
 	mutex_lock(&cpuidle_lock);
 
 	dev = per_cpu(cpuidle_devices, cpu);
-	if (!dev->coupled)
+	if (!dev || !dev->coupled)
 		goto out;
 
 	switch (action & ~CPU_TASKS_FROZEN) {