Skip to contentSkip to conversation

kprobes: Update examples to target _do_fork

PATCH In review Steve Capper 2 participants 2 messages Aug 12, 2015 kprobes

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kprobes: Update examples to target _do_fork

In commit 3033f14ab78c ("clone: support passing tls argument via C rather than pt_regs magic"), the kernel calls _do_fork in places where it previously called do_fork.

Unfortunately, the kprobe examples target do_fork; thus no events appear to fire when one runs the example modules.

This commit updates the kprobe example code s.t. _do_fork is targeted instead, and the examples work as expected.

---
 samples/kprobes/jprobe_example.c    | 8 ++++----
 samples/kprobes/kprobe_example.c    | 2 +-
 samples/kprobes/kretprobe_example.c | 2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)
samples/kprobes/jprobe_example.c +4 -4
index 9119ac6..11dd54b 100644
@@ -23,9 +23,9 @@
  */
 
 /* Proxy routine having the same arguments as actual do_fork() routine */
-static long jdo_fork(unsigned long clone_flags, unsigned long stack_start,
+static long j_do_fork(unsigned long clone_flags, unsigned long stack_start,
 	      unsigned long stack_size, int __user *parent_tidptr,
-	      int __user *child_tidptr)
+	      int __user *child_tidptr, unsigned long tls)
 {
 	pr_info("jprobe: clone_flags = 0x%lx, stack_start = 0x%lx "
 		"stack_size = 0x%lx\n", clone_flags, stack_start, stack_size);
@@ -36,9 +36,9 @@ static long jdo_fork(unsigned long clone_flags, unsigned long stack_start,
 }
 
 static struct jprobe my_jprobe = {
-	.entry			= jdo_fork,
+	.entry			= j_do_fork,
 	.kp = {
-		.symbol_name	= "do_fork",
+		.symbol_name	= "_do_fork",
 	},
 };
 
samples/kprobes/kprobe_example.c +1 -1
index 51d459c..597e101 100644
@@ -16,7 +16,7 @@
 
 /* For each probe you need to allocate a kprobe structure */
 static struct kprobe kp = {
-	.symbol_name	= "do_fork",
+	.symbol_name	= "_do_fork",
 };
 
 /* kprobe pre_handler: called just before the probed instruction is executed */
samples/kprobes/kretprobe_example.c +1 -1
index 1041b67..a270535 100644
@@ -25,7 +25,7 @@
 #include <linux/limits.h>
 #include <linux/sched.h>
 
-static char func_name[NAME_MAX] = "do_fork";
+static char func_name[NAME_MAX] = "_do_fork";
 module_param_string(func, func_name, NAME_MAX, S_IRUGO);
 MODULE_PARM_DESC(func, "Function to kretprobe; this module will report the"
 			" function's execution time");
Signature · 1 line
2.1.0
#1 lore raw
Quoted 11 lines

From: Steve Capper [mailto:[email protected]]

In commit 3033f14ab78c ("clone: support passing tls argument via C rather than pt_regs magic"), the kernel calls _do_fork in places where it previously called do_fork.

Unfortunately, the kprobe examples target do_fork; thus no events appear to fire when one runs the example modules.

This commit updates the kprobe example code s.t. _do_fork is targeted instead, and the examples work as expected.

Oops, right! I've found it on ftrace-test, but missed on kprobes examples :(

Quoted 2 lines

Thank you!

Quoted 61 lines
---
 samples/kprobes/jprobe_example.c    | 8 ++++----
 samples/kprobes/kprobe_example.c    | 2 +-
 samples/kprobes/kretprobe_example.c | 2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)
samples/kprobes/jprobe_example.c +4 -4
index 9119ac6..11dd54b 100644
@@ -23,9 +23,9 @@
  */
 
 /* Proxy routine having the same arguments as actual do_fork() routine */
-static long jdo_fork(unsigned long clone_flags, unsigned long stack_start,
+static long j_do_fork(unsigned long clone_flags, unsigned long stack_start,
 	      unsigned long stack_size, int __user *parent_tidptr,
-	      int __user *child_tidptr)
+	      int __user *child_tidptr, unsigned long tls)
 {
 	pr_info("jprobe: clone_flags = 0x%lx, stack_start = 0x%lx "
 		"stack_size = 0x%lx\n", clone_flags, stack_start, stack_size);
@@ -36,9 +36,9 @@ static long jdo_fork(unsigned long clone_flags, unsigned long stack_start,
 }
 
 static struct jprobe my_jprobe = {
-	.entry			= jdo_fork,
+	.entry			= j_do_fork,
 	.kp = {
-		.symbol_name	= "do_fork",
+		.symbol_name	= "_do_fork",
 	},
 };
 
samples/kprobes/kprobe_example.c +1 -1
index 51d459c..597e101 100644
@@ -16,7 +16,7 @@
 
 /* For each probe you need to allocate a kprobe structure */
 static struct kprobe kp = {
-	.symbol_name	= "do_fork",
+	.symbol_name	= "_do_fork",
 };
 
 /* kprobe pre_handler: called just before the probed instruction is executed */
samples/kprobes/kretprobe_example.c +1 -2
index 1041b67..a270535 100644
@@ -25,7 +25,7 @@
 #include <linux/limits.h>
 #include <linux/sched.h>
 
-static char func_name[NAME_MAX] = "do_fork";
+static char func_name[NAME_MAX] = "_do_fork";
 module_param_string(func, func_name, NAME_MAX, S_IRUGO);
 MODULE_PARM_DESC(func, "Function to kretprobe; this module will report the"
 			" function's execution time");
--
Quoted 1 line

2.1.0

���{.n�+�������+%�����ݶ��w��{.n�+����{��G�����{ay�ʇڙ�,j��f���h��������z_�(�階�ݢj"���m������G������?����&���~��iO��z��v�^�m���� ������?�I�