android_kernel_sony_sdm845/arch/x86
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
..
boot x86/boot/compressed: Relax sed symbol type regex for LLVM ld.lld 2020-06-30 15:38:31 -04:00
configs IOMMU Updates for Linux v4.9 2016-10-11 12:52:41 -07:00
crypto crypto: x86/crct10dif-pcl - fix use via crypto_shash_digest() 2019-05-21 18:48:57 +02:00
entry x86/entry/32: Add missing ASM_CLAC to general_protection entry 2020-04-24 07:58:54 +02:00
events perf/amd/uncore: Replace manual sampling check with CAP_NO_INTERRUPT flag 2020-03-20 09:07:56 +01:00
ia32 x86/ia32: Fix ia32_restore_sigcontext() AC leak 2019-05-31 06:48:29 -07:00
include x86/speculation: Add support for STIBP always-on preferred mode 2020-06-20 10:24:10 +02:00
kernel kretprobe: Prevent triggering kretprobe from within kprobe_flush_task 2020-06-30 15:38:33 -04:00
kvm KVM: nVMX: Consult only the "basic" exit reason when routing nested exit 2020-06-20 10:24:11 +02:00
lguest
lib x86/decoder: Add TEST opcode to Group3-2 2020-02-28 15:42:36 +01:00
math-emu x86: math-emu: Hide clang warnings for 16-bit overflow 2019-08-06 18:29:37 +02:00
mm x86/mm: Stop printing BRK addresses 2020-06-20 10:24:17 +02:00
net bpf, x86: Fix encoding for lower 8-bit registers in BPF_STX BPF_B 2020-05-02 17:23:16 +02:00
oprofile x86/oprofile: Fix bogus GCC-8 warning in nmi_setup() 2018-02-28 10:18:31 +01:00
pci x86/PCI: Mark Intel C620 MROMs as having non-compliant BARs 2020-06-20 10:24:08 +02:00
platform efi/x86: Map the entire EFI vendor string before copying it 2020-02-28 15:42:19 +01:00
power x86/CPU/AMD: Clear RDRAND CPUID bit on AMD family 15h/16h 2019-09-06 10:19:41 +02:00
purgatory kasan: do not sanitize kexec purgatory 2017-10-08 10:26:09 +02:00
ras x86/RAS/mce_amd_inj: Remove debugfs dir recursively on exit 2016-09-26 11:13:17 +02:00
realmode x86/build: Specify elf_i386 linker emulation explicitly for i386 objects 2019-04-05 22:29:14 +02:00
tools x86/insn: Fix awk regexp warnings 2019-11-28 18:29:03 +01:00
um um: Fix FP register size for XSTATE/XSAVE 2019-08-04 09:33:31 +02:00
video
xen x86: Fix early boot crash on gcc-10, third try 2020-05-20 08:15:41 +02:00
.gitignore
Kbuild
Kconfig x86/olpc: Fix build error with CONFIG_MFD_CS5535=m 2019-11-25 09:53:38 +01:00
Kconfig.cpu
Kconfig.debug x86, perf: Fix the dependency of the x86 insn decoder selftest 2020-01-29 10:24:31 +01:00
Makefile x86/build: Add -Wnoaddress-of-packed-member to REALMODE_CFLAGS, to silence GCC9 build warning 2019-09-21 07:14:08 +02:00
Makefile.um
Makefile_32.cpu