All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kprobes: Print an error if probe is rejected
@ 2021-06-10  8:56 Naveen N. Rao
  2021-06-10 10:16 ` Masami Hiramatsu
  0 siblings, 1 reply; 13+ messages in thread
From: Naveen N. Rao @ 2021-06-10  8:56 UTC (permalink / raw)
  To: linux-kernel
  Cc: Masami Hiramatsu, Peter Zijlstra, Steven Rostedt, Aneesh Kumar K.V

When probing at different locations in the kernel, it is not always
evident if the location can be probed or not. As an example:

    $ perf probe __radix__flush_tlb_range:35
    Failed to write event: Invalid argument
      Error: Failed to add events.

The probed line above is:
     35         if (!mmu_has_feature(MMU_FTR_GTSE) && type == FLUSH_TYPE_GLOBAL) {

This ends up trying to probe on BUILD_BUG_ON(), which is rejected.
However, the user receives no indication at all as to why the probe
failed. Print an error in such cases so that it is clear that the probe
was rejected.

Reported-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
---
 kernel/kprobes.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index e41385afe79dc5..7c8929165924ed 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -1542,8 +1542,10 @@ static int check_kprobe_address_safe(struct kprobe *p,
 	int ret;
 
 	ret = arch_check_ftrace_location(p);
-	if (ret)
+	if (ret) {
+		pr_err("kprobes: can't probe at the provided ftrace location\n");
 		return ret;
+	}
 	jump_label_lock();
 	preempt_disable();
 
@@ -1552,6 +1554,7 @@ static int check_kprobe_address_safe(struct kprobe *p,
 	    within_kprobe_blacklist((unsigned long) p->addr) ||
 	    jump_label_text_reserved(p->addr, p->addr) ||
 	    find_bug((unsigned long)p->addr)) {
+		pr_err("kprobes: can't probe at address in reject list\n");
 		ret = -EINVAL;
 		goto out;
 	}
@@ -1976,8 +1979,10 @@ int register_kretprobe(struct kretprobe *rp)
 	void *addr;
 
 	ret = kprobe_on_func_entry(rp->kp.addr, rp->kp.symbol_name, rp->kp.offset);
-	if (ret)
+	if (ret) {
+		pr_err("kretprobes: can't probe at address outside function entry\n");
 		return ret;
+	}
 
 	/* If only rp->kp.addr is specified, check reregistering kprobes */
 	if (rp->kp.addr && warn_kprobe_rereg(&rp->kp))
@@ -1989,8 +1994,10 @@ int register_kretprobe(struct kretprobe *rp)
 			return PTR_ERR(addr);
 
 		for (i = 0; kretprobe_blacklist[i].name != NULL; i++) {
-			if (kretprobe_blacklist[i].addr == addr)
+			if (kretprobe_blacklist[i].addr == addr) {
+				pr_err("kretprobes: can't probe at address in reject list\n");
 				return -EINVAL;
+			}
 		}
 	}
 

base-commit: 2e38eb04c95e5546b71bb86ee699a891c7d212b5
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2021-06-21 12:54 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-10  8:56 [PATCH] kprobes: Print an error if probe is rejected Naveen N. Rao
2021-06-10 10:16 ` Masami Hiramatsu
2021-06-10 17:33   ` Steven Rostedt
2021-06-11  1:50     ` Masami Hiramatsu
2021-06-11 13:55   ` Naveen N. Rao
2021-06-11 19:40     ` Steven Rostedt
2021-06-14 15:30       ` Naveen N. Rao
2021-06-18 16:15         ` Masami Hiramatsu
2021-06-21  9:36           ` Naveen N. Rao
2021-06-21 12:54             ` Masami Hiramatsu
2021-06-12  1:13     ` Masami Hiramatsu
2021-06-14 15:37       ` Naveen N. Rao
2021-06-15  5:42         ` Masami Hiramatsu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.