From: Arnaldo Carvalho de Melo <acme@kernel•org>
To: Ingo Molnar <mingo@kernel•org>
Cc: linux-kernel@vger•kernel.org,
"Naveen N. Rao" <naveen.n.rao@linux•vnet.ibm.com>,
Ananth N Mavinakayanahalli <ananth@linux•vnet.ibm.com>,
Michael Ellerman <mpe@ellerman•id.au>,
Steven Rostedt <rostedt@goodmis•org>,
linuxppc-dev@lists•ozlabs.org,
Arnaldo Carvalho de Melo <acme@redhat•com>
Subject: [PATCH 25/35] kretprobes: Ensure probe location is at function entry
Date: Mon, 6 Mar 2017 16:38:15 -0300 [thread overview]
Message-ID: <20170306193825.24011-26-acme@kernel.org> (raw)
In-Reply-To: <20170306193825.24011-1-acme@kernel.org>
From: "Naveen N. Rao" <naveen.n.rao@linux•vnet.ibm.com>
kretprobes can be registered by specifying an absolute address or by
specifying offset to a symbol. However, we need to ensure this falls at
function entry so as to be able to determine the return address.
Validate the same during kretprobe registration. By default, there
should not be any offset from a function entry, as determined through a
kallsyms_lookup(). Introduce arch_function_offset_within_entry() as a
way for architectures to override this.
Signed-off-by: Naveen N. Rao <naveen.n.rao@linux•vnet.ibm.com>
Acked-by: Masami Hiramatsu <mhiramat@kernel•org>
Cc: Ananth N Mavinakayanahalli <ananth@linux•vnet.ibm.com>
Cc: Michael Ellerman <mpe@ellerman•id.au>
Cc: Steven Rostedt <rostedt@goodmis•org>
Cc: linuxppc-dev@lists•ozlabs.org
Link: http://lkml.kernel.org/r/f1583bc4839a3862cfc2acefcc56f9c8837fa2ba.1487770934.git.naveen.n.rao@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat•com>
---
include/linux/kprobes.h | 1 +
kernel/kprobes.c | 13 +++++++++++++
2 files changed, 14 insertions(+)
diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h
index c328e4f7dcad..177bdf6c6aeb 100644
--- a/include/linux/kprobes.h
+++ b/include/linux/kprobes.h
@@ -267,6 +267,7 @@ extern int arch_init_kprobes(void);
extern void show_registers(struct pt_regs *regs);
extern void kprobes_inc_nmissed_count(struct kprobe *p);
extern bool arch_within_kprobe_blacklist(unsigned long addr);
+extern bool arch_function_offset_within_entry(unsigned long offset);
extern bool within_kprobe_blacklist(unsigned long addr);
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 699c5bc51a92..448759d4a263 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -1875,12 +1875,25 @@ static int pre_handler_kretprobe(struct kprobe *p, struct pt_regs *regs)
}
NOKPROBE_SYMBOL(pre_handler_kretprobe);
+bool __weak arch_function_offset_within_entry(unsigned long offset)
+{
+ return !offset;
+}
+
int register_kretprobe(struct kretprobe *rp)
{
int ret = 0;
struct kretprobe_instance *inst;
int i;
void *addr;
+ unsigned long offset;
+
+ addr = kprobe_addr(&rp->kp);
+ if (!kallsyms_lookup_size_offset((unsigned long)addr, NULL, &offset))
+ return -EINVAL;
+
+ if (!arch_function_offset_within_entry(offset))
+ return -EINVAL;
if (kretprobe_blacklist_size) {
addr = kprobe_addr(&rp->kp);
--
2.9.3
next prev parent reply other threads:[~2017-03-06 19:38 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-06 19:37 [GIT PULL 00/35] perf/core improvements and fixes Arnaldo Carvalho de Melo
2017-03-06 19:38 ` Arnaldo Carvalho de Melo [this message]
2017-03-06 19:38 ` [PATCH 26/35] trace/kprobes: Allow return probes with offsets and absolute addresses Arnaldo Carvalho de Melo
2017-03-06 19:38 ` [PATCH 27/35] perf probe: Generalize probe event file open routine Arnaldo Carvalho de Melo
2017-03-06 19:38 ` [PATCH 29/35] trace/kprobes: Add back warning about offset in return probes Arnaldo Carvalho de Melo
2017-03-07 7:17 ` [GIT PULL 00/35] perf/core improvements and fixes Ingo Molnar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170306193825.24011-26-acme@kernel.org \
--to=acme@kernel$(echo .)org \
--cc=acme@redhat$(echo .)com \
--cc=ananth@linux$(echo .)vnet.ibm.com \
--cc=linux-kernel@vger$(echo .)kernel.org \
--cc=linuxppc-dev@lists$(echo .)ozlabs.org \
--cc=mingo@kernel$(echo .)org \
--cc=mpe@ellerman$(echo .)id.au \
--cc=naveen.n.rao@linux$(echo .)vnet.ibm.com \
--cc=rostedt@goodmis$(echo .)org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox