1. 26 Sep, 2020 1 commit
  2. 21 Aug, 2020 1 commit
    • Muchun Song's avatar
      kprobes: Fix NULL pointer dereference at kprobe_ftrace_handler · 46c9d392
      Muchun Song authored
      commit 0cb2f137 upstream.
      
      We found a case of kernel panic on our server. The stack trace is as
      follows(omit some irrelevant information):
      
        BUG: kernel NULL pointer dereference, address: 0000000000000080
        RIP: 0010:kprobe_ftrace_handler+0x5e/0xe0
        RSP: 0018:ffffb512c6550998 EFLAGS: 00010282
        RAX: 0000000000000000 RBX: ffff8e9d16eea018 RCX: 0000000000000000
        RDX: ffffffffbe1179c0 RSI: ffffffffc0535564 RDI: ffffffffc0534ec0
        RBP: ffffffffc0534ec1 R08: ffff8e9d1bbb0f00 R09: 0000000000000004
        R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000
        R13: ffff8e9d1f797060 R14: 000000000000bacc R15: ffff8e9ce13eca00
        CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
        CR2: 0000000000000080 CR3: 00000008453d0005 CR4: 00000000003606e0
        DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
        DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
        Call Trace:
         <IRQ>
         ftrace_ops_assist_func+0x56/0xe0
         ftrace_call+0x5/0x34
         tcpa_statistic_send+0x5/0x130 [ttcp_engine]
      
      The tcpa_statistic_send is the function being kprobed. After analysis,
      the root cause is that the fourth parameter regs of kprobe_ftrace_handler
      is NULL. Why regs is NULL? We use the crash tool to analyze the kdump.
      
        crash> dis tcpa_statistic_send -r
               <tcpa_statistic_send>: callq 0xffffffffbd8018c0 <ftrace_caller>
      
      The tcpa_statistic_send calls ftrace_caller instead of ftrace_regs_caller.
      So it is reasonable that the fourth parameter regs of kprobe_ftrace_handler
      is NULL. In theory, we should call the ftrace_regs_caller instead of the
      ftrace_caller. After in-depth analysis, we found a reproducible path.
      
        Writing a simple kernel module which starts a periodic timer. The
        timer's handler is named 'kprobe_test_timer_handler'. The module
        name is kprobe_test.ko.
      
        1) insmod kprobe_test.ko
        2) bpftrace -e 'kretprobe:kprobe_test_timer_handler {}'
        3) echo 0 > /proc/sys/kernel/ftrace_enabled
        4) rmmod kprobe_test
        5) stop step 2) kprobe
        6) insmod kprobe_test.ko
        7) bpftrace -e 'kretprobe:kprobe_test_timer_handler {}'
      
      We mark the kprobe as GONE but not disarm the kprobe in the step 4).
      The step 5) also do not disarm the kprobe when unregister kprobe. So
      we do not remove the ip from the filter. In this case, when the module
      loads again in the step 6), we will replace the code to ftrace_caller
      via the ftrace_module_enable(). When we register kprobe again, we will
      not replace ftrace_caller to ftrace_regs_caller because the ftrace is
      disabled in the step 3). So the step 7) will trigger kernel panic. Fix
      this problem by disarming the kprobe when the module is going away.
      
      Link: https://lkml.kernel.org/r/20200728064536.24405-1-songmuchun@bytedance.com
      
      Cc: stable@vger.kernel.org
      Fixes: ae6aa16f
      
       ("kprobes: introduce ftrace based optimization")
      Acked-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Signed-off-by: default avatarMuchun Song <songmuchun@bytedance.com>
      Co-developed-by: default avatarChengming Zhou <zhouchengming@bytedance.com>
      Signed-off-by: default avatarChengming Zhou <zhouchengming@bytedance.com>
      Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      46c9d392
  3. 16 Jul, 2020 2 commits
  4. 25 Jun, 2020 2 commits
    • Jiri Olsa's avatar
      kretprobe: Prevent triggering kretprobe from within kprobe_flush_task · 98abe944
      Jiri Olsa authored
      [ Upstream commit 9b38cc70 ]
      
      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: ef53d9c5
      
       ("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: default avatar"Ziqian SUN (Zamir)" <zsun@redhat.com>
      Acked-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
      Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      98abe944
    • Masami Hiramatsu's avatar
      kprobes: Fix to protect kick_kprobe_optimizer() by kprobe_mutex · 34895355
      Masami Hiramatsu authored
      commit 1a0aa991 upstream.
      
      In kprobe_optimizer() kick_kprobe_optimizer() is called
      without kprobe_mutex, but this can race with other caller
      which is protected by kprobe_mutex.
      
      To fix that, expand kprobe_mutex protected area to protect
      kick_kprobe_optimizer() call.
      
      Link: http://lkml.kernel.org/r/158927057586.27680.5036330063955940456.stgit@devnote2
      
      Fixes: cd7ebe22
      
       ("kprobes: Use text_poke_smp_batch for optimizing")
      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: Ziqian SUN <zsun@redhat.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      34895355
  5. 11 Mar, 2020 1 commit
    • Masami Hiramatsu's avatar
      kprobes: Fix optimize_kprobe()/unoptimize_kprobe() cancellation logic · 38d37073
      Masami Hiramatsu authored
      [ Upstream commit e4add247 ]
      
      optimize_kprobe() and unoptimize_kprobe() cancels if a given kprobe
      is on the optimizing_list or unoptimizing_list already. However, since
      the following commit:
      
        f66c0447
      
       ("kprobes: Set unoptimized flag after unoptimizing code")
      
      modified the update timing of the KPROBE_FLAG_OPTIMIZED, it doesn't
      work as expected anymore.
      
      The optimized_kprobe could be in the following states:
      
      - [optimizing]: Before inserting jump instruction
        op.kp->flags has KPROBE_FLAG_OPTIMIZED and
        op->list is not empty.
      
      - [optimized]: jump inserted
        op.kp->flags has KPROBE_FLAG_OPTIMIZED and
        op->list is empty.
      
      - [unoptimizing]: Before removing jump instruction (including unused
        optprobe)
        op.kp->flags has KPROBE_FLAG_OPTIMIZED and
        op->list is not empty.
      
      - [unoptimized]: jump removed
        op.kp->flags doesn't have KPROBE_FLAG_OPTIMIZED and
        op->list is empty.
      
      Current code mis-expects [unoptimizing] state doesn't have
      KPROBE_FLAG_OPTIMIZED, and that can cause incorrect results.
      
      To fix this, introduce optprobe_queued_unopt() to distinguish [optimizing]
      and [unoptimizing] states and fixes the logic in optimize_kprobe() and
      unoptimize_kprobe().
      
      [ mingo: Cleaned up the changelog and the code a bit. ]
      Signed-off-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Reviewed-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: bristot@redhat.com
      Fixes: f66c0447 ("kprobes: Set unoptimized flag after unoptimizing code")
      Link: https://lkml.kernel.org/r/157840814418.7181.13478003006386303481.stgit@devnote2
      
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      38d37073
  6. 05 Mar, 2020 1 commit
    • Masami Hiramatsu's avatar
      kprobes: Set unoptimized flag after unoptimizing code · 39af044d
      Masami Hiramatsu authored
      commit f66c0447
      
       upstream.
      
      Set the unoptimized flag after confirming the code is completely
      unoptimized. Without this fix, when a kprobe hits the intermediate
      modified instruction (the first byte is replaced by an INT3, but
      later bytes can still be a jump address operand) while unoptimizing,
      it can return to the middle byte of the modified code, which causes
      an invalid instruction exception in the kernel.
      
      Usually, this is a rare case, but if we put a probe on the function
      call while text patching, it always causes a kernel panic as below:
      
       # echo p text_poke+5 > kprobe_events
       # echo 1 > events/kprobes/enable
       # echo 0 > events/kprobes/enable
      
      invalid opcode: 0000 [#1] PREEMPT SMP PTI
       RIP: 0010:text_poke+0x9/0x50
       Call Trace:
        arch_unoptimize_kprobe+0x22/0x28
        arch_unoptimize_kprobes+0x39/0x87
        kprobe_optimizer+0x6e/0x290
        process_one_work+0x2a0/0x610
        worker_thread+0x28/0x3d0
        ? process_one_work+0x610/0x610
        kthread+0x10d/0x130
        ? kthread_park+0x80/0x80
        ret_from_fork+0x3a/0x50
      
      text_poke() is used for patching the code in optprobes.
      
      This can happen even if we blacklist text_poke() and other functions,
      because there is a small time window during which we show the intermediate
      code to other CPUs.
      
       [ mingo: Edited the changelog. ]
      Tested-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Signed-off-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Cc: Andy Lutomirski <luto@kernel.org>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Steven Rostedt <rostedt@goodmis.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: bristot@redhat.com
      Fixes: 6274de49 ("kprobes: Support delayed unoptimizing")
      Link: https://lkml.kernel.org/r/157483422375.25881.13508326028469515760.stgit@devnote2
      
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      39af044d
  7. 05 Dec, 2019 1 commit
  8. 20 Nov, 2019 1 commit
  9. 05 Oct, 2019 1 commit
  10. 10 Sep, 2019 1 commit
    • Andrea Righi's avatar
      kprobes: Fix potential deadlock in kprobe_optimizer() · 5e1d50a3
      Andrea Righi authored
      [ Upstream commit f1c6ece2 ]
      
      lockdep reports the following deadlock scenario:
      
       WARNING: possible circular locking dependency detected
      
       kworker/1:1/48 is trying to acquire lock:
       000000008d7a62b2 (text_mutex){+.+.}, at: kprobe_optimizer+0x163/0x290
      
       but task is already holding lock:
       00000000850b5e2d (module_mutex){+.+.}, at: kprobe_optimizer+0x31/0x290
      
       which lock already depends on the new lock.
      
       the existing dependency chain (in reverse order) is:
      
       -> #1 (module_mutex){+.+.}:
              __mutex_lock+0xac/0x9f0
              mutex_lock_nested+0x1b/0x20
              set_all_modules_text_rw+0x22/0x90
              ftrace_arch_code_modify_prepare+0x1c/0x20
              ftrace_run_update_code+0xe/0x30
              ftrace_startup_enable+0x2e/0x50
              ftrace_startup+0xa7/0x100
              register_ftrace_function+0x27/0x70
              arm_kprobe+0xb3/0x130
              enable_kprobe+0x83/0xa0
              enable_trace_kprobe.part.0+0x2e/0x80
              kprobe_register+0x6f/0xc0
              perf_trace_event_init+0x16b/0x270
              perf_kprobe_init+0xa7/0xe0
              perf_kprobe_event_init+0x3e/0x70
              perf_try_init_event+0x4a/0x140
              perf_event_alloc+0x93a/0xde0
              __do_sys_perf_event_open+0x19f/0xf30
              __x64_sys_perf_event_open+0x20/0x30
              do_syscall_64+0x65/0x1d0
              entry_SYSCALL_64_after_hwframe+0x49/0xbe
      
       -> #0 (text_mutex){+.+.}:
              __lock_acquire+0xfcb/0x1b60
              lock_acquire+0xca/0x1d0
              __mutex_lock+0xac/0x9f0
              mutex_lock_nested+0x1b/0x20
              kprobe_optimizer+0x163/0x290
              process_one_work+0x22b/0x560
              worker_thread+0x50/0x3c0
              kthread+0x112/0x150
              ret_from_fork+0x3a/0x50
      
       other info that might help us debug this:
      
        Possible unsafe locking scenario:
      
              CPU0                    CPU1
              ----                    ----
         lock(module_mutex);
                                      lock(text_mutex);
                                      lock(module_mutex);
         lock(text_mutex);
      
        *** DEADLOCK ***
      
      As a reproducer I've been using bcc's funccount.py
      (https://github.com/iovisor/bcc/blob/master/tools/funccount.py
      
      ),
      for example:
      
       # ./funccount.py '*interrupt*'
      
      That immediately triggers the lockdep splat.
      
      Fix by acquiring text_mutex before module_mutex in kprobe_optimizer().
      Signed-off-by: default avatarAndrea Righi <andrea.righi@canonical.com>
      Acked-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
      Cc: David S. Miller <davem@davemloft.net>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Naveen N. Rao <naveen.n.rao@linux.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Fixes: d5b844a2 ("ftrace/x86: Remove possible deadlock between register_kprobe() and ftrace_run_update_code()")
      Link: http://lkml.kernel.org/r/20190812184302.GA7010@xps-13
      
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      5e1d50a3
  11. 27 Apr, 2019 1 commit
    • Masami Hiramatsu's avatar
      kprobes: Fix error check when reusing optimized probes · 23a926e5
      Masami Hiramatsu authored
      commit 5f843ed4 upstream.
      
      The following commit introduced a bug in one of our error paths:
      
        819319fc
      
       ("kprobes: Return error if we fail to reuse kprobe instead of BUG_ON()")
      
      it missed to handle the return value of kprobe_optready() as
      error-value. In reality, the kprobe_optready() returns a bool
      result, so "true" case must be passed instead of 0.
      
      This causes some errors on kprobe boot-time selftests on ARM:
      
       [   ] Beginning kprobe tests...
       [   ] Probe ARM code
       [   ]     kprobe
       [   ]     kretprobe
       [   ] ARM instruction simulation
       [   ]     Check decoding tables
       [   ]     Run test cases
       [   ] FAIL: test_case_handler not run
       [   ] FAIL: Test andge	r10, r11, r14, asr r7
       [   ] FAIL: Scenario 11
       ...
       [   ] FAIL: Scenario 7
       [   ] Total instruction simulation tests=1631, pass=1433 fail=198
       [   ] kprobe tests failed
      
      This can happen if an optimized probe is unregistered and next
      kprobe is registered on same address until the previous probe
      is not reclaimed.
      
      If this happens, a hidden aggregated probe may be kept in memory,
      and no new kprobe can probe same address. Also, in that case
      register_kprobe() will return "1" instead of minus error value,
      which can mislead caller logic.
      Signed-off-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
      Cc: David S . Miller <davem@davemloft.net>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Naveen N . Rao <naveen.n.rao@linux.vnet.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: stable@vger.kernel.org # v5.0+
      Fixes: 819319fc ("kprobes: Return error if we fail to reuse kprobe instead of BUG_ON()")
      Link: http://lkml.kernel.org/r/155530808559.32517.539898325433642204.stgit@devnote2
      
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      23a926e5
  12. 13 Nov, 2018 1 commit
  13. 21 Jun, 2018 6 commits
  14. 25 Apr, 2018 1 commit
    • Thomas Richter's avatar
      kprobes: Fix random address output of blacklist file · bcbd385b
      Thomas Richter authored
      File /sys/kernel/debug/kprobes/blacklist displays random addresses:
      
      [root@s8360046 linux]# cat /sys/kernel/debug/kprobes/blacklist
      0x0000000047149a90-0x00000000bfcb099a	print_type_x8
      ....
      
      This breaks 'perf probe' which uses the blacklist file to prohibit
      probes on certain functions by checking the address range.
      
      Fix this by printing the correct (unhashed) address.
      
      The file mode is read all but this is not an issue as the file
      hierarchy points out:
       # ls -ld /sys/ /sys/kernel/ /sys/kernel/debug/ /sys/kernel/debug/kprobes/
      	/sys/kernel/debug/kprobes/blacklist
      dr-xr-xr-x 12 root root 0 Apr 19 07:56 /sys/
      drwxr-xr-x  8 root root 0 Apr 19 07:56 /sys/kernel/
      drwx------ 16 root root 0 Apr 19 06:56 /sys/kernel/debug/
      drwxr-xr-x  2 root root 0 Apr 19 06:56 /sys/kernel/debug/kprobes/
      -r--r--r--  1 root root 0 Apr 19 06:56 /sys/kernel/debug/kprobes/blacklist
      
      Everything in and below /sys/kernel/debug is rwx to root only,
      no group or others have access.
      
      Background:
      Directory /sys/kernel/debug/kprobes is created by debugfs_create_dir()
      which sets the mode bits to rwxr-xr-x. Maybe change that to use the
      parent's directory mode bits instead?
      
      Link: http://lkml.kernel.org/r/20180419105556.86664-1-tmricht@linux.ibm.com
      
      Fixes: ad67b74d
      
       ("printk: hash addresses printed with %p")
      Cc: stable@vger.kernel.org
      Cc: <stable@vger.kernel.org> # v4.15+
      Cc: Ananth N Mavinakayanahalli <ananth@linux.vnet.ibm.com>
      Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
      Cc: David S Miller <davem@davemloft.net>
      Cc: Masami Hiramatsu <mhiramat@kernel.org>
      Cc: acme@kernel.org
      Signed-off-by: default avatarThomas Richter <tmricht@linux.ibm.com>
      Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
      bcbd385b
  15. 16 Feb, 2018 2 commits
    • Jessica Yu's avatar
      kprobes: Propagate error from disarm_kprobe_ftrace() · 297f9233
      Jessica Yu authored
      Improve error handling when disarming ftrace-based kprobes. Like with
      arm_kprobe_ftrace(), propagate any errors from disarm_kprobe_ftrace() so
      that we do not disable/unregister kprobes that are still armed. In other
      words, unregister_kprobe() and disable_kprobe() should not report success
      if the kprobe could not be disarmed.
      
      disarm_all_kprobes() keeps its current behavior and attempts to
      disarm all kprobes. It returns the last encountered error and gives a
      warning if not all probes could be disarmed.
      
      This patch is based on Petr Mladek's original patchset (patches 2 and 3)
      back in 2015, which improved kprobes error handling, found here:
      
         https://lkml.org/lkml/2015/2/26/452
      
      
      
      However, further work on this had been paused since then and the patches
      were not upstreamed.
      Based-on-patches-by: default avatarPetr Mladek <pmladek@suse.com>
      Signed-off-by: default avatarJessica Yu <jeyu@kernel.org>
      Acked-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Cc: Ananth N Mavinakayanahalli <ananth@linux.vnet.ibm.com>
      Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
      Cc: David S . Miller <davem@davemloft.net>
      Cc: Jiri Kosina <jikos@kernel.org>
      Cc: Joe Lawrence <joe.lawrence@redhat.com>
      Cc: Josh Poimboeuf <jpoimboe@redhat.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Miroslav Benes <mbenes@suse.cz>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Petr Mladek <pmladek@suse.com>
      Cc: Steven Rostedt <rostedt@goodmis.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: live-patching@vger.kernel.org
      Link: http://lkml.kernel.org/r/20180109235124.30886-3-jeyu@kernel.org
      
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      297f9233
    • Jessica Yu's avatar
      kprobes: Propagate error from arm_kprobe_ftrace() · 12310e34
      Jessica Yu authored
      Improve error handling when arming ftrace-based kprobes. Specifically, if
      we fail to arm a ftrace-based kprobe, register_kprobe()/enable_kprobe()
      should report an error instead of success. Previously, this has lead to
      confusing situations where register_kprobe() would return 0 indicating
      success, but the kprobe would not be functional if ftrace registration
      during the kprobe arming process had failed. We should therefore take any
      errors returned by ftrace into account and propagate this error so that we
      do not register/enable kprobes that cannot be armed. This can happen if,
      for example, register_ftrace_function() finds an IPMODIFY conflict (since
      kprobe_ftrace_ops has this flag set) and returns an error. Such a conflict
      is possible since livepatches also set the IPMODIFY flag for their ftrace_ops.
      
      arm_all_kprobes() keeps its current behavior and attempts to arm all
      kprobes. It returns the last encountered error and gives a warning if
      not all probes could be armed.
      
      This patch is based on Petr Mladek's original patchset (patches 2 and 3)
      back in 2015, which improved kprobes error handling, found here:
      
         https://lkml.org/lkml/2015/2/26/452
      
      
      
      However, further work on this had been paused since then and the patches
      were not upstreamed.
      Based-on-patches-by: default avatarPetr Mladek <pmladek@suse.com>
      Signed-off-by: default avatarJessica Yu <jeyu@kernel.org>
      Acked-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Cc: Ananth N Mavinakayanahalli <ananth@linux.vnet.ibm.com>
      Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
      Cc: David S . Miller <davem@davemloft.net>
      Cc: Jiri Kosina <jikos@kernel.org>
      Cc: Joe Lawrence <joe.lawrence@redhat.com>
      Cc: Josh Poimboeuf <jpoimboe@redhat.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Miroslav Benes <mbenes@suse.cz>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Petr Mladek <pmladek@suse.com>
      Cc: Steven Rostedt <rostedt@goodmis.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: live-patching@vger.kernel.org
      Link: http://lkml.kernel.org/r/20180109235124.30886-2-jeyu@kernel.org
      
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      12310e34
  16. 13 Jan, 2018 1 commit
    • Masami Hiramatsu's avatar
      error-injection: Separate error-injection from kprobe · 540adea3
      Masami Hiramatsu authored
      
      Since error-injection framework is not limited to be used
      by kprobes, nor bpf. Other kernel subsystems can use it
      freely for checking safeness of error-injection, e.g.
      livepatch, ftrace etc.
      So this separate error-injection framework from kprobes.
      
      Some differences has been made:
      
      - "kprobe" word is removed from any APIs/structures.
      - BPF_ALLOW_ERROR_INJECTION() is renamed to
        ALLOW_ERROR_INJECTION() since it is not limited for BPF too.
      - CONFIG_FUNCTION_ERROR_INJECTION is the config item of this
        feature. It is automatically enabled if the arch supports
        error injection feature for kprobe or ftrace etc.
      Signed-off-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Reviewed-by: default avatarJosef Bacik <jbacik@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      540adea3
  17. 12 Dec, 2017 1 commit
  18. 20 Oct, 2017 2 commits
    • Masami Hiramatsu's avatar
      kprobes: Disable the jprobes APIs · 590c8459
      Masami Hiramatsu authored
      
      Disable the jprobes APIs and comment out the jprobes API function
      code. This is in preparation of removing all jprobes related
      code (including kprobe's break_handler).
      
      Nowadays ftrace and other tracing features are mature enough
      to replace jprobes use-cases. Users can safely use ftrace and
      perf probe etc. for their use cases.
      Signed-off-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Ananth N Mavinakayanahalli <ananth@linux.vnet.ibm.com>
      Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
      Cc: David S . Miller <davem@davemloft.net>
      Cc: Ian McDonald <ian.mcdonald@jandi.co.nz>
      Cc: Kees Cook <keescook@chromium.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Paul E . McKenney <paulmck@linux.vnet.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Stephen Hemminger <stephen@networkplumber.org>
      Cc: Steven Rostedt <rostedt@goodmis.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Vlad Yasevich <vyasevich@gmail.com>
      Lin...
      590c8459
    • Masami Hiramatsu's avatar
      kprobes: Use synchronize_rcu_tasks() for optprobe with CONFIG_PREEMPT=y · a30b85df
      Masami Hiramatsu authored
      
      We want to wait for all potentially preempted kprobes trampoline
      execution to have completed. This guarantees that any freed
      trampoline memory is not in use by any task in the system anymore.
      synchronize_rcu_tasks() gives such a guarantee, so use it.
      
      Also, this guarantees to wait for all potentially preempted tasks
      on the instructions which will be replaced with a jump.
      
      Since this becomes a problem only when CONFIG_PREEMPT=y, enable
      CONFIG_TASKS_RCU=y for synchronize_rcu_tasks() in that case.
      Signed-off-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Acked-by: default avatarPaul E. McKenney <paulmck@linux.vnet.ibm.com>
      Cc: Ananth N Mavinakayanahalli <ananth@linux.vnet.ibm.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Naveen N . Rao <naveen.n.rao@linux.vnet.ibm.com>
      Cc: Paul E . McKenney <paulmck@linux.vnet.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Steven Rostedt <rostedt@goodmis.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Link: http://lkml.kernel.org/r/150845661962.5443.17724352636247312231.stgit@devbox
      
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      a30b85df
  19. 18 Oct, 2017 1 commit
  20. 28 Sep, 2017 2 commits
  21. 08 Jul, 2017 3 commits
  22. 27 May, 2017 1 commit
  23. 26 May, 2017 1 commit
    • Thomas Gleixner's avatar
      kprobes: Cure hotplug lock ordering issues · 2d1e38f5
      Thomas Gleixner authored
      
      Converting the cpu hotplug locking to a percpu rwsem unearthed hidden lock
      ordering problems.
      
      There is a wide range of locks involved in this: kprobe_mutex,
      jump_label_mutex, ftrace_lock, text_mutex, event_mutex, module_mutex,
      func_hash->regex_lock and a gazillion of lock order permutations with
      nested get_online_cpus() calls.
      
      Some of those permutations are potential deadlocks even with the current
      nesting hotplug locking scheme, but they can't be discovered by lockdep.
      
      The conversion of the hotplug locking to a percpu rwsem requires to prevent
      nested locking, so it's required to take the hotplug rwsem early in the
      call chain and establish a proper lock order.
      
      After quite some analysis and going down the wrong road severa times the
      following lock order has been chosen:
      
      kprobe_mutex -> cpus_rwsem -> jump_label_mutex -> text_mutex
      
      For kprobes which hook on an ftrace function trace point, it's required to
      drop cpus_rwsem before calling into the ftrace code to avoid a deadlock on
      the func_hash->regex_lock.
      
      [ Steven: Ftrace interaction fixes ]
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
      Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Acked-by: default avatarIngo Molnar <mingo@kernel.org>
      Acked-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Sebastian Siewior <bigeasy@linutronix.de>
      Link: http://lkml.kernel.org/r/20170524081549.104864779@linutronix.de
      2d1e38f5
  24. 18 May, 2017 2 commits
  25. 20 Apr, 2017 3 commits