Skip to contentSkip to conversation

sched/core: Fix error pointer dereference

PATCH In review Ethan Tidmore 3 participants 4 messages Feb 17 – Feb 26 CPU hotplug

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sched/core: Fix error pointer dereference

The function idle_thread_get() can return an error pointer and is not checked for one. Add check for error pointer.

Detected by Smatch:
kernel/cpu.c:911 finish_cpu() error:
'idle' dereferencing possible ERR_PTR()

Fixes bf2c59fce4074 ("sched/core: Fix illegal RCU from offline CPUs")
---
 kernel/cpu.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
kernel/cpu.c +6 -1
index bc4f7a9ba64e..30af888d1bc1 100644
@@ -908,7 +908,12 @@ static int bringup_cpu(unsigned int cpu)
 static int finish_cpu(unsigned int cpu)
 {
 	struct task_struct *idle = idle_thread_get(cpu);
-	struct mm_struct *mm = idle->active_mm;
+	struct mm_struct *mm;
+
+	if (IS_ERR(idle))
+		return PTR_ERR(idle);
+
+	mm = idle->active_mm;
 
 	/*
 	 * sched_force_init_mm() ensured the use of &init_mm,
Signature · 1 line
2.53.0
maintainer
#1 lore raw
Quoted 6 lines · Ethan Tidmore

The function idle_thread_get() can return an error pointer and is not checked for one. Add check for error pointer.

Detected by Smatch:
kernel/cpu.c:911 finish_cpu() error:
'idle' dereferencing possible ERR_PTR()

How could this possibly happen?

Quoted 26 lines
---
 kernel/cpu.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
kernel/cpu.c +6 -1
index bc4f7a9ba64e..30af888d1bc1 100644
@@ -908,7 +908,12 @@ static int bringup_cpu(unsigned int cpu)
 static int finish_cpu(unsigned int cpu)
 {
 	struct task_struct *idle = idle_thread_get(cpu);
-	struct mm_struct *mm = idle->active_mm;
+	struct mm_struct *mm;
+
+	if (IS_ERR(idle))
+		return PTR_ERR(idle);
+
+	mm = idle->active_mm;
 
 	/*
 	 * sched_force_init_mm() ensured the use of &init_mm,
Signature · 1 line
2.53.0
#2 lore raw
Quoted 10 lines · Peter Zijlstra
Quoted 6 lines · Ethan Tidmore

The function idle_thread_get() can return an error pointer and is not checked for one. Add check for error pointer.

Detected by Smatch:
kernel/cpu.c:911 finish_cpu() error:
'idle' dereferencing possible ERR_PTR()

How could this possibly happen?

Sorry about that, must be a false positive. I'll be more careful next time.

Thanks,

ET

Reviewed-by on v1 1/1
#3 lore raw
In reply to Ethan Tidmore
Quoted 34 lines · Ethan Tidmore

The function idle_thread_get() can return an error pointer and is not checked for one. Add check for error pointer.

Detected by Smatch:
kernel/cpu.c:911 finish_cpu() error:
'idle' dereferencing possible ERR_PTR()

Fixes bf2c59fce4074 ("sched/core: Fix illegal RCU from offline CPUs")
---
 kernel/cpu.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
kernel/cpu.c +6 -1
index bc4f7a9ba64e..30af888d1bc1 100644
@@ -908,7 +908,12 @@ static int bringup_cpu(unsigned int cpu)
 static int finish_cpu(unsigned int cpu)
 {
 	struct task_struct *idle = idle_thread_get(cpu);
-	struct mm_struct *mm = idle->active_mm;
+	struct mm_struct *mm;
+
+	if (IS_ERR(idle))
+		return PTR_ERR(idle);
+
+	mm = idle->active_mm;
 
 	/*
 	 * sched_force_init_mm() ensured the use of &init_mm,
Signature · 1 line
2.53.0