Skip to content

Commit 7a22e03

Browse files
Sean ChristophersonKAGA-KOKO
authored andcommitted
x86/apic/x2apic: Fix a NULL pointer deref when handling a dying cpu
Check that the per-cpu cluster mask pointer has been set prior to clearing a dying cpu's bit. The per-cpu pointer is not set until the target cpu reaches smp_callin() during CPUHP_BRINGUP_CPU, whereas the teardown function, x2apic_dead_cpu(), is associated with the earlier CPUHP_X2APIC_PREPARE. If an error occurs before the cpu is awakened, e.g. if do_boot_cpu() itself fails, x2apic_dead_cpu() will dereference the NULL pointer and cause a panic. smpboot: do_boot_cpu failed(-22) to wakeup CPU#1 BUG: kernel NULL pointer dereference, address: 0000000000000008 RIP: 0010:x2apic_dead_cpu+0x1a/0x30 Call Trace: cpuhp_invoke_callback+0x9a/0x580 _cpu_up+0x10d/0x140 do_cpu_up+0x69/0xb0 smp_init+0x63/0xa9 kernel_init_freeable+0xd7/0x229 ? rest_init+0xa0/0xa0 kernel_init+0xa/0x100 ret_from_fork+0x35/0x40 Fixes: 023a611 ("x86/apic/x2apic: Simplify cluster management") Signed-off-by: Sean Christopherson <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Cc: [email protected] Link: https://lkml.kernel.org/r/[email protected]
1 parent e211288 commit 7a22e03

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

arch/x86/kernel/apic/x2apic_cluster.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ static int x2apic_dead_cpu(unsigned int dead_cpu)
156156
{
157157
struct cluster_mask *cmsk = per_cpu(cluster_masks, dead_cpu);
158158

159-
cpumask_clear_cpu(dead_cpu, &cmsk->mask);
159+
if (cmsk)
160+
cpumask_clear_cpu(dead_cpu, &cmsk->mask);
160161
free_cpumask_var(per_cpu(ipi_mask, dead_cpu));
161162
return 0;
162163
}

0 commit comments

Comments
 (0)