Commit e3a44ded authored by Masami Hiramatsu's avatar Masami Hiramatsu Committed by Stefan Bader

kprobes: Fix error check when reusing optimized probes

BugLink: https://bugs.launchpad.net/bugs/1828420

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@devnote2Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
Signed-off-by: default avatarStefan Bader <stefan.bader@canonical.com>
parent 0771ac69
...@@ -668,7 +668,6 @@ static void unoptimize_kprobe(struct kprobe *p, bool force) ...@@ -668,7 +668,6 @@ static void unoptimize_kprobe(struct kprobe *p, bool force)
static int reuse_unused_kprobe(struct kprobe *ap) static int reuse_unused_kprobe(struct kprobe *ap)
{ {
struct optimized_kprobe *op; struct optimized_kprobe *op;
int ret;
BUG_ON(!kprobe_unused(ap)); BUG_ON(!kprobe_unused(ap));
/* /*
...@@ -682,9 +681,8 @@ static int reuse_unused_kprobe(struct kprobe *ap) ...@@ -682,9 +681,8 @@ static int reuse_unused_kprobe(struct kprobe *ap)
/* Enable the probe again */ /* Enable the probe again */
ap->flags &= ~KPROBE_FLAG_DISABLED; ap->flags &= ~KPROBE_FLAG_DISABLED;
/* Optimize it again (remove from op->list) */ /* Optimize it again (remove from op->list) */
ret = kprobe_optready(ap); if (!kprobe_optready(ap))
if (ret) return -EINVAL;
return ret;
optimize_kprobe(ap); optimize_kprobe(ap);
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment