android_kernel_sony_sdm845/arch/x86/kernel
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Jiri Olsa ed61e8c59b kretprobe: Prevent triggering kretprobe from within kprobe_flush_task
[ Upstream commit 9b38cc704e844e41d9cf74e647bff1d249512cb3 ]

Ziqian reported lockup when adding retprobe on _raw_spin_lock_irqsave.
My test was also able to trigger lockdep output:

 ============================================
 WARNING: possible recursive locking detected
 5.6.0-rc6+ #6 Not tainted
 --------------------------------------------
 sched-messaging/2767 is trying to acquire lock:
 ffffffff9a492798 (&(kretprobe_table_locks[i].lock)){-.-.}, at: kretprobe_hash_lock+0x52/0xa0

 but task is already holding lock:
 ffffffff9a491a18 (&(kretprobe_table_locks[i].lock)){-.-.}, at: kretprobe_trampoline+0x0/0x50

 other info that might help us debug this:
  Possible unsafe locking scenario:

        CPU0
        ----
   lock(&(kretprobe_table_locks[i].lock));
   lock(&(kretprobe_table_locks[i].lock));

  *** DEADLOCK ***

  May be due to missing lock nesting notation

 1 lock held by sched-messaging/2767:
  #0: ffffffff9a491a18 (&(kretprobe_table_locks[i].lock)){-.-.}, at: kretprobe_trampoline+0x0/0x50

 stack backtrace:
 CPU: 3 PID: 2767 Comm: sched-messaging Not tainted 5.6.0-rc6+ #6
 Call Trace:
  dump_stack+0x96/0xe0
  __lock_acquire.cold.57+0x173/0x2b7
  ? native_queued_spin_lock_slowpath+0x42b/0x9e0
  ? lockdep_hardirqs_on+0x590/0x590
  ? __lock_acquire+0xf63/0x4030
  lock_acquire+0x15a/0x3d0
  ? kretprobe_hash_lock+0x52/0xa0
  _raw_spin_lock_irqsave+0x36/0x70
  ? kretprobe_hash_lock+0x52/0xa0
  kretprobe_hash_lock+0x52/0xa0
  trampoline_handler+0xf8/0x940
  ? kprobe_fault_handler+0x380/0x380
  ? find_held_lock+0x3a/0x1c0
  kretprobe_trampoline+0x25/0x50
  ? lock_acquired+0x392/0xbc0
  ? _raw_spin_lock_irqsave+0x50/0x70
  ? __get_valid_kprobe+0x1f0/0x1f0
  ? _raw_spin_unlock_irqrestore+0x3b/0x40
  ? finish_task_switch+0x4b9/0x6d0
  ? __switch_to_asm+0x34/0x70
  ? __switch_to_asm+0x40/0x70

The code within the kretprobe handler checks for probe reentrancy,
so we won't trigger any _raw_spin_lock_irqsave probe in there.

The problem is in outside kprobe_flush_task, where we call:

  kprobe_flush_task
    kretprobe_table_lock
      raw_spin_lock_irqsave
        _raw_spin_lock_irqsave

where _raw_spin_lock_irqsave triggers the kretprobe and installs
kretprobe_trampoline handler on _raw_spin_lock_irqsave return.

The kretprobe_trampoline handler is then executed with already
locked kretprobe_table_locks, and first thing it does is to
lock kretprobe_table_locks ;-) the whole lockup path like:

  kprobe_flush_task
    kretprobe_table_lock
      raw_spin_lock_irqsave
        _raw_spin_lock_irqsave ---> probe triggered, kretprobe_trampoline installed

        ---> kretprobe_table_locks locked

        kretprobe_trampoline
          trampoline_handler
            kretprobe_hash_lock(current, &head, &flags);  <--- deadlock

Adding kprobe_busy_begin/end helpers that mark code with fake
probe installed to prevent triggering of another kprobe within
this code.

Using these helpers in kprobe_flush_task, so the probe recursion
protection check is hit and the probe is never set to prevent
above lockup.

Link: http://lkml.kernel.org/r/158927059835.27680.7011202830041561604.stgit@devnote2

Fixes: ef53d9c5e4 ("kprobes: improve kretprobe scalability with hashed locking")
Cc: Ingo Molnar <mingo@kernel.org>
Cc: "Gustavo A . R . Silva" <gustavoars@kernel.org>
Cc: Anders Roxell <anders.roxell@linaro.org>
Cc: "Naveen N . Rao" <naveen.n.rao@linux.ibm.com>
Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
Cc: David Miller <davem@davemloft.net>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: stable@vger.kernel.org
Reported-by: "Ziqian SUN (Zamir)" <zsun@redhat.com>
Acked-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2020-06-30 15:38:33 -04:00
..
acpi acpi/x86: ignore unspecified bit positions in the ACPI global lock field 2020-04-24 07:58:53 +02:00
apic x86/ioapic: Prevent inconsistent state when moving an interrupt 2020-01-04 13:39:29 +01:00
cpu x86/speculation: PR_SPEC_FORCE_DISABLE enforcement for indirect branches. 2020-06-20 10:24:10 +02:00
fpu x86/fpu: Disable bottom halves while loading FPU registers 2018-12-29 13:40:15 +01:00
kprobes kretprobe: Prevent triggering kretprobe from within kprobe_flush_task 2020-06-30 15:38:33 -04:00
.gitignore
alternative.c x86/paravirt: Remove 'noreplace-paravirt' cmdline option 2018-02-13 12:36:01 +01:00
amd_gart_64.c dma-mapping: use unsigned long for dma_attrs 2016-08-04 08:50:07 -04:00
amd_nb.c x86/cpu: Rename cpu_data.x86_mask to cpu_data.x86_stepping 2018-02-22 15:43:55 +01:00
apb_timer.c x86/apb_timer: Convert to hotplug state machine 2016-07-15 10:40:22 +02:00
aperture_64.c param: convert some "on"/"off" users to strtobool 2016-03-17 15:09:34 -07:00
apm_32.c x86/apm: Don't access __preempt_count with zeroed fs 2018-07-25 11:23:58 +02:00
asm-offsets.c x86: Move thread_info into task_struct 2016-09-15 08:25:13 +02:00
asm-offsets_32.c x86/cpu: Rename cpu_data.x86_mask to cpu_data.x86_stepping 2018-02-22 15:43:55 +01:00
asm-offsets_64.c sched/x86: Rewrite the switch_to() code 2016-08-24 12:31:41 +02:00
audit_64.c
bootflag.c
check.c x86/corruption-check: Fix panic in memory_corruption_check() when boot option without value is provided 2018-11-13 11:16:47 -08:00
cpuid.c new helpers: no_seek_end_llseek{,_size}() 2015-12-23 10:41:31 -05:00
crash.c x86/panic: replace smp_send_stop() with kdump friendly version in panic path 2016-10-11 15:06:32 -07:00
crash_dump_32.c
crash_dump_64.c
devicetree.c x86/devicetree: Fix device IRQ settings in DT 2018-05-30 07:50:48 +02:00
doublefault.c
dumpstack.c x86/entry/64: Wipe KASAN stack shadow before rewind_stack_do_exit() 2018-09-05 09:20:10 +02:00
dumpstack_32.c x86/dumpstack: Remove dump_trace() and related callbacks 2016-09-20 08:29:34 +02:00
dumpstack_64.c x86/dumpstack: Remove dump_trace() and related callbacks 2016-09-20 08:29:34 +02:00
e820.c x86/e820: Don't merge consecutive E820_PRAM ranges 2016-10-16 11:16:48 +02:00
early-quirks.c Merge tag 'drm-for-v4.9' of git://people.freedesktop.org/~airlied/linux 2016-10-11 18:12:22 -07:00
early_printk.c x86: Fix misspellings in comments 2016-02-24 08:44:58 +01:00
ebda.c x86/boot: Simplify EBDA-vs-BIOS reservation logic 2016-07-22 11:46:01 +02:00
espfix_64.c kaiser: add "nokaiser" boot option, using ALTERNATIVE 2018-01-05 15:46:34 +01:00
ftrace.c x86: Don't include linux/irq.h from asm/hardirq.h 2018-08-15 18:14:52 +02:00
head32.c x86/boot: Run reserve_bios_regions() after we initialize the memory map 2016-08-11 11:14:59 +02:00
head64.c x86/kasan: Fix boot with KASAN=y and PROFILE_ANNOTATED_BRANCHES=y 2017-03-22 12:43:40 +01:00
head_32.S x86/cpu: Rename cpu_data.x86_mask to cpu_data.x86_stepping 2018-02-22 15:43:55 +01:00
head_64.S Revert "x86/mm: Expand static page table for fixmap space" 2018-11-10 07:42:59 -08:00
hpet.c x86/hpet: Prevent potential NULL pointer dereference 2019-04-20 09:07:50 +02:00
hw_breakpoint.c x86/hw_breakpoints: Make default case in hw_breakpoint_arch_parse() return an error 2019-04-20 09:07:50 +02:00
i8237.c
i8253.c x86/kernel: Audit and remove any unnecessary uses of module.h 2016-07-14 15:06:41 +02:00
i8259.c x86: Don't include linux/irq.h from asm/hardirq.h 2018-08-15 18:14:52 +02:00
io_delay.c x86/kernel: Audit and remove any unnecessary uses of module.h 2016-07-14 15:06:41 +02:00
ioport.c x86/iopl: Fix iopl capability check on Xen PV 2016-03-17 09:49:27 +01:00
irq.c x86: Don't include linux/irq.h from asm/hardirq.h 2018-08-15 18:14:52 +02:00
irq_32.c x86: Don't include linux/irq.h from asm/hardirq.h 2018-08-15 18:14:52 +02:00
irq_64.c x86/irq/64: Limit IST stack overflow check to #DB stack 2019-05-31 06:48:22 -07:00
irq_work.c x86/irq, trace: Add __irq_entry annotation to x86's platform IRQ handlers 2017-11-21 09:23:24 +01:00
irqflags.S x86/paravirt: Make native_save_fl() extern inline 2018-07-22 14:27:35 +02:00
irqinit.c x86: Don't include linux/irq.h from asm/hardirq.h 2018-08-15 18:14:52 +02:00
jump_label.c x86/asm: Stop depending on ptrace.h in alternative.h 2016-04-29 11:56:40 +02:00
kdebugfs.c x86/kernel: Audit and remove any unnecessary uses of module.h 2016-07-14 15:06:41 +02:00
kexec-bzimage64.c x86/kexec: Don't setup EFI info if EFI runtime is not enabled 2019-03-13 14:04:57 -07:00
kgdb.c x86/kgbd: Use NMI_VECTOR not APIC_DM_NMI 2020-01-29 10:24:29 +01:00
ksysfs.c x86: Apply more __ro_after_init and const 2016-08-10 14:55:05 +02:00
kvm.c kvm/x86: Handle async PF in RCU read-side critical sections 2017-10-05 09:44:03 +02:00
kvmclock.c Merge branch 'linus' into x86/asm, to pick up recent fixes 2016-09-15 08:24:53 +02:00
ldt.c kaiser: fix unlikely error in alloc_ldt_struct() 2018-01-05 15:46:34 +01:00
livepatch.c livepatch/x86: apply alternatives and paravirt patches after relocations 2016-08-18 23:41:55 +02:00
machine_kexec_32.c x86/kexec: Avoid double free_page() upon do_kexec_load() failure 2018-05-25 16:12:59 +02:00
machine_kexec_64.c x86/kexec: Avoid double free_page() upon do_kexec_load() failure 2018-05-25 16:12:59 +02:00
Makefile x86/paravirt: Make native_save_fl() extern inline 2018-07-22 14:27:35 +02:00
mcount_64.S x86/retpoline/ftrace: Convert ftrace assembler indirect jumps 2018-01-17 09:38:59 +01:00
mmconf-fam10h_64.c
module.c x86: Treat R_X86_64_PLT32 as R_X86_64_PC32 2018-03-18 11:18:55 +01:00
mpparse.c x86/cpu: Rename cpu_data.x86_mask to cpu_data.x86_stepping 2018-02-22 15:43:55 +01:00
msr.c x86/cpufeature: Carve out X86_FEATURE_* 2016-01-30 11:22:17 +01:00
nmi.c x86/speculation/mds: Clear CPU buffers on exit to user 2019-05-14 19:19:40 +02:00
nmi_selftest.c
paravirt-spinlocks.c x86, locking/spinlocks: Remove ticket (spin)lock implementation 2016-09-30 10:56:00 +02:00
paravirt.c x86/paravirt: Fix some warning messages 2018-11-10 07:42:55 -08:00
paravirt_patch_32.c x86, locking/spinlocks: Remove ticket (spin)lock implementation 2016-09-30 10:56:00 +02:00
paravirt_patch_64.c x86/paravirt: Dont patch flush_tlb_single 2018-01-05 15:46:35 +01:00
pci-calgary_64.c x86/pci-calgary: Fix iommu_free() comparison of unsigned expression >= 0 2017-05-14 14:00:17 +02:00
pci-dma.c dma-mapping: use unsigned long for dma_attrs 2016-08-04 08:50:07 -04:00
pci-iommu_table.c x86: Fix non-static inlines 2016-04-16 13:21:40 +02:00
pci-nommu.c dma-mapping: use unsigned long for dma_attrs 2016-08-04 08:50:07 -04:00
pci-swiotlb.c swiotlb: Convert swiotlb_force from int to enum 2017-01-26 08:24:44 +01:00
pcspeaker.c
perf_regs.c
platform-quirks.c x86/boot: Reorganize and clean up the BIOS area reservation code 2016-07-21 10:11:57 +02:00
pmem.c x86/kernel: Audit and remove any unnecessary uses of module.h 2016-07-14 15:06:41 +02:00
probe_roms.c
process.c x86/speculation: Prevent rogue cross-process SSBD shutdown 2020-06-20 10:24:08 +02:00
process.h x86/speculation: Change misspelled STIPB to STIBP 2020-06-20 10:24:10 +02:00
process_32.c sched/x86: Save [ER]FLAGS on context switch 2019-05-21 18:48:56 +02:00
process_64.c sched/x86: Save [ER]FLAGS on context switch 2019-05-21 18:48:56 +02:00
ptrace.c x86/ptrace: fix up botched merge of spectrev1 fix 2019-09-06 10:19:53 +02:00
pvclock.c KVM: x86: introduce get_kvmclock_ns 2016-09-20 09:26:15 +02:00
quirks.c x86/mce: Check for alternate indication of machine check recovery on Skylake 2018-07-03 11:23:05 +02:00
reboot.c x86/reboot/quirks: Add MacBook6,1 reboot quirk 2020-06-20 10:24:08 +02:00
reboot_fixups_32.c
relocate_kernel_32.S
relocate_kernel_64.S
resource.c x86/e820: Prepare e280 code for switch to dynamic storage 2016-09-21 15:02:12 +02:00
rtc.c char/genrtc: x86: remove remnants of asm/rtc.h 2016-06-04 00:20:07 +02:00
setup.c x86/speculation/l1tf: Make sure the first page is always reserved 2018-08-15 18:14:44 +02:00
setup_percpu.c x86/boot/32: Fix UP boot on Quark and possibly other platforms 2018-03-22 09:17:58 +01:00
signal.c x86/uaccess, signal: Fix AC=1 bloat 2019-05-31 06:48:29 -07:00
signal_compat.c x86/signals: Fix lower/upper bound reporting in compat siginfo 2017-04-21 09:31:20 +02:00
smp.c x86/reboot: Always use NMI fallback when shutdown via reboot vector IPI fails 2019-10-05 12:30:18 +02:00
smpboot.c x86: Fix early boot crash on gcc-10, third try 2020-05-20 08:15:41 +02:00
stacktrace.c x86/stacktrace: Convert save_stack_trace_*() to use the new unwinder 2016-09-20 08:29:33 +02:00
step.c mm: replace access_process_vm() write parameter with gup_flags 2016-10-19 08:31:25 -07:00
sys_x86_64.c x86/mm: Make mmap(MAP_32BIT) work correctly 2018-03-22 09:17:38 +01:00
sysfb.c
sysfb_efi.c x86/sysfb_efi: Add quirks for some devices with swapped width and height 2019-08-04 09:33:42 +02:00
sysfb_simplefb.c x86/sysfb: Fix check for bad VRAM size 2020-02-28 15:42:21 +01:00
tboot.c x86/pti: Make unpoison of pgd for trusted boot work for real 2018-02-13 12:35:55 +01:00
tce_64.c x86/cpufeature: Remove cpu_has_clflush 2016-03-31 13:35:09 +02:00
test_nx.c x86/mm: Always enable CONFIG_DEBUG_RODATA and remove the Kconfig option 2016-02-22 08:51:38 +01:00
test_rodata.c x86: Don't use module.h just for AUTHOR / LICENSE tags 2016-07-14 13:04:20 +02:00
time.c x86_64: Fix jiffies ODR violation 2020-06-20 10:24:08 +02:00
tls.c x86/tls: Fix possible spectre-v1 in do_get_thread_area() 2019-07-21 09:05:58 +02:00
tls.h
topology.c
trace_clock.c
tracepoint.c kaiser: merged update 2018-01-05 15:46:32 +01:00
traps.c x86/speculation/mds: Revert CPU buffer clear on double fault exit 2019-05-21 18:48:55 +02:00
tsc.c x86/cpu: Sanitize FAM6_ATOM naming 2019-05-14 19:19:34 +02:00
tsc_msr.c x86/tsc: Add missing header to tsc_msr.c 2018-10-03 17:01:45 -07:00
tsc_sync.c
unwind_frame.c x86/unwind: Disable KASAN checks for non-current tasks 2019-05-08 07:19:06 +02:00
unwind_guess.c x86/unwind: Fix guess-unwinder regression 2016-11-28 07:47:54 +01:00
uprobes.c uprobes/x86: Prohibit probing on MOV SS instruction 2019-11-25 09:53:13 +01:00
verify_cpu.S x86/cpufeature: Carve out X86_FEATURE_* 2016-01-30 11:22:17 +01:00
vm86_32.c x86/vm86/32: Fix POPF emulation 2018-03-22 09:17:59 +01:00
vmlinux.lds.S x86_64: Fix jiffies ODR violation 2020-06-20 10:24:08 +02:00
vsmp_64.c
x86_init.c x86: Apply more __ro_after_init and const 2016-08-10 14:55:05 +02:00