Skip to content

Commit 9c89bb8

Browse files
mhiramatrostedt
authored andcommitted
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@devnote2 Signed-off-by: Masami Hiramatsu <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 4402dea commit 9c89bb8

File tree

7 files changed

+41
-40
lines changed

7 files changed

+41
-40
lines changed

arch/arm/probes/kprobes/core.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
* Copyright (C) 2007 Marvell Ltd.
1212
*/
1313

14+
#define pr_fmt(fmt) "kprobes: " fmt
15+
1416
#include <linux/kernel.h>
1517
#include <linux/kprobes.h>
1618
#include <linux/module.h>
@@ -278,7 +280,7 @@ void __kprobes kprobe_handler(struct pt_regs *regs)
278280
break;
279281
case KPROBE_REENTER:
280282
/* A nested probe was hit in FIQ, it is a BUG */
281-
pr_warn("Unrecoverable kprobe detected.\n");
283+
pr_warn("Failed to recover from reentered kprobes.\n");
282284
dump_kprobe(p);
283285
fallthrough;
284286
default:

arch/arm64/kernel/probes/kprobes.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
* Copyright (C) 2013 Linaro Limited.
88
* Author: Sandeepa Prabhu <[email protected]>
99
*/
10+
11+
#define pr_fmt(fmt) "kprobes: " fmt
12+
1013
#include <linux/extable.h>
1114
#include <linux/kasan.h>
1215
#include <linux/kernel.h>
@@ -218,7 +221,7 @@ static int __kprobes reenter_kprobe(struct kprobe *p,
218221
break;
219222
case KPROBE_HIT_SS:
220223
case KPROBE_REENTER:
221-
pr_warn("Unrecoverable kprobe detected.\n");
224+
pr_warn("Failed to recover from reentered kprobes.\n");
222225
dump_kprobe(p);
223226
BUG();
224227
break;

arch/csky/kernel/probes/kprobes.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// SPDX-License-Identifier: GPL-2.0+
22

3+
#define pr_fmt(fmt) "kprobes: " fmt
4+
35
#include <linux/kprobes.h>
46
#include <linux/extable.h>
57
#include <linux/slab.h>
@@ -77,10 +79,8 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p)
7779
{
7880
unsigned long probe_addr = (unsigned long)p->addr;
7981

80-
if (probe_addr & 0x1) {
81-
pr_warn("Address not aligned.\n");
82-
return -EINVAL;
83-
}
82+
if (probe_addr & 0x1)
83+
return -EILSEQ;
8484

8585
/* copy instruction */
8686
p->opcode = le32_to_cpu(*p->addr);
@@ -225,7 +225,7 @@ static int __kprobes reenter_kprobe(struct kprobe *p,
225225
break;
226226
case KPROBE_HIT_SS:
227227
case KPROBE_REENTER:
228-
pr_warn("Unrecoverable kprobe detected.\n");
228+
pr_warn("Failed to recover from reentered kprobes.\n");
229229
dump_kprobe(p);
230230
BUG();
231231
break;

arch/mips/kernel/kprobes.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
* Copyright (C) IBM Corporation, 2002, 2004
1212
*/
1313

14+
#define pr_fmt(fmt) "kprobes: " fmt
15+
1416
#include <linux/kprobes.h>
1517
#include <linux/preempt.h>
1618
#include <linux/uaccess.h>
@@ -80,8 +82,7 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p)
8082
insn = p->addr[0];
8183

8284
if (insn_has_ll_or_sc(insn)) {
83-
pr_notice("Kprobes for ll and sc instructions are not"
84-
"supported\n");
85+
pr_notice("Kprobes for ll and sc instructions are not supported\n");
8586
ret = -EINVAL;
8687
goto out;
8788
}
@@ -219,7 +220,7 @@ static int evaluate_branch_instruction(struct kprobe *p, struct pt_regs *regs,
219220
return 0;
220221

221222
unaligned:
222-
pr_notice("%s: unaligned epc - sending SIGBUS.\n", current->comm);
223+
pr_notice("Failed to emulate branch instruction because of unaligned epc - sending SIGBUS to %s.\n", current->comm);
223224
force_sig(SIGBUS);
224225
return -EFAULT;
225226

@@ -238,10 +239,8 @@ static void prepare_singlestep(struct kprobe *p, struct pt_regs *regs,
238239
regs->cp0_epc = (unsigned long)p->addr;
239240
else if (insn_has_delayslot(p->opcode)) {
240241
ret = evaluate_branch_instruction(p, regs, kcb);
241-
if (ret < 0) {
242-
pr_notice("Kprobes: Error in evaluating branch\n");
242+
if (ret < 0)
243243
return;
244-
}
245244
}
246245
regs->cp0_epc = (unsigned long)&p->ainsn.insn[0];
247246
}

arch/riscv/kernel/probes/kprobes.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// SPDX-License-Identifier: GPL-2.0+
22

3+
#define pr_fmt(fmt) "kprobes: " fmt
4+
35
#include <linux/kprobes.h>
46
#include <linux/extable.h>
57
#include <linux/slab.h>
@@ -50,11 +52,8 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p)
5052
{
5153
unsigned long probe_addr = (unsigned long)p->addr;
5254

53-
if (probe_addr & 0x1) {
54-
pr_warn("Address not aligned.\n");
55-
56-
return -EINVAL;
57-
}
55+
if (probe_addr & 0x1)
56+
return -EILSEQ;
5857

5958
/* copy instruction */
6059
p->opcode = *p->addr;
@@ -191,7 +190,7 @@ static int __kprobes reenter_kprobe(struct kprobe *p,
191190
break;
192191
case KPROBE_HIT_SS:
193192
case KPROBE_REENTER:
194-
pr_warn("Unrecoverable kprobe detected.\n");
193+
pr_warn("Failed to recover from reentered kprobes.\n");
195194
dump_kprobe(p);
196195
BUG();
197196
break;

arch/s390/kernel/kprobes.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
* s390 port, used ppc64 as template. Mike Grundy <[email protected]>
88
*/
99

10+
#define pr_fmt(fmt) "kprobes: " fmt
11+
1012
#include <linux/moduleloader.h>
1113
#include <linux/kprobes.h>
1214
#include <linux/ptrace.h>
@@ -259,7 +261,7 @@ static void kprobe_reenter_check(struct kprobe_ctlblk *kcb, struct kprobe *p)
259261
* is a BUG. The code path resides in the .kprobes.text
260262
* section and is executed with interrupts disabled.
261263
*/
262-
pr_err("Invalid kprobe detected.\n");
264+
pr_err("Failed to recover from reentered kprobes.\n");
263265
dump_kprobe(p);
264266
BUG();
265267
}

kernel/kprobes.c

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
* <[email protected]> and Prasanna S Panchamukhi
1919
* <[email protected]> added function-return probes.
2020
*/
21+
22+
#define pr_fmt(fmt) "kprobes: " fmt
23+
2124
#include <linux/kprobes.h>
2225
#include <linux/hash.h>
2326
#include <linux/init.h>
@@ -892,7 +895,7 @@ static void optimize_all_kprobes(void)
892895
optimize_kprobe(p);
893896
}
894897
cpus_read_unlock();
895-
printk(KERN_INFO "Kprobes globally optimized\n");
898+
pr_info("kprobe jump-optimization is enabled. All kprobes are optimized if possible.\n");
896899
out:
897900
mutex_unlock(&kprobe_mutex);
898901
}
@@ -925,7 +928,7 @@ static void unoptimize_all_kprobes(void)
925928

926929
/* Wait for unoptimizing completion */
927930
wait_for_kprobe_optimizer();
928-
printk(KERN_INFO "Kprobes globally unoptimized\n");
931+
pr_info("kprobe jump-optimization is disabled. All kprobes are based on software breakpoint.\n");
929932
}
930933

931934
static DEFINE_MUTEX(kprobe_sysctl_mutex);
@@ -1003,7 +1006,7 @@ static int reuse_unused_kprobe(struct kprobe *ap)
10031006
* unregistered.
10041007
* Thus there should be no chance to reuse unused kprobe.
10051008
*/
1006-
printk(KERN_ERR "Error: There should be no unused kprobe here.\n");
1009+
WARN_ON_ONCE(1);
10071010
return -EINVAL;
10081011
}
10091012

@@ -1040,18 +1043,13 @@ static int __arm_kprobe_ftrace(struct kprobe *p, struct ftrace_ops *ops,
10401043
int ret = 0;
10411044

10421045
ret = ftrace_set_filter_ip(ops, (unsigned long)p->addr, 0, 0);
1043-
if (ret) {
1044-
pr_debug("Failed to arm kprobe-ftrace at %pS (%d)\n",
1045-
p->addr, ret);
1046+
if (WARN_ONCE(ret < 0, "Failed to arm kprobe-ftrace at %pS (error %d)\n", p->addr, ret))
10461047
return ret;
1047-
}
10481048

10491049
if (*cnt == 0) {
10501050
ret = register_ftrace_function(ops);
1051-
if (ret) {
1052-
pr_debug("Failed to init kprobe-ftrace (%d)\n", ret);
1051+
if (WARN(ret < 0, "Failed to register kprobe-ftrace (error %d)\n", ret))
10531052
goto err_ftrace;
1054-
}
10551053
}
10561054

10571055
(*cnt)++;
@@ -1083,14 +1081,14 @@ static int __disarm_kprobe_ftrace(struct kprobe *p, struct ftrace_ops *ops,
10831081

10841082
if (*cnt == 1) {
10851083
ret = unregister_ftrace_function(ops);
1086-
if (WARN(ret < 0, "Failed to unregister kprobe-ftrace (%d)\n", ret))
1084+
if (WARN(ret < 0, "Failed to unregister kprobe-ftrace (error %d)\n", ret))
10871085
return ret;
10881086
}
10891087

10901088
(*cnt)--;
10911089

10921090
ret = ftrace_set_filter_ip(ops, (unsigned long)p->addr, 1, 0);
1093-
WARN_ONCE(ret < 0, "Failed to disarm kprobe-ftrace at %pS (%d)\n",
1091+
WARN_ONCE(ret < 0, "Failed to disarm kprobe-ftrace at %pS (error %d)\n",
10941092
p->addr, ret);
10951093
return ret;
10961094
}
@@ -1880,7 +1878,7 @@ unsigned long __kretprobe_trampoline_handler(struct pt_regs *regs,
18801878

18811879
node = node->next;
18821880
}
1883-
pr_err("Oops! Kretprobe fails to find correct return address.\n");
1881+
pr_err("kretprobe: Return address not found, not execute handler. Maybe there is a bug in the kernel.\n");
18841882
BUG_ON(1);
18851883

18861884
found:
@@ -2209,8 +2207,7 @@ EXPORT_SYMBOL_GPL(enable_kprobe);
22092207
/* Caller must NOT call this in usual path. This is only for critical case */
22102208
void dump_kprobe(struct kprobe *kp)
22112209
{
2212-
pr_err("Dumping kprobe:\n");
2213-
pr_err("Name: %s\nOffset: %x\nAddress: %pS\n",
2210+
pr_err("Dump kprobe:\n.symbol_name = %s, .offset = %x, .addr = %pS\n",
22142211
kp->symbol_name, kp->offset, kp->addr);
22152212
}
22162213
NOKPROBE_SYMBOL(dump_kprobe);
@@ -2473,8 +2470,7 @@ static int __init init_kprobes(void)
24732470
err = populate_kprobe_blacklist(__start_kprobe_blacklist,
24742471
__stop_kprobe_blacklist);
24752472
if (err) {
2476-
pr_err("kprobes: failed to populate blacklist: %d\n", err);
2477-
pr_err("Please take care of using kprobes.\n");
2473+
pr_err("Failed to populate blacklist (error %d), kprobes not restricted, be careful using them!\n", err);
24782474
}
24792475

24802476
if (kretprobe_blacklist_size) {
@@ -2483,7 +2479,7 @@ static int __init init_kprobes(void)
24832479
kretprobe_blacklist[i].addr =
24842480
kprobe_lookup_name(kretprobe_blacklist[i].name, 0);
24852481
if (!kretprobe_blacklist[i].addr)
2486-
printk("kretprobe: lookup failed: %s\n",
2482+
pr_err("Failed to lookup symbol '%s' for kretprobe blacklist. Maybe the target function is removed or renamed.\n",
24872483
kretprobe_blacklist[i].name);
24882484
}
24892485
}
@@ -2687,7 +2683,7 @@ static int arm_all_kprobes(void)
26872683
}
26882684

26892685
if (errors)
2690-
pr_warn("Kprobes globally enabled, but failed to arm %d out of %d probes\n",
2686+
pr_warn("Kprobes globally enabled, but failed to enable %d out of %d probes. Please check which kprobes are kept disabled via debugfs.\n",
26912687
errors, total);
26922688
else
26932689
pr_info("Kprobes globally enabled\n");
@@ -2730,7 +2726,7 @@ static int disarm_all_kprobes(void)
27302726
}
27312727

27322728
if (errors)
2733-
pr_warn("Kprobes globally disabled, but failed to disarm %d out of %d probes\n",
2729+
pr_warn("Kprobes globally disabled, but failed to disable %d out of %d probes. Please check which kprobes are kept enabled via debugfs.\n",
27342730
errors, total);
27352731
else
27362732
pr_info("Kprobes globally disabled\n");

0 commit comments

Comments
 (0)