Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1581544
| From | "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 1/3] kretprobes: ensure probe location is at function entry |
| Date | 2017-02-15 19:20 +0100 |
| Message-ID | <tbclk-3oS-33@gated-at.bofh.it> (permalink) |
| References | <tbc1Z-32F-29@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
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>
---
powerpc64 ABIv2 will need to use the over-ride as we want to use the
local entry point which will be at an offset of 8 bytes from the
(global) entry point. I have a patch that I will post separately.
Thanks,
Naveen
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 8f6849084248..0c2489435117 100644
--- a/include/linux/kprobes.h
+++ b/include/linux/kprobes.h
@@ -266,6 +266,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 43460104f119..72ecbf5a6312 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -1834,12 +1834,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.11.0
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH] kretprobes: reject registration if a symbol offset is specified "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> - 2017-02-14 09:40 +0100
Re: [PATCH] kretprobes: reject registration if a symbol offset is specified Ananth N Mavinakayanahalli <ananth@linux.vnet.ibm.com> - 2017-02-14 09:50 +0100
Re: [PATCH] kretprobes: reject registration if a symbol offset is specified Masami Hiramatsu <mhiramat@kernel.org> - 2017-02-14 11:40 +0100
Re: [PATCH] kretprobes: reject registration if a symbol offset is specified "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> - 2017-02-15 19:00 +0100
[PATCH 3/3] perf: revert "perf probe: Fix probing kretprobes" "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> - 2017-02-15 19:20 +0100
Re: [PATCH 3/3] perf: revert "perf probe: Fix probing kretprobes" Masami Hiramatsu <mhiramat@kernel.org> - 2017-02-16 00:50 +0100
[PATCH 1/3] kretprobes: ensure probe location is at function entry "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> - 2017-02-15 19:20 +0100
[PATCH 2/3] trace/kprobes: allow return probes with offsets and absolute addresses "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> - 2017-02-15 19:20 +0100
Re: [PATCH 2/3] trace/kprobes: allow return probes with offsets and absolute addresses Masami Hiramatsu <mhiramat@kernel.org> - 2017-02-16 00:50 +0100
Re: [PATCH 1/3] kretprobes: ensure probe location is at function entry Masami Hiramatsu <mhiramat@kernel.org> - 2017-02-16 00:50 +0100
Re: [PATCH 1/3] kretprobes: ensure probe location is at function entry "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> - 2017-02-16 09:00 +0100
[PATCH 0/2] powerpc: kretprobe updates "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> - 2017-02-16 09:20 +0100
[PATCH 1/2] powerpc: kretprobes: override default function entry offset "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> - 2017-02-16 09:20 +0100
[PATCH 2/2] perf: powerpc: choose LEP with kretprobes "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> - 2017-02-16 09:20 +0100
Re: [PATCH 0/2] powerpc: kretprobe updates Masami Hiramatsu <mhiramat@kernel.org> - 2017-02-17 11:50 +0100
Re: [PATCH 0/2] powerpc: kretprobe updates Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-02-17 21:50 +0100
Re: [PATCH 0/2] powerpc: kretprobe updates Masami Hiramatsu <mhiramat@kernel.org> - 2017-02-19 05:50 +0100
Re: [PATCH 0/2] powerpc: kretprobe updates "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> - 2017-02-20 11:00 +0100
Re: [PATCH 0/2] powerpc: kretprobe updates Masami Hiramatsu <mhiramat@kernel.org> - 2017-02-21 14:10 +0100
Re: [PATCH 0/2] powerpc: kretprobe updates "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> - 2017-02-22 14:50 +0100
Re: [PATCH 0/2] powerpc: kretprobe updates "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> - 2017-02-20 10:50 +0100
Re: [PATCH 0/2] powerpc: kretprobe updates "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> - 2017-02-20 12:50 +0100
Re: [PATCH 0/2] powerpc: kretprobe updates Masami Hiramatsu <mhiramat@kernel.org> - 2017-02-21 14:10 +0100
Re: [PATCH] kretprobes: reject registration if a symbol offset is specified Masami Hiramatsu <mhiramat@kernel.org> - 2017-02-16 00:30 +0100
csiph-web