x86/apic/x2apic: Fix a NULL pointer deref when handling a dying cpu
authorSean Christopherson <sean.j.christopherson@intel.com>
Tue, 1 Oct 2019 20:50:19 +0000 (13:50 -0700)
committerThomas Gleixner <tglx@linutronix.de>
Tue, 15 Oct 2019 08:57:09 +0000 (10:57 +0200)
commit7a22e03b0c02988e91003c505b34d752a51de344
tree92b8c226cf69876a17096c02f87412feca98d7e7
parente211288b72f15259da86eed6eca680758dbe9e74
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: 023a611748fd5 ("x86/apic/x2apic: Simplify cluster management")
Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/20191001205019.5789-1-sean.j.christopherson@intel.com
arch/x86/kernel/apic/x2apic_cluster.c