linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/3] kernel/kprobes: A few trivial updates to jprobes
@ 2017-07-07 17:07 Naveen N. Rao
  2017-07-07 17:07 ` [PATCH v2 1/3] kernel/kprobes: Rename [arch_]function_offset_within_entry() to [arch_]kprobe_on_func_entry() Naveen N. Rao
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Naveen N. Rao @ 2017-07-07 17:07 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: Masami Hiramatsu, Ananth N Mavinakayanahalli, linux-kernel

Here is v2 of the patch:
https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1434133.html

As suggested, the first two patches first clean up the existing jprobe
registration functions and rename function_offset_within_entry() to
kprobe_on_func_entry(). The last patch has been updated accordingly.

Thanks,
Naveen

Naveen N. Rao (3):
  kernel/kprobes: Rename [arch_]function_offset_within_entry() to
    [arch_]kprobe_on_func_entry()
  kernel/kprobes: Simplify register_jprobes()
  kernel/kprobes: Ensure that jprobe probepoints are at function entry

 arch/powerpc/kernel/kprobes.c |  2 +-
 include/linux/kprobes.h       |  4 ++--
 kernel/kprobes.c              | 42 ++++++++++++++++++++++++------------------
 kernel/trace/trace_kprobe.c   |  2 +-
 4 files changed, 28 insertions(+), 22 deletions(-)

-- 
2.13.2

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

* [PATCH v2 1/3] kernel/kprobes: Rename [arch_]function_offset_within_entry() to [arch_]kprobe_on_func_entry()
  2017-07-07 17:07 [PATCH v2 0/3] kernel/kprobes: A few trivial updates to jprobes Naveen N. Rao
@ 2017-07-07 17:07 ` Naveen N. Rao
  2017-07-08 11:10   ` [tip:perf/urgent] kprobes: " tip-bot for Naveen N. Rao
  2017-07-07 17:07 ` [PATCH v2 2/3] kernel/kprobes: Simplify register_jprobes() Naveen N. Rao
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Naveen N. Rao @ 2017-07-07 17:07 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: Masami Hiramatsu, Ananth N Mavinakayanahalli, linux-kernel

Rename function_offset_within_entry() to scope it to kprobe namespace by
using kprobe_ prefix, and to also simplify it.

Suggested-by: Ingo Molnar <mingo@kernel.org>
Suggested-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
---
 arch/powerpc/kernel/kprobes.c | 2 +-
 include/linux/kprobes.h       | 4 ++--
 kernel/kprobes.c              | 8 ++++----
 kernel/trace/trace_kprobe.c   | 2 +-
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobes.c
index 01addfb0ed0a..586508e949f0 100644
--- a/arch/powerpc/kernel/kprobes.c
+++ b/arch/powerpc/kernel/kprobes.c
@@ -221,7 +221,7 @@ static nokprobe_inline void set_current_kprobe(struct kprobe *p, struct pt_regs
 	kcb->kprobe_saved_msr = regs->msr;
 }
 
-bool arch_function_offset_within_entry(unsigned long offset)
+bool arch_kprobe_on_func_entry(unsigned long offset)
 {
 #ifdef PPC64_ELF_ABI_v2
 #ifdef CONFIG_KPROBES_ON_FTRACE
diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h
index 541df0b5b815..bd2684700b74 100644
--- a/include/linux/kprobes.h
+++ b/include/linux/kprobes.h
@@ -267,8 +267,8 @@ 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 function_offset_within_entry(kprobe_opcode_t *addr, const char *sym, unsigned long offset);
+extern bool arch_kprobe_on_func_entry(unsigned long offset);
+extern bool kprobe_on_func_entry(kprobe_opcode_t *addr, const char *sym, unsigned long offset);
 
 extern bool within_kprobe_blacklist(unsigned long addr);
 
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 6756d750b31b..a519219169fd 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -1888,12 +1888,12 @@ 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)
+bool __weak arch_kprobe_on_func_entry(unsigned long offset)
 {
 	return !offset;
 }
 
-bool function_offset_within_entry(kprobe_opcode_t *addr, const char *sym, unsigned long offset)
+bool kprobe_on_func_entry(kprobe_opcode_t *addr, const char *sym, unsigned long offset)
 {
 	kprobe_opcode_t *kp_addr = _kprobe_addr(addr, sym, offset);
 
@@ -1901,7 +1901,7 @@ bool function_offset_within_entry(kprobe_opcode_t *addr, const char *sym, unsign
 		return false;
 
 	if (!kallsyms_lookup_size_offset((unsigned long)kp_addr, NULL, &offset) ||
-						!arch_function_offset_within_entry(offset))
+						!arch_kprobe_on_func_entry(offset))
 		return false;
 
 	return true;
@@ -1914,7 +1914,7 @@ int register_kretprobe(struct kretprobe *rp)
 	int i;
 	void *addr;
 
-	if (!function_offset_within_entry(rp->kp.addr, rp->kp.symbol_name, rp->kp.offset))
+	if (!kprobe_on_func_entry(rp->kp.addr, rp->kp.symbol_name, rp->kp.offset))
 		return -EINVAL;
 
 	if (kretprobe_blacklist_size) {
diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
index b53c8d369163..2c5221819be5 100644
--- a/kernel/trace/trace_kprobe.c
+++ b/kernel/trace/trace_kprobe.c
@@ -720,7 +720,7 @@ static int create_trace_kprobe(int argc, char **argv)
 			return ret;
 		}
 		if (offset && is_return &&
-		    !function_offset_within_entry(NULL, symbol, offset)) {
+		    !kprobe_on_func_entry(NULL, symbol, offset)) {
 			pr_info("Given offset is not valid for return probe.\n");
 			return -EINVAL;
 		}
-- 
2.13.2

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

* [PATCH v2 2/3] kernel/kprobes: Simplify register_jprobes()
  2017-07-07 17:07 [PATCH v2 0/3] kernel/kprobes: A few trivial updates to jprobes Naveen N. Rao
  2017-07-07 17:07 ` [PATCH v2 1/3] kernel/kprobes: Rename [arch_]function_offset_within_entry() to [arch_]kprobe_on_func_entry() Naveen N. Rao
@ 2017-07-07 17:07 ` Naveen N. Rao
  2017-07-08 11:10   ` [tip:perf/urgent] kprobes: " tip-bot for Naveen N. Rao
  2017-07-07 17:07 ` [PATCH v2 3/3] kernel/kprobes: Ensure that jprobe probepoints are at function entry Naveen N. Rao
  2017-07-09 12:28 ` [PATCH v2 0/3] kernel/kprobes: A few trivial updates to jprobes Masami Hiramatsu
  3 siblings, 1 reply; 8+ messages in thread
From: Naveen N. Rao @ 2017-07-07 17:07 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: Masami Hiramatsu, Ananth N Mavinakayanahalli, linux-kernel

Re-factor jprobe registration functions as the current version is
getting too unwieldy. Move the actual jprobe registration to
register_jprobe() and re-organize code accordingly.

Suggested-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
---
 kernel/kprobes.c | 30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index a519219169fd..db3cd3e60bdd 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -1771,24 +1771,13 @@ unsigned long __weak arch_deref_entry_point(void *entry)
 
 int register_jprobes(struct jprobe **jps, int num)
 {
-	struct jprobe *jp;
 	int ret = 0, i;
 
 	if (num <= 0)
 		return -EINVAL;
+
 	for (i = 0; i < num; i++) {
-		unsigned long addr, offset;
-		jp = jps[i];
-		addr = arch_deref_entry_point(jp->entry);
-
-		/* Verify probepoint is a function entry point */
-		if (kallsyms_lookup_size_offset(addr, NULL, &offset) &&
-		    offset == 0) {
-			jp->kp.pre_handler = setjmp_pre_handler;
-			jp->kp.break_handler = longjmp_break_handler;
-			ret = register_kprobe(&jp->kp);
-		} else
-			ret = -EINVAL;
+		ret = register_jprobe(jps[i]);
 
 		if (ret < 0) {
 			if (i > 0)
@@ -1796,13 +1785,26 @@ int register_jprobes(struct jprobe **jps, int num)
 			break;
 		}
 	}
+
 	return ret;
 }
 EXPORT_SYMBOL_GPL(register_jprobes);
 
 int register_jprobe(struct jprobe *jp)
 {
-	return register_jprobes(&jp, 1);
+	unsigned long addr, offset;
+	struct kprobe *kp = &jp->kp;
+
+	/* Verify probepoint is a function entry point */
+	addr = arch_deref_entry_point(jp->entry);
+
+	if (kallsyms_lookup_size_offset(addr, NULL, &offset) && offset == 0) {
+		kp->pre_handler = setjmp_pre_handler;
+		kp->break_handler = longjmp_break_handler;
+		return register_kprobe(kp);
+	}
+
+	return -EINVAL;
 }
 EXPORT_SYMBOL_GPL(register_jprobe);
 
-- 
2.13.2

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

* [PATCH v2 3/3] kernel/kprobes: Ensure that jprobe probepoints are at function entry
  2017-07-07 17:07 [PATCH v2 0/3] kernel/kprobes: A few trivial updates to jprobes Naveen N. Rao
  2017-07-07 17:07 ` [PATCH v2 1/3] kernel/kprobes: Rename [arch_]function_offset_within_entry() to [arch_]kprobe_on_func_entry() Naveen N. Rao
  2017-07-07 17:07 ` [PATCH v2 2/3] kernel/kprobes: Simplify register_jprobes() Naveen N. Rao
@ 2017-07-07 17:07 ` Naveen N. Rao
  2017-07-08 11:10   ` [tip:perf/urgent] kprobes: " tip-bot for Naveen N. Rao
  2017-07-09 12:28 ` [PATCH v2 0/3] kernel/kprobes: A few trivial updates to jprobes Masami Hiramatsu
  3 siblings, 1 reply; 8+ messages in thread
From: Naveen N. Rao @ 2017-07-07 17:07 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: Masami Hiramatsu, Ananth N Mavinakayanahalli, linux-kernel

Similar to commit 90ec5e89e393c ("kretprobes: Ensure probe location is
at function entry"), ensure that the jprobe probepoint is at function
entry.

Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
---
 kernel/kprobes.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index db3cd3e60bdd..a1606a4224e1 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -1795,10 +1795,14 @@ int register_jprobe(struct jprobe *jp)
 	unsigned long addr, offset;
 	struct kprobe *kp = &jp->kp;
 
-	/* Verify probepoint is a function entry point */
+	/*
+	 * Verify probepoint as well as the jprobe handler are
+	 * valid function entry points.
+	 */
 	addr = arch_deref_entry_point(jp->entry);
 
-	if (kallsyms_lookup_size_offset(addr, NULL, &offset) && offset == 0) {
+	if (kallsyms_lookup_size_offset(addr, NULL, &offset) && offset == 0 &&
+	    kprobe_on_func_entry(kp->addr, kp->symbol_name, kp->offset)) {
 		kp->pre_handler = setjmp_pre_handler;
 		kp->break_handler = longjmp_break_handler;
 		return register_kprobe(kp);
-- 
2.13.2

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

* [tip:perf/urgent] kprobes: Rename [arch_]function_offset_within_entry() to [arch_]kprobe_on_func_entry()
  2017-07-07 17:07 ` [PATCH v2 1/3] kernel/kprobes: Rename [arch_]function_offset_within_entry() to [arch_]kprobe_on_func_entry() Naveen N. Rao
@ 2017-07-08 11:10   ` tip-bot for Naveen N. Rao
  0 siblings, 0 replies; 8+ messages in thread
From: tip-bot for Naveen N. Rao @ 2017-07-08 11:10 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: hpa, ananth, peterz, tglx, naveen.n.rao, linux-kernel, mhiramat,
	torvalds, mingo

Commit-ID:  659b957f20c78fd470083c80af5e79eedfb39e5b
Gitweb:     http://git.kernel.org/tip/659b957f20c78fd470083c80af5e79eedfb39e5b
Author:     Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
AuthorDate: Fri, 7 Jul 2017 22:37:24 +0530
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Sat, 8 Jul 2017 11:05:34 +0200

kprobes: Rename [arch_]function_offset_within_entry() to [arch_]kprobe_on_func_entry()

Rename function_offset_within_entry() to scope it to kprobe namespace by
using kprobe_ prefix, and to also simplify it.

Suggested-by: Ingo Molnar <mingo@kernel.org>
Suggested-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Cc: Ananth N Mavinakayanahalli <ananth@linux.vnet.ibm.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/3aa6c7e2e4fb6e00f3c24fa306496a66edb558ea.1499443367.git.naveen.n.rao@linux.vnet.ibm.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/powerpc/kernel/kprobes.c | 2 +-
 include/linux/kprobes.h       | 4 ++--
 kernel/kprobes.c              | 8 ++++----
 kernel/trace/trace_kprobe.c   | 2 +-
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobes.c
index 01addfb..586508e 100644
--- a/arch/powerpc/kernel/kprobes.c
+++ b/arch/powerpc/kernel/kprobes.c
@@ -221,7 +221,7 @@ static nokprobe_inline void set_current_kprobe(struct kprobe *p, struct pt_regs
 	kcb->kprobe_saved_msr = regs->msr;
 }
 
-bool arch_function_offset_within_entry(unsigned long offset)
+bool arch_kprobe_on_func_entry(unsigned long offset)
 {
 #ifdef PPC64_ELF_ABI_v2
 #ifdef CONFIG_KPROBES_ON_FTRACE
diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h
index 541df0b..bd26847 100644
--- a/include/linux/kprobes.h
+++ b/include/linux/kprobes.h
@@ -267,8 +267,8 @@ 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 function_offset_within_entry(kprobe_opcode_t *addr, const char *sym, unsigned long offset);
+extern bool arch_kprobe_on_func_entry(unsigned long offset);
+extern bool kprobe_on_func_entry(kprobe_opcode_t *addr, const char *sym, unsigned long offset);
 
 extern bool within_kprobe_blacklist(unsigned long addr);
 
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 6756d75..a519219 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -1888,12 +1888,12 @@ 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)
+bool __weak arch_kprobe_on_func_entry(unsigned long offset)
 {
 	return !offset;
 }
 
-bool function_offset_within_entry(kprobe_opcode_t *addr, const char *sym, unsigned long offset)
+bool kprobe_on_func_entry(kprobe_opcode_t *addr, const char *sym, unsigned long offset)
 {
 	kprobe_opcode_t *kp_addr = _kprobe_addr(addr, sym, offset);
 
@@ -1901,7 +1901,7 @@ bool function_offset_within_entry(kprobe_opcode_t *addr, const char *sym, unsign
 		return false;
 
 	if (!kallsyms_lookup_size_offset((unsigned long)kp_addr, NULL, &offset) ||
-						!arch_function_offset_within_entry(offset))
+						!arch_kprobe_on_func_entry(offset))
 		return false;
 
 	return true;
@@ -1914,7 +1914,7 @@ int register_kretprobe(struct kretprobe *rp)
 	int i;
 	void *addr;
 
-	if (!function_offset_within_entry(rp->kp.addr, rp->kp.symbol_name, rp->kp.offset))
+	if (!kprobe_on_func_entry(rp->kp.addr, rp->kp.symbol_name, rp->kp.offset))
 		return -EINVAL;
 
 	if (kretprobe_blacklist_size) {
diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
index b53c8d3..2c52218 100644
--- a/kernel/trace/trace_kprobe.c
+++ b/kernel/trace/trace_kprobe.c
@@ -720,7 +720,7 @@ static int create_trace_kprobe(int argc, char **argv)
 			return ret;
 		}
 		if (offset && is_return &&
-		    !function_offset_within_entry(NULL, symbol, offset)) {
+		    !kprobe_on_func_entry(NULL, symbol, offset)) {
 			pr_info("Given offset is not valid for return probe.\n");
 			return -EINVAL;
 		}

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

* [tip:perf/urgent] kprobes: Simplify register_jprobes()
  2017-07-07 17:07 ` [PATCH v2 2/3] kernel/kprobes: Simplify register_jprobes() Naveen N. Rao
@ 2017-07-08 11:10   ` tip-bot for Naveen N. Rao
  0 siblings, 0 replies; 8+ messages in thread
From: tip-bot for Naveen N. Rao @ 2017-07-08 11:10 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: mingo, ananth, peterz, torvalds, linux-kernel, mhiramat,
	naveen.n.rao, tglx, hpa

Commit-ID:  0f73ff80b751b39ff539a550e65c5bd131ff0316
Gitweb:     http://git.kernel.org/tip/0f73ff80b751b39ff539a550e65c5bd131ff0316
Author:     Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
AuthorDate: Fri, 7 Jul 2017 22:37:25 +0530
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Sat, 8 Jul 2017 11:05:34 +0200

kprobes: Simplify register_jprobes()

Re-factor jprobe registration functions as the current version is
getting too unwieldy. Move the actual jprobe registration to
register_jprobe() and re-organize code accordingly.

Suggested-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Cc: Ananth N Mavinakayanahalli <ananth@linux.vnet.ibm.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/089cae4bfe73767f765291ee0e6fb0c3d240e5f1.1499443367.git.naveen.n.rao@linux.vnet.ibm.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 kernel/kprobes.c | 30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index a519219..db3cd3e 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -1771,24 +1771,13 @@ unsigned long __weak arch_deref_entry_point(void *entry)
 
 int register_jprobes(struct jprobe **jps, int num)
 {
-	struct jprobe *jp;
 	int ret = 0, i;
 
 	if (num <= 0)
 		return -EINVAL;
+
 	for (i = 0; i < num; i++) {
-		unsigned long addr, offset;
-		jp = jps[i];
-		addr = arch_deref_entry_point(jp->entry);
-
-		/* Verify probepoint is a function entry point */
-		if (kallsyms_lookup_size_offset(addr, NULL, &offset) &&
-		    offset == 0) {
-			jp->kp.pre_handler = setjmp_pre_handler;
-			jp->kp.break_handler = longjmp_break_handler;
-			ret = register_kprobe(&jp->kp);
-		} else
-			ret = -EINVAL;
+		ret = register_jprobe(jps[i]);
 
 		if (ret < 0) {
 			if (i > 0)
@@ -1796,13 +1785,26 @@ int register_jprobes(struct jprobe **jps, int num)
 			break;
 		}
 	}
+
 	return ret;
 }
 EXPORT_SYMBOL_GPL(register_jprobes);
 
 int register_jprobe(struct jprobe *jp)
 {
-	return register_jprobes(&jp, 1);
+	unsigned long addr, offset;
+	struct kprobe *kp = &jp->kp;
+
+	/* Verify probepoint is a function entry point */
+	addr = arch_deref_entry_point(jp->entry);
+
+	if (kallsyms_lookup_size_offset(addr, NULL, &offset) && offset == 0) {
+		kp->pre_handler = setjmp_pre_handler;
+		kp->break_handler = longjmp_break_handler;
+		return register_kprobe(kp);
+	}
+
+	return -EINVAL;
 }
 EXPORT_SYMBOL_GPL(register_jprobe);
 

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

* [tip:perf/urgent] kprobes: Ensure that jprobe probepoints are at function entry
  2017-07-07 17:07 ` [PATCH v2 3/3] kernel/kprobes: Ensure that jprobe probepoints are at function entry Naveen N. Rao
@ 2017-07-08 11:10   ` tip-bot for Naveen N. Rao
  0 siblings, 0 replies; 8+ messages in thread
From: tip-bot for Naveen N. Rao @ 2017-07-08 11:10 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: hpa, ananth, peterz, naveen.n.rao, mingo, torvalds, mhiramat,
	linux-kernel, tglx

Commit-ID:  dbf580623d5fee785218d1a47a2bcdf36d85c0e9
Gitweb:     http://git.kernel.org/tip/dbf580623d5fee785218d1a47a2bcdf36d85c0e9
Author:     Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
AuthorDate: Fri, 7 Jul 2017 22:37:26 +0530
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Sat, 8 Jul 2017 11:05:35 +0200

kprobes: Ensure that jprobe probepoints are at function entry

Similar to commit 90ec5e89e393c ("kretprobes: Ensure probe location is
at function entry"), ensure that the jprobe probepoint is at function
entry.

Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Cc: Ananth N Mavinakayanahalli <ananth@linux.vnet.ibm.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/a4525af6c5a42df385efa31251246cf7cca73598.1499443367.git.naveen.n.rao@linux.vnet.ibm.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 kernel/kprobes.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index db3cd3e..a1606a4 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -1795,10 +1795,14 @@ int register_jprobe(struct jprobe *jp)
 	unsigned long addr, offset;
 	struct kprobe *kp = &jp->kp;
 
-	/* Verify probepoint is a function entry point */
+	/*
+	 * Verify probepoint as well as the jprobe handler are
+	 * valid function entry points.
+	 */
 	addr = arch_deref_entry_point(jp->entry);
 
-	if (kallsyms_lookup_size_offset(addr, NULL, &offset) && offset == 0) {
+	if (kallsyms_lookup_size_offset(addr, NULL, &offset) && offset == 0 &&
+	    kprobe_on_func_entry(kp->addr, kp->symbol_name, kp->offset)) {
 		kp->pre_handler = setjmp_pre_handler;
 		kp->break_handler = longjmp_break_handler;
 		return register_kprobe(kp);

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

* Re: [PATCH v2 0/3] kernel/kprobes: A few trivial updates to jprobes
  2017-07-07 17:07 [PATCH v2 0/3] kernel/kprobes: A few trivial updates to jprobes Naveen N. Rao
                   ` (2 preceding siblings ...)
  2017-07-07 17:07 ` [PATCH v2 3/3] kernel/kprobes: Ensure that jprobe probepoints are at function entry Naveen N. Rao
@ 2017-07-09 12:28 ` Masami Hiramatsu
  3 siblings, 0 replies; 8+ messages in thread
From: Masami Hiramatsu @ 2017-07-09 12:28 UTC (permalink / raw)
  To: Naveen N. Rao
  Cc: Ingo Molnar, Masami Hiramatsu, Ananth N Mavinakayanahalli, linux-kernel

On Fri,  7 Jul 2017 22:37:23 +0530
"Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> wrote:

> Here is v2 of the patch:
> https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1434133.html
> 
> As suggested, the first two patches first clean up the existing jprobe
> registration functions and rename function_offset_within_entry() to
> kprobe_on_func_entry(). The last patch has been updated accordingly.

This series looks good to me.

Acked-by: Masami Hiramatsu <mhiramat@kernel.org>


Thanks!

> 
> Thanks,
> Naveen
> 
> Naveen N. Rao (3):
>   kernel/kprobes: Rename [arch_]function_offset_within_entry() to
>     [arch_]kprobe_on_func_entry()
>   kernel/kprobes: Simplify register_jprobes()
>   kernel/kprobes: Ensure that jprobe probepoints are at function entry
> 
>  arch/powerpc/kernel/kprobes.c |  2 +-
>  include/linux/kprobes.h       |  4 ++--
>  kernel/kprobes.c              | 42 ++++++++++++++++++++++++------------------
>  kernel/trace/trace_kprobe.c   |  2 +-
>  4 files changed, 28 insertions(+), 22 deletions(-)
> 
> -- 
> 2.13.2
> 


-- 
Masami Hiramatsu <mhiramat@kernel.org>

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

end of thread, other threads:[~2017-07-09 12:28 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-07 17:07 [PATCH v2 0/3] kernel/kprobes: A few trivial updates to jprobes Naveen N. Rao
2017-07-07 17:07 ` [PATCH v2 1/3] kernel/kprobes: Rename [arch_]function_offset_within_entry() to [arch_]kprobe_on_func_entry() Naveen N. Rao
2017-07-08 11:10   ` [tip:perf/urgent] kprobes: " tip-bot for Naveen N. Rao
2017-07-07 17:07 ` [PATCH v2 2/3] kernel/kprobes: Simplify register_jprobes() Naveen N. Rao
2017-07-08 11:10   ` [tip:perf/urgent] kprobes: " tip-bot for Naveen N. Rao
2017-07-07 17:07 ` [PATCH v2 3/3] kernel/kprobes: Ensure that jprobe probepoints are at function entry Naveen N. Rao
2017-07-08 11:10   ` [tip:perf/urgent] kprobes: " tip-bot for Naveen N. Rao
2017-07-09 12:28 ` [PATCH v2 0/3] kernel/kprobes: A few trivial updates to jprobes Masami Hiramatsu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).