Commit 9c89bb8e authored by Masami Hiramatsu's avatar Masami Hiramatsu Committed by Steven Rostedt (VMware)

kprobes: treewide: Cleanup the error messages for kprobes

This clean up the error/notification messages in kprobes related code.
Basically this defines 'pr_fmt()' macros for each files and update
the messages which describes

 - what happened,
 - what is the kernel going to do or not do,
 - is the kernel fine,
 - what can the user do about it.

Also, if the message is not needed (e.g. the function returns unique
error code, or other error message is already shown.) remove it,
and replace the message with WARN_*() macros if suitable.

Link: https://lkml.kernel.org/r/163163036568.489837.14085396178727185469.stgit@devnote2Signed-off-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
parent 4402deae
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
* Copyright (C) 2007 Marvell Ltd. * Copyright (C) 2007 Marvell Ltd.
*/ */
#define pr_fmt(fmt) "kprobes: " fmt
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/kprobes.h> #include <linux/kprobes.h>
#include <linux/module.h> #include <linux/module.h>
...@@ -278,7 +280,7 @@ void __kprobes kprobe_handler(struct pt_regs *regs) ...@@ -278,7 +280,7 @@ void __kprobes kprobe_handler(struct pt_regs *regs)
break; break;
case KPROBE_REENTER: case KPROBE_REENTER:
/* A nested probe was hit in FIQ, it is a BUG */ /* A nested probe was hit in FIQ, it is a BUG */
pr_warn("Unrecoverable kprobe detected.\n"); pr_warn("Failed to recover from reentered kprobes.\n");
dump_kprobe(p); dump_kprobe(p);
fallthrough; fallthrough;
default: default:
......
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
* Copyright (C) 2013 Linaro Limited. * Copyright (C) 2013 Linaro Limited.
* Author: Sandeepa Prabhu <sandeepa.prabhu@linaro.org> * Author: Sandeepa Prabhu <sandeepa.prabhu@linaro.org>
*/ */
#define pr_fmt(fmt) "kprobes: " fmt
#include <linux/extable.h> #include <linux/extable.h>
#include <linux/kasan.h> #include <linux/kasan.h>
#include <linux/kernel.h> #include <linux/kernel.h>
...@@ -218,7 +221,7 @@ static int __kprobes reenter_kprobe(struct kprobe *p, ...@@ -218,7 +221,7 @@ static int __kprobes reenter_kprobe(struct kprobe *p,
break; break;
case KPROBE_HIT_SS: case KPROBE_HIT_SS:
case KPROBE_REENTER: case KPROBE_REENTER:
pr_warn("Unrecoverable kprobe detected.\n"); pr_warn("Failed to recover from reentered kprobes.\n");
dump_kprobe(p); dump_kprobe(p);
BUG(); BUG();
break; break;
......
// SPDX-License-Identifier: GPL-2.0+ // SPDX-License-Identifier: GPL-2.0+
#define pr_fmt(fmt) "kprobes: " fmt
#include <linux/kprobes.h> #include <linux/kprobes.h>
#include <linux/extable.h> #include <linux/extable.h>
#include <linux/slab.h> #include <linux/slab.h>
...@@ -77,10 +79,8 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p) ...@@ -77,10 +79,8 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p)
{ {
unsigned long probe_addr = (unsigned long)p->addr; unsigned long probe_addr = (unsigned long)p->addr;
if (probe_addr & 0x1) { if (probe_addr & 0x1)
pr_warn("Address not aligned.\n"); return -EILSEQ;
return -EINVAL;
}
/* copy instruction */ /* copy instruction */
p->opcode = le32_to_cpu(*p->addr); p->opcode = le32_to_cpu(*p->addr);
...@@ -225,7 +225,7 @@ static int __kprobes reenter_kprobe(struct kprobe *p, ...@@ -225,7 +225,7 @@ static int __kprobes reenter_kprobe(struct kprobe *p,
break; break;
case KPROBE_HIT_SS: case KPROBE_HIT_SS:
case KPROBE_REENTER: case KPROBE_REENTER:
pr_warn("Unrecoverable kprobe detected.\n"); pr_warn("Failed to recover from reentered kprobes.\n");
dump_kprobe(p); dump_kprobe(p);
BUG(); BUG();
break; break;
......
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
* Copyright (C) IBM Corporation, 2002, 2004 * Copyright (C) IBM Corporation, 2002, 2004
*/ */
#define pr_fmt(fmt) "kprobes: " fmt
#include <linux/kprobes.h> #include <linux/kprobes.h>
#include <linux/preempt.h> #include <linux/preempt.h>
#include <linux/uaccess.h> #include <linux/uaccess.h>
...@@ -80,8 +82,7 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p) ...@@ -80,8 +82,7 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p)
insn = p->addr[0]; insn = p->addr[0];
if (insn_has_ll_or_sc(insn)) { if (insn_has_ll_or_sc(insn)) {
pr_notice("Kprobes for ll and sc instructions are not" pr_notice("Kprobes for ll and sc instructions are not supported\n");
"supported\n");
ret = -EINVAL; ret = -EINVAL;
goto out; goto out;
} }
...@@ -219,7 +220,7 @@ static int evaluate_branch_instruction(struct kprobe *p, struct pt_regs *regs, ...@@ -219,7 +220,7 @@ static int evaluate_branch_instruction(struct kprobe *p, struct pt_regs *regs,
return 0; return 0;
unaligned: unaligned:
pr_notice("%s: unaligned epc - sending SIGBUS.\n", current->comm); pr_notice("Failed to emulate branch instruction because of unaligned epc - sending SIGBUS to %s.\n", current->comm);
force_sig(SIGBUS); force_sig(SIGBUS);
return -EFAULT; return -EFAULT;
...@@ -238,10 +239,8 @@ static void prepare_singlestep(struct kprobe *p, struct pt_regs *regs, ...@@ -238,10 +239,8 @@ static void prepare_singlestep(struct kprobe *p, struct pt_regs *regs,
regs->cp0_epc = (unsigned long)p->addr; regs->cp0_epc = (unsigned long)p->addr;
else if (insn_has_delayslot(p->opcode)) { else if (insn_has_delayslot(p->opcode)) {
ret = evaluate_branch_instruction(p, regs, kcb); ret = evaluate_branch_instruction(p, regs, kcb);
if (ret < 0) { if (ret < 0)
pr_notice("Kprobes: Error in evaluating branch\n");
return; return;
}
} }
regs->cp0_epc = (unsigned long)&p->ainsn.insn[0]; regs->cp0_epc = (unsigned long)&p->ainsn.insn[0];
} }
......
// SPDX-License-Identifier: GPL-2.0+ // SPDX-License-Identifier: GPL-2.0+
#define pr_fmt(fmt) "kprobes: " fmt
#include <linux/kprobes.h> #include <linux/kprobes.h>
#include <linux/extable.h> #include <linux/extable.h>
#include <linux/slab.h> #include <linux/slab.h>
...@@ -50,11 +52,8 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p) ...@@ -50,11 +52,8 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p)
{ {
unsigned long probe_addr = (unsigned long)p->addr; unsigned long probe_addr = (unsigned long)p->addr;
if (probe_addr & 0x1) { if (probe_addr & 0x1)
pr_warn("Address not aligned.\n"); return -EILSEQ;
return -EINVAL;
}
/* copy instruction */ /* copy instruction */
p->opcode = *p->addr; p->opcode = *p->addr;
...@@ -191,7 +190,7 @@ static int __kprobes reenter_kprobe(struct kprobe *p, ...@@ -191,7 +190,7 @@ static int __kprobes reenter_kprobe(struct kprobe *p,
break; break;
case KPROBE_HIT_SS: case KPROBE_HIT_SS:
case KPROBE_REENTER: case KPROBE_REENTER:
pr_warn("Unrecoverable kprobe detected.\n"); pr_warn("Failed to recover from reentered kprobes.\n");
dump_kprobe(p); dump_kprobe(p);
BUG(); BUG();
break; break;
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
* s390 port, used ppc64 as template. Mike Grundy <grundym@us.ibm.com> * s390 port, used ppc64 as template. Mike Grundy <grundym@us.ibm.com>
*/ */
#define pr_fmt(fmt) "kprobes: " fmt
#include <linux/moduleloader.h> #include <linux/moduleloader.h>
#include <linux/kprobes.h> #include <linux/kprobes.h>
#include <linux/ptrace.h> #include <linux/ptrace.h>
...@@ -259,7 +261,7 @@ static void kprobe_reenter_check(struct kprobe_ctlblk *kcb, struct kprobe *p) ...@@ -259,7 +261,7 @@ static void kprobe_reenter_check(struct kprobe_ctlblk *kcb, struct kprobe *p)
* is a BUG. The code path resides in the .kprobes.text * is a BUG. The code path resides in the .kprobes.text
* section and is executed with interrupts disabled. * section and is executed with interrupts disabled.
*/ */
pr_err("Invalid kprobe detected.\n"); pr_err("Failed to recover from reentered kprobes.\n");
dump_kprobe(p); dump_kprobe(p);
BUG(); BUG();
} }
......
...@@ -18,6 +18,9 @@ ...@@ -18,6 +18,9 @@
* <jkenisto@us.ibm.com> and Prasanna S Panchamukhi * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
* <prasanna@in.ibm.com> added function-return probes. * <prasanna@in.ibm.com> added function-return probes.
*/ */
#define pr_fmt(fmt) "kprobes: " fmt
#include <linux/kprobes.h> #include <linux/kprobes.h>
#include <linux/hash.h> #include <linux/hash.h>
#include <linux/init.h> #include <linux/init.h>
...@@ -892,7 +895,7 @@ static void optimize_all_kprobes(void) ...@@ -892,7 +895,7 @@ static void optimize_all_kprobes(void)
optimize_kprobe(p); optimize_kprobe(p);
} }
cpus_read_unlock(); cpus_read_unlock();
printk(KERN_INFO "Kprobes globally optimized\n"); pr_info("kprobe jump-optimization is enabled. All kprobes are optimized if possible.\n");
out: out:
mutex_unlock(&kprobe_mutex); mutex_unlock(&kprobe_mutex);
} }
...@@ -925,7 +928,7 @@ static void unoptimize_all_kprobes(void) ...@@ -925,7 +928,7 @@ static void unoptimize_all_kprobes(void)
/* Wait for unoptimizing completion */ /* Wait for unoptimizing completion */
wait_for_kprobe_optimizer(); wait_for_kprobe_optimizer();
printk(KERN_INFO "Kprobes globally unoptimized\n"); pr_info("kprobe jump-optimization is disabled. All kprobes are based on software breakpoint.\n");
} }
static DEFINE_MUTEX(kprobe_sysctl_mutex); static DEFINE_MUTEX(kprobe_sysctl_mutex);
...@@ -1003,7 +1006,7 @@ static int reuse_unused_kprobe(struct kprobe *ap) ...@@ -1003,7 +1006,7 @@ static int reuse_unused_kprobe(struct kprobe *ap)
* unregistered. * unregistered.
* Thus there should be no chance to reuse unused kprobe. * Thus there should be no chance to reuse unused kprobe.
*/ */
printk(KERN_ERR "Error: There should be no unused kprobe here.\n"); WARN_ON_ONCE(1);
return -EINVAL; return -EINVAL;
} }
...@@ -1040,18 +1043,13 @@ static int __arm_kprobe_ftrace(struct kprobe *p, struct ftrace_ops *ops, ...@@ -1040,18 +1043,13 @@ static int __arm_kprobe_ftrace(struct kprobe *p, struct ftrace_ops *ops,
int ret = 0; int ret = 0;
ret = ftrace_set_filter_ip(ops, (unsigned long)p->addr, 0, 0); ret = ftrace_set_filter_ip(ops, (unsigned long)p->addr, 0, 0);
if (ret) { if (WARN_ONCE(ret < 0, "Failed to arm kprobe-ftrace at %pS (error %d)\n", p->addr, ret))
pr_debug("Failed to arm kprobe-ftrace at %pS (%d)\n",
p->addr, ret);
return ret; return ret;
}
if (*cnt == 0) { if (*cnt == 0) {
ret = register_ftrace_function(ops); ret = register_ftrace_function(ops);
if (ret) { if (WARN(ret < 0, "Failed to register kprobe-ftrace (error %d)\n", ret))
pr_debug("Failed to init kprobe-ftrace (%d)\n", ret);
goto err_ftrace; goto err_ftrace;
}
} }
(*cnt)++; (*cnt)++;
...@@ -1083,14 +1081,14 @@ static int __disarm_kprobe_ftrace(struct kprobe *p, struct ftrace_ops *ops, ...@@ -1083,14 +1081,14 @@ static int __disarm_kprobe_ftrace(struct kprobe *p, struct ftrace_ops *ops,
if (*cnt == 1) { if (*cnt == 1) {
ret = unregister_ftrace_function(ops); ret = unregister_ftrace_function(ops);
if (WARN(ret < 0, "Failed to unregister kprobe-ftrace (%d)\n", ret)) if (WARN(ret < 0, "Failed to unregister kprobe-ftrace (error %d)\n", ret))
return ret; return ret;
} }
(*cnt)--; (*cnt)--;
ret = ftrace_set_filter_ip(ops, (unsigned long)p->addr, 1, 0); ret = ftrace_set_filter_ip(ops, (unsigned long)p->addr, 1, 0);
WARN_ONCE(ret < 0, "Failed to disarm kprobe-ftrace at %pS (%d)\n", WARN_ONCE(ret < 0, "Failed to disarm kprobe-ftrace at %pS (error %d)\n",
p->addr, ret); p->addr, ret);
return ret; return ret;
} }
...@@ -1880,7 +1878,7 @@ unsigned long __kretprobe_trampoline_handler(struct pt_regs *regs, ...@@ -1880,7 +1878,7 @@ unsigned long __kretprobe_trampoline_handler(struct pt_regs *regs,
node = node->next; node = node->next;
} }
pr_err("Oops! Kretprobe fails to find correct return address.\n"); pr_err("kretprobe: Return address not found, not execute handler. Maybe there is a bug in the kernel.\n");
BUG_ON(1); BUG_ON(1);
found: found:
...@@ -2209,8 +2207,7 @@ EXPORT_SYMBOL_GPL(enable_kprobe); ...@@ -2209,8 +2207,7 @@ EXPORT_SYMBOL_GPL(enable_kprobe);
/* Caller must NOT call this in usual path. This is only for critical case */ /* Caller must NOT call this in usual path. This is only for critical case */
void dump_kprobe(struct kprobe *kp) void dump_kprobe(struct kprobe *kp)
{ {
pr_err("Dumping kprobe:\n"); pr_err("Dump kprobe:\n.symbol_name = %s, .offset = %x, .addr = %pS\n",
pr_err("Name: %s\nOffset: %x\nAddress: %pS\n",
kp->symbol_name, kp->offset, kp->addr); kp->symbol_name, kp->offset, kp->addr);
} }
NOKPROBE_SYMBOL(dump_kprobe); NOKPROBE_SYMBOL(dump_kprobe);
...@@ -2473,8 +2470,7 @@ static int __init init_kprobes(void) ...@@ -2473,8 +2470,7 @@ static int __init init_kprobes(void)
err = populate_kprobe_blacklist(__start_kprobe_blacklist, err = populate_kprobe_blacklist(__start_kprobe_blacklist,
__stop_kprobe_blacklist); __stop_kprobe_blacklist);
if (err) { if (err) {
pr_err("kprobes: failed to populate blacklist: %d\n", err); pr_err("Failed to populate blacklist (error %d), kprobes not restricted, be careful using them!\n", err);
pr_err("Please take care of using kprobes.\n");
} }
if (kretprobe_blacklist_size) { if (kretprobe_blacklist_size) {
...@@ -2483,7 +2479,7 @@ static int __init init_kprobes(void) ...@@ -2483,7 +2479,7 @@ static int __init init_kprobes(void)
kretprobe_blacklist[i].addr = kretprobe_blacklist[i].addr =
kprobe_lookup_name(kretprobe_blacklist[i].name, 0); kprobe_lookup_name(kretprobe_blacklist[i].name, 0);
if (!kretprobe_blacklist[i].addr) if (!kretprobe_blacklist[i].addr)
printk("kretprobe: lookup failed: %s\n", pr_err("Failed to lookup symbol '%s' for kretprobe blacklist. Maybe the target function is removed or renamed.\n",
kretprobe_blacklist[i].name); kretprobe_blacklist[i].name);
} }
} }
...@@ -2687,7 +2683,7 @@ static int arm_all_kprobes(void) ...@@ -2687,7 +2683,7 @@ static int arm_all_kprobes(void)
} }
if (errors) if (errors)
pr_warn("Kprobes globally enabled, but failed to arm %d out of %d probes\n", pr_warn("Kprobes globally enabled, but failed to enable %d out of %d probes. Please check which kprobes are kept disabled via debugfs.\n",
errors, total); errors, total);
else else
pr_info("Kprobes globally enabled\n"); pr_info("Kprobes globally enabled\n");
...@@ -2730,7 +2726,7 @@ static int disarm_all_kprobes(void) ...@@ -2730,7 +2726,7 @@ static int disarm_all_kprobes(void)
} }
if (errors) if (errors)
pr_warn("Kprobes globally disabled, but failed to disarm %d out of %d probes\n", pr_warn("Kprobes globally disabled, but failed to disable %d out of %d probes. Please check which kprobes are kept enabled via debugfs.\n",
errors, total); errors, total);
else else
pr_info("Kprobes globally disabled\n"); pr_info("Kprobes globally disabled\n");
......
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