aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnanth N Mavinakayanahalli <ananth@in.ibm.com>2007-05-08 03:34:16 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-05-08 14:15:19 -0400
commitbf8f6e5b3e51ee0c64c2d1350c70198ddc8ad3f7 (patch)
treec48ebb92f836cfac58465eacc9658fbc2bac4783
parent4c4308cb93450989846ac49faeb6dab943e7657e (diff)
Kprobes: The ON/OFF knob thru debugfs
This patch provides a debugfs knob to turn kprobes on/off o A new file /debug/kprobes/enabled indicates if kprobes is enabled or not (default enabled) o Echoing 0 to this file will disarm all installed probes o Any new probe registration when disabled will register the probe but not arm it. A message will be printed out in such a case. o When a value 1 is echoed to the file, all probes (including ones registered in the intervening period) will be enabled o Unregistration will happen irrespective of whether probes are globally enabled or not. o Update Documentation/kprobes.txt to reflect these changes. While there also update the doc to make it current. We are also looking at providing sysrq key support to tie to the disabling feature provided by this patch. [akpm@linux-foundation.org: Use bool like a bool!] [akpm@linux-foundation.org: add printk facility levels] [cornelia.huck@de.ibm.com: Add the missing arch_trampoline_kprobe() for s390] Signed-off-by: Ananth N Mavinakayanahalli <ananth@in.ibm.com> Signed-off-by: Srinivasa DS <srinivasa@in.ibm.com> Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--Documentation/kprobes.txt34
-rw-r--r--arch/i386/kernel/kprobes.c5
-rw-r--r--arch/ia64/kernel/kprobes.c9
-rw-r--r--arch/powerpc/kernel/kprobes.c8
-rw-r--r--arch/s390/kernel/kprobes.c7
-rw-r--r--arch/x86_64/kernel/kprobes.c8
-rw-r--r--include/linux/kprobes.h5
-rw-r--r--kernel/kprobes.c156
8 files changed, 222 insertions, 10 deletions
diff --git a/Documentation/kprobes.txt b/Documentation/kprobes.txt
index d71fafffce90..da5404ab7569 100644
--- a/Documentation/kprobes.txt
+++ b/Documentation/kprobes.txt
@@ -14,6 +14,7 @@ CONTENTS
148. Kprobes Example 148. Kprobes Example
159. Jprobes Example 159. Jprobes Example
1610. Kretprobes Example 1610. Kretprobes Example
17Appendix A: The kprobes debugfs interface
17 18
181. Concepts: Kprobes, Jprobes, Return Probes 191. Concepts: Kprobes, Jprobes, Return Probes
19 20
@@ -349,9 +350,12 @@ for instrumentation and error reporting.)
349 350
350If the number of times a function is called does not match the number 351If the number of times a function is called does not match the number
351of times it returns, registering a return probe on that function may 352of times it returns, registering a return probe on that function may
352produce undesirable results. We have the do_exit() case covered. 353produce undesirable results. In such a case, a line:
353do_execve() and do_fork() are not an issue. We're unaware of other 354kretprobe BUG!: Processing kretprobe d000000000041aa8 @ c00000000004f48c
354specific cases where this could be a problem. 355gets printed. With this information, one will be able to correlate the
356exact instance of the kretprobe that caused the problem. We have the
357do_exit() case covered. do_execve() and do_fork() are not an issue.
358We're unaware of other specific cases where this could be a problem.
355 359
356If, upon entry to or exit from a function, the CPU is running on 360If, upon entry to or exit from a function, the CPU is running on
357a stack other than that of the current task, registering a return 361a stack other than that of the current task, registering a return
@@ -614,3 +618,27 @@ http://www-106.ibm.com/developerworks/library/l-kprobes.html?ca=dgr-lnxw42Kprobe
614http://www.redhat.com/magazine/005mar05/features/kprobes/ 618http://www.redhat.com/magazine/005mar05/features/kprobes/
615http://www-users.cs.umn.edu/~boutcher/kprobes/ 619http://www-users.cs.umn.edu/~boutcher/kprobes/
616http://www.linuxsymposium.org/2006/linuxsymposium_procv2.pdf (pages 101-115) 620http://www.linuxsymposium.org/2006/linuxsymposium_procv2.pdf (pages 101-115)
621
622
623Appendix A: The kprobes debugfs interface
624
625With recent kernels (> 2.6.20) the list of registered kprobes is visible
626under the /debug/kprobes/ directory (assuming debugfs is mounted at /debug).
627
628/debug/kprobes/list: Lists all registered probes on the system
629
630c015d71a k vfs_read+0x0
631c011a316 j do_fork+0x0
632c03dedc5 r tcp_v4_rcv+0x0
633
634The first column provides the kernel address where the probe is inserted.
635The second column identifies the type of probe (k - kprobe, r - kretprobe
636and j - jprobe), while the third column specifies the symbol+offset of
637the probe. If the probed function belongs to a module, the module name
638is also specified.
639
640/debug/kprobes/enabled: Turn kprobes ON/OFF
641
642Provides a knob to globally turn registered kprobes ON or OFF. By default,
643all kprobes are enabled. By echoing "0" to this file, all registered probes
644will be disarmed, till such time a "1" is echoed to this file.
diff --git a/arch/i386/kernel/kprobes.c b/arch/i386/kernel/kprobes.c
index b6a9d64c2251..dde828a333c3 100644
--- a/arch/i386/kernel/kprobes.c
+++ b/arch/i386/kernel/kprobes.c
@@ -743,6 +743,11 @@ int __kprobes longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
743 return 0; 743 return 0;
744} 744}
745 745
746int __kprobes arch_trampoline_kprobe(struct kprobe *p)
747{
748 return 0;
749}
750
746int __init arch_init_kprobes(void) 751int __init arch_init_kprobes(void)
747{ 752{
748 return 0; 753 return 0;
diff --git a/arch/ia64/kernel/kprobes.c b/arch/ia64/kernel/kprobes.c
index 0b72f0f94192..4f5fd0960ba7 100644
--- a/arch/ia64/kernel/kprobes.c
+++ b/arch/ia64/kernel/kprobes.c
@@ -1012,3 +1012,12 @@ int __init arch_init_kprobes(void)
1012 (kprobe_opcode_t *)((struct fnptr *)kretprobe_trampoline)->ip; 1012 (kprobe_opcode_t *)((struct fnptr *)kretprobe_trampoline)->ip;
1013 return register_kprobe(&trampoline_p); 1013 return register_kprobe(&trampoline_p);
1014} 1014}
1015
1016int __kprobes arch_trampoline_kprobe(struct kprobe *p)
1017{
1018 if (p->addr ==
1019 (kprobe_opcode_t *)((struct fnptr *)kretprobe_trampoline)->ip)
1020 return 1;
1021
1022 return 0;
1023}
diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobes.c
index aed58e1cb91f..088b8c6defa0 100644
--- a/arch/powerpc/kernel/kprobes.c
+++ b/arch/powerpc/kernel/kprobes.c
@@ -550,3 +550,11 @@ int __init arch_init_kprobes(void)
550{ 550{
551 return register_kprobe(&trampoline_p); 551 return register_kprobe(&trampoline_p);
552} 552}
553
554int __kprobes arch_trampoline_kprobe(struct kprobe *p)
555{
556 if (p->addr == (kprobe_opcode_t *)&kretprobe_trampoline)
557 return 1;
558
559 return 0;
560}
diff --git a/arch/s390/kernel/kprobes.c b/arch/s390/kernel/kprobes.c
index 9d0f0d09d473..e39333ae0fcf 100644
--- a/arch/s390/kernel/kprobes.c
+++ b/arch/s390/kernel/kprobes.c
@@ -661,3 +661,10 @@ int __init arch_init_kprobes(void)
661{ 661{
662 return register_kprobe(&trampoline_p); 662 return register_kprobe(&trampoline_p);
663} 663}
664
665int __kprobes arch_trampoline_kprobe(struct kprobe *p)
666{
667 if (p->addr == (kprobe_opcode_t *) & kretprobe_trampoline)
668 return 1;
669 return 0;
670}
diff --git a/arch/x86_64/kernel/kprobes.c b/arch/x86_64/kernel/kprobes.c
index f995bea6e2c1..d4a0d0ac9935 100644
--- a/arch/x86_64/kernel/kprobes.c
+++ b/arch/x86_64/kernel/kprobes.c
@@ -743,3 +743,11 @@ int __init arch_init_kprobes(void)
743{ 743{
744 return register_kprobe(&trampoline_p); 744 return register_kprobe(&trampoline_p);
745} 745}
746
747int __kprobes arch_trampoline_kprobe(struct kprobe *p)
748{
749 if (p->addr == (kprobe_opcode_t *)&kretprobe_trampoline)
750 return 1;
751
752 return 0;
753}
diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h
index 6fc623e41fd8..23adf6075ae4 100644
--- a/include/linux/kprobes.h
+++ b/include/linux/kprobes.h
@@ -125,11 +125,16 @@ DECLARE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
125#ifdef ARCH_SUPPORTS_KRETPROBES 125#ifdef ARCH_SUPPORTS_KRETPROBES
126extern void arch_prepare_kretprobe(struct kretprobe_instance *ri, 126extern void arch_prepare_kretprobe(struct kretprobe_instance *ri,
127 struct pt_regs *regs); 127 struct pt_regs *regs);
128extern int arch_trampoline_kprobe(struct kprobe *p);
128#else /* ARCH_SUPPORTS_KRETPROBES */ 129#else /* ARCH_SUPPORTS_KRETPROBES */
129static inline void arch_prepare_kretprobe(struct kretprobe *rp, 130static inline void arch_prepare_kretprobe(struct kretprobe *rp,
130 struct pt_regs *regs) 131 struct pt_regs *regs)
131{ 132{
132} 133}
134static inline int arch_trampoline_kprobe(struct kprobe *p)
135{
136 return 0;
137}
133#endif /* ARCH_SUPPORTS_KRETPROBES */ 138#endif /* ARCH_SUPPORTS_KRETPROBES */
134/* 139/*
135 * Function-return probe - 140 * Function-return probe -
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index f58f171bd65f..9e47d8c493f3 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -43,9 +43,11 @@
43#include <linux/seq_file.h> 43#include <linux/seq_file.h>
44#include <linux/debugfs.h> 44#include <linux/debugfs.h>
45#include <linux/kdebug.h> 45#include <linux/kdebug.h>
46
46#include <asm-generic/sections.h> 47#include <asm-generic/sections.h>
47#include <asm/cacheflush.h> 48#include <asm/cacheflush.h>
48#include <asm/errno.h> 49#include <asm/errno.h>
50#include <asm/uaccess.h>
49 51
50#define KPROBE_HASH_BITS 6 52#define KPROBE_HASH_BITS 6
51#define KPROBE_TABLE_SIZE (1 << KPROBE_HASH_BITS) 53#define KPROBE_TABLE_SIZE (1 << KPROBE_HASH_BITS)
@@ -64,6 +66,9 @@ static struct hlist_head kprobe_table[KPROBE_TABLE_SIZE];
64static struct hlist_head kretprobe_inst_table[KPROBE_TABLE_SIZE]; 66static struct hlist_head kretprobe_inst_table[KPROBE_TABLE_SIZE];
65static atomic_t kprobe_count; 67static atomic_t kprobe_count;
66 68