Skip to contentSkip to conversation

+ kprobes-support-probing-module-__exit-function.patch added to -mm tree

PATCH In review [email protected] 3 participants 3 messages Nov 14, 2008 – Nov 19, 2008 kprobes

lore
Share & tools
lore

[email protected]

author tree notice
#0 lore raw

The patch titled
kprobes: support probing module __exit function
has been added to the -mm tree. Its filename is
kprobes-support-probing-module-__exit-function.patch

Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/SubmitChecklist when testing your code ***

See http://userweb.kernel.org/~akpm/stuff/added-to-mm.txt to find out what to do about this

The current -mm tree may be found at http://userweb.kernel.org/~akpm/mmotm/

------------------------------------------------------
Subject: kprobes: support probing module __exit function
From: Masami Hiramatsu <[email protected]>

Allows kprobes to probe __exit routine. This adds flags member to struct kprobe. When module is freed(kprobes hooks module_notifier to get this event), kprobes which probe the functions in that module are set to "Gone" flag to the flags member. These "Gone" probes are never be enabled. Users can check the GONE flag through debugfs.

This also removes mod_refcounted, because we couldn't free a module if kprobe incremented the refcount of that module.

---

 Documentation/kprobes.txt |    5 +
 include/linux/kprobes.h   |   14 ++-
 kernel/kprobes.c          |  140 +++++++++++++++++++++++++++---------
 3 files changed, 123 insertions(+), 36 deletions(-)
Documentation/kprobes.txt renamed from Documentation/kprobes.txt~kprobes-support-probing-module-__exit-function +4 -1
diff -puN Documentation/kprobes.txt~kprobes-support-probing-module-__exit-function Documentation/kprobes.txt
@@ -497,7 +497,10 @@ The first column provides the kernel add
 The second column identifies the type of probe (k - kprobe, r - kretprobe
 and j - jprobe), while the third column specifies the symbol+offset of
 the probe. If the probed function belongs to a module, the module name
-is also specified.
+is also specified. Following columns show probe status. If the probe is on
+a virtual address that is no longer valid (module init sections, module
+virtual addresses that correspond to modules that've been unloaded),
+such probes are marked with [GONE].
 
 /debug/kprobes/enabled: Turn kprobes ON/OFF
 
include/linux/kprobes.h renamed from include/linux/kprobes.h~kprobes-support-probing-module-__exit-function +11 -3
diff -puN include/linux/kprobes.h~kprobes-support-probing-module-__exit-function include/linux/kprobes.h
@@ -69,9 +69,6 @@ struct kprobe {
 	/* list of kprobes for multi-handler support */
 	struct list_head list;
 
-	/* Indicates that the corresponding module has been ref counted */
-	unsigned int mod_refcounted;
-
 	/*count the number of times this probe was temporarily disarmed */
 	unsigned long nmissed;
 
@@ -103,8 +100,19 @@ struct kprobe {
 
 	/* copy of the original instruction */
 	struct arch_specific_insn ainsn;
+
+	/* Indicates various status flags */
+	u32 flags;
 };
 
+/* Kprobe status flags */
+#define KPROBE_FLAG_GONE	1 /* breakpoint has already gone */
+
+static inline int kprobe_gone(struct kprobe *p)
+{
+	return p->flags & KPROBE_FLAG_GONE;
+}
+
 /*
  * Special probe type that uses setjmp-longjmp type tricks to resume
  * execution at a specified entry with a matching prototype corresponding
kernel/kprobes.c renamed from kernel/kprobes.c~kprobes-support-probing-module-__exit-function +108 -32

249 lines not on this page · raw message

_

Patches currently in -mm which might be from [email protected] are

origin.patch kprobes-bugfix-try_module_get-even-if-calling_mod-is-null.patch kprobes-indirectly-call-kprobe_target.patch kprobes-add-tests-for-register_kprobes.patch module-add-within_module_core-and-within_module_init.patch kprobes-add-kprobe_insn_mutex-and-cleanup-arch_remove_kprobe.patch kprobes-add-__kprobes-to-kprobe-internal-functions.patch kprobes-support-probing-module-__exit-function.patch kprobes-support-probing-module-__exit-function-fix.patch kprobes-remove-called_from-argument.patch kprobes-remove-called_from-argument-fix.patch module-add-module_state_live-notify.patch kprobes-support-probing-module-__init-function.patch

#1 lore raw

PATCH 1/1 bugfix: pass aggr_kprobe to arch_remove_kprobe

Hi Andrew,

Quoted 4 lines · [email protected] wrote:

The patch titled
kprobes: support probing module __exit function
has been added to the -mm tree. Its filename is
kprobes-support-probing-module-__exit-function.patch

I found that one bug was still alive. Here is the bugfix.

Thank you,

Call arch_remove_kprobe() with aggr_kprobe instead of user specific kprobe, because the user specific kprobe on the gone or reused aggr_kprobe may have invalid arch_specific_insn.

Cc Ananth N Mavinakayanahalli <[email protected]>
---
 kernel/kprobes.c |   14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
kernel/kprobes.c +7 -7
Index: 2.6-rc/kernel/kprobes.c
===================================================================
@@ -766,14 +766,14 @@ static void __kprobes __unregister_kprob
 {
 	struct kprobe *old_p;
 
-	if (list_empty(&p->list) || list_is_singular(&p->list)) {
-		if (!list_empty(&p->list)) {
-			/* "p" is the last child of an aggr_kprobe */
-			old_p = list_entry(p->list.next, struct kprobe, list);
-			list_del(&p->list);
-			kfree(old_p);
-		}
+	if (list_empty(&p->list))
 		arch_remove_kprobe(p);
+	else if (list_is_singular(&p->list)) {
+		/* "p" is the last child of an aggr_kprobe */
+		old_p = list_entry(p->list.next, struct kprobe, list);
+		list_del(&p->list);
+		arch_remove_kprobe(old_p);
+		kfree(old_p);
 	}
 }
 
Signature · 7 lines
Masami Hiramatsu

Software Engineer
Hitachi Computer Products (America) Inc.
Software Solutions Division

e-mail: [email protected]
Acked-by on v1 1/1
#2 lore raw

Re: [PATCH -mm] bugfix: pass aggr_kprobe to arch_remove_kprobe

Quoted 10 lines · Masami Hiramatsu

Hi Andrew,

Quoted 4 lines · [email protected] wrote:

The patch titled
kprobes: support probing module __exit function
has been added to the -mm tree. Its filename is
kprobes-support-probing-module-__exit-function.patch

I found that one bug was still alive. Here is the bugfix.

Quoted 8 lines

Thank you,

Call arch_remove_kprobe() with aggr_kprobe instead of user specific kprobe, because the user specific kprobe on the gone or reused aggr_kprobe may have invalid arch_specific_insn.

Cc Ananth N Mavinakayanahalli <[email protected]>
Quoted 40 lines
---
 kernel/kprobes.c |   14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

Index: 2.6-rc/kernel/kprobes.c
===================================================================

kernel/kprobes.c +7 -7
@@ -766,14 +766,14 @@ static void __kprobes __unregister_kprob
 {
 	struct kprobe *old_p;
 
-	if (list_empty(&p->list) || list_is_singular(&p->list)) {
-		if (!list_empty(&p->list)) {
-			/* "p" is the last child of an aggr_kprobe */
-			old_p = list_entry(p->list.next, struct kprobe, list);
-			list_del(&p->list);
-			kfree(old_p);
-		}
+	if (list_empty(&p->list))
 		arch_remove_kprobe(p);
+	else if (list_is_singular(&p->list)) {
+		/* "p" is the last child of an aggr_kprobe */
+		old_p = list_entry(p->list.next, struct kprobe, list);
+		list_del(&p->list);
+		arch_remove_kprobe(old_p);
+		kfree(old_p);
 	}
 }
 
Signature · 8 lines
-- 
Masami Hiramatsu

Software Engineer
Hitachi Computer Products (America) Inc.
Software Solutions Division

e-mail: [email protected]