Skip to contentSkip to conversation

To refuse users from probing preempt_schedule()

RFC PATCH In review srinivasa 3 participants 5 messages Feb 25, 2008 – Mar 4, 2008 kprobes

lore
Share & tools
lore

srinivasa

author
#0 lore raw

RFC PATCH 1/1 To refuse users from probing preempt_schedule()

From: Srinivasa Ds <[email protected]>

This patch prohibits user from probing preempt_schedule(). One way of prohibiting the user from probing functions is by marking such functions with __kprobes. But this method doesn't work for those functions, which are already marked to different section like preempt_schedule() (belongs to __sched section). So we use blacklist approach to refuse user from probing these functions.

In blacklist approach we populate the blacklisted function's starting address and its size in kprobe_blacklist structure. Then we verify the user specified address against start and end of the blacklisted function. So any attempt to register probe on blacklisted functions will be rejected.

please let me know your comments.

---
 include/linux/kprobes.h |    7 ++++++
 kernel/kprobes.c        |   52 
++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 59 insertions(+)
include/linux/kprobes.h +7 -0
Index: linux-2.6.25-rc3/include/linux/kprobes.h
===================================================================
@@ -173,6 +173,13 @@ struct kretprobe_blackpoint {
 	const char *name;
 	void *addr;
 };
+
+struct kprobe_blackpoint {
+	const char *name;
+	unsigned long start_addr;
+	unsigned long range;
+};
+
 extern struct kretprobe_blackpoint kretprobe_blacklist[];
 
 static inline void kretprobe_assert(struct kretprobe_instance *ri,
kernel/kprobes.c +52 -0

79 lines not on this page · raw message

#1 lore raw
Quoted 6 lines · srinivasa

This patch prohibits user from probing preempt_schedule(). One way of prohibiting the user from probing functions is by marking such functions with __kprobes. But this method doesn't work for those functions, which are already marked to different section like preempt_schedule() (belongs to __sched section). So we use blacklist approach to refuse user from probing these functions.

preempt_schedule() does sound really, really important. But, what kinds of functions can't be kprobed? It would be nice to give that blacklist a nice comment on the topic. :)

Also, have you strained your brains to think of other functions that this should be applied to? Is it just for functions that are sensitive and already have an assigned section? Might be nice to call that out explicitly.

-- Dave

#2 lore raw
Quoted 10 lines · Dave Hansen
Quoted 6 lines · srinivasa

This patch prohibits user from probing preempt_schedule(). One way of prohibiting the user from probing functions is by marking such functions with __kprobes. But this method doesn't work for those functions, which are already marked to different section like preempt_schedule() (belongs to __sched section). So we use blacklist approach to refuse user from probing these functions.

preempt_schedule() does sound really, really important. But, what kinds of functions can't be kprobed?

Normally we don't allow user to probe those functions, which are used by kprobes internally while registering probe on user specified address. For example kprobes internally makes use of preempt_disable()(this in turn calls add_preempt_count()), so we prohibit users from probing add_preempt_count() function. To get comprehensive list of functions which are prohibited from probing, please have a look at functions which are marked under __kprobes.

Quoted 2 lines

It would be nice to give that blacklist
a nice comment on the topic. :)

Yes, I have added comments on the blacklist approach in
1)init_kprobes(), where we populate entries for kprobe blacklist.
2) in_kprobe_function(), where we verify the user specified address with
the start and end of the blacklisted function.

Quoted 4 lines

Also, have you strained your brains to think of other functions that this should be applied to? Is it just for functions that are sensitive and already have an assigned section?

Yes, this kprobes blacklist approach is only for those functions which are sensitive and are already assigned to different sections. Right now, there is no other function, except preempt_schedule() which satisfies above condition. But in future if we encounter any such functions we surely add them kprobe blacklist.

#3 lore raw
In reply to srinivasa
Quoted 9 lines · On Mon, 25 Feb 2008 11:27:40 +0530 srinivasa <[email protected]> wrote:

From: Srinivasa Ds <[email protected]>

This patch prohibits user from probing preempt_schedule(). One way of prohibiting the user from probing functions is by marking such functions with __kprobes. But this method doesn't work for those functions, which are already marked to different section like preempt_schedule() (belongs to __sched section). So we use blacklist approach to refuse user from probing these functions.

Quoted 7 lines

In blacklist approach we populate the blacklisted function's starting address and its size in kprobe_blacklist structure. Then we verify the user specified address against start and end of the blacklisted function. So any attempt to register probe on blacklisted functions will be rejected.

please let me know your comments.

sparc64:

kernel/kprobes.c: In function `in_kprobes_functions':
kernel/kprobes.c:516: error: `kprobe_blacklist' undeclared (first use in this function) kernel/kprobes.c:516: error: (Each undeclared identifier is reported only once kernel/kprobes.c:516: error: for each function it appears in.) kernel/kprobes.c: In function `init_kprobes':
kernel/kprobes.c:860: error: `kprobe_blacklist' undeclared (first use in this function)

Quoted 11 lines
---
 include/linux/kprobes.h |    7 ++++++
 kernel/kprobes.c        |   52 
++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 59 insertions(+)

Index: linux-2.6.25-rc3/include/linux/kprobes.h
===================================================================

include/linux/kprobes.h struct kretprobe_blackpoint { · line 182

Quoted 10 lines
include/linux/kprobes.h +7 -0
@@ -173,6 +173,13 @@ struct kretprobe_blackpoint {
 	const char *name;
 	void *addr;
 };
+
+struct kprobe_blackpoint {
+	const char *name;
+	unsigned long start_addr;
+	unsigned long range;
+};
+

I'm assuming that the placement of this definition inside __ARCH_WANT_KPROBES_INSN_SLOT wqs accidental?

kernel/kprobes.c renamed from kernel/kprobes.c~kprobes-prevent-probing-of-preempt_schedule-fix +12 -12
@@ -72,6 +72,18 @@ DEFINE_MUTEX(kprobe_mutex);		/* Protects
 DEFINE_SPINLOCK(kretprobe_lock);	/* Protects kretprobe_inst_table */
 static DEFINE_PER_CPU(struct kprobe *, kprobe_instance) = NULL;
 
+/*
+ * Normally, functions that we'd want to prohibit kprobes in, are marked
+ * __kprobes. But, there are cases where such functions already belong to
+ * a different section (__sched for preempt_schedule)
+ *
+ * For such cases, we now have a blacklist
+ */
+struct kprobe_blackpoint kprobe_blacklist[] = {
+        {"preempt_schedule",},
+        {NULL}    /* Terminator */
+};
+
 #ifdef __ARCH_WANT_KPROBES_INSN_SLOT
 /*
  * kprobe->ainsn.insn points to the copy of the instruction to be
@@ -89,18 +101,6 @@ struct kprobe_insn_page {
 	int ngarbage;
 };
 
-/*
- * Normally, functions that we'd want to prohibit kprobes in, are marked
- * __kprobes. But, there are cases where such functions already belong to
- * a different section (__sched for preempt_schedule)
- *
- * For such cases, we now have a blacklist
- */
-struct kprobe_blackpoint kprobe_blacklist[] = {
-        {"preempt_schedule",},
-        {NULL}    /* Terminator */
-};
-
 enum kprobe_slot_state {
 	SLOT_CLEAN = 0,
 	SLOT_DIRTY = 1,

_

#4 lore raw
Quoted 45 lines · Andrew Morton
Quoted 9 lines · On Mon, 25 Feb 2008 11:27:40 +0530 srinivasa <[email protected]> wrote:

From: Srinivasa Ds <[email protected]>

This patch prohibits user from probing preempt_schedule(). One way of prohibiting the user from probing functions is by marking such functions with __kprobes. But this method doesn't work for those functions, which are already marked to different section like preempt_schedule() (belongs to __sched section). So we use blacklist approach to refuse user from probing these functions.

Quoted 7 lines

In blacklist approach we populate the blacklisted function's starting address and its size in kprobe_blacklist structure. Then we verify the user specified address against start and end of the blacklisted function. So any attempt to register probe on blacklisted functions will be rejected.

please let me know your comments.

sparc64:

kernel/kprobes.c: In function `in_kprobes_functions':
kernel/kprobes.c:516: error: `kprobe_blacklist' undeclared (first use in this function) kernel/kprobes.c:516: error: (Each undeclared identifier is reported only once kernel/kprobes.c:516: error: for each function it appears in.)
kernel/kprobes.c: In function `init_kprobes':
kernel/kprobes.c:860: error: `kprobe_blacklist' undeclared (first use in this function)

Quoted 16 lines
---
 include/linux/kprobes.h |    7 ++++++
 kernel/kprobes.c        |   52
++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 59 insertions(+)

Index: linux-2.6.25-rc3/include/linux/kprobes.h
===================================================================

include/linux/kprobes.h +2 -0
@@ -173,6 +173,13 @@ struct kretprobe_blackpoint {
 	const char *name;
 	void *addr;
 };
+
+struct kprobe_blackpoint {
Quoted 8 lines

include/linux/kprobes.h struct kretprobe_blackpoint { · line 182

Quoted 5 lines
include/linux/kprobes.h +5 -0
+	const char *name;
+	unsigned long start_addr;
+	unsigned long range;
+};
+

I'm assuming that the placement of this definition inside __ARCH_WANT_KPROBES_INSN_SLOT wqs accidental?

Yes Andrew. Sorry I over looked __ARCH_WANT_KPROBES_INSN_SLOT and placed the struct kprobe_black_point in a wrong place.

Patch, that you have attached below looks good, but for your reference,
Iam attaching the modified patch below.

Quoted 41 lines
kernel/kprobes.c renamed from kernel/kprobes.c~kprobes-prevent-probing-of-preempt_schedule-fix +12 -12
@@ -72,6 +72,18 @@ DEFINE_MUTEX(kprobe_mutex);		/* Protects
 DEFINE_SPINLOCK(kretprobe_lock);	/* Protects kretprobe_inst_table */
 static DEFINE_PER_CPU(struct kprobe *, kprobe_instance) = NULL;
 
+/*
+ * Normally, functions that we'd want to prohibit kprobes in, are marked
+ * __kprobes. But, there are cases where such functions already belong to
+ * a different section (__sched for preempt_schedule)
+ *
+ * For such cases, we now have a blacklist
+ */
+struct kprobe_blackpoint kprobe_blacklist[] = {
+        {"preempt_schedule",},
+        {NULL}    /* Terminator */
+};
+
 #ifdef __ARCH_WANT_KPROBES_INSN_SLOT
 /*
  * kprobe->ainsn.insn points to the copy of the instruction to be
@@ -89,18 +101,6 @@ struct kprobe_insn_page {
 	int ngarbage;
 };
 
-/*
- * Normally, functions that we'd want to prohibit kprobes in, are marked
- * __kprobes. But, there are cases where such functions already belong to
- * a different section (__sched for preempt_schedule)
- *
- * For such cases, we now have a blacklist
- */
-struct kprobe_blackpoint kprobe_blacklist[] = {
-        {"preempt_schedule",},
-        {NULL}    /* Terminator */
-};
-
 enum kprobe_slot_state {
 	SLOT_CLEAN = 0,
 	SLOT_DIRTY = 1,
Quoted 1 line

_

---
 include/linux/kprobes.h |    7 ++++++
 kernel/kprobes.c        |   51 
++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+)
include/linux/kprobes.h +7 -0
Index: linux-2.6.25-rc3/include/linux/kprobes.h
===================================================================
@@ -173,6 +173,13 @@ struct kretprobe_blackpoint {
 	const char *name;
 	void *addr;
 };
+
+struct kprobe_blackpoint {
+	const char *name;
+	unsigned long start_addr;
+	unsigned long range;
+};
+
 extern struct kretprobe_blackpoint kretprobe_blacklist[];
 
 static inline void kretprobe_assert(struct kretprobe_instance *ri,
kernel/kprobes.c +51 -0

78 lines not on this page · raw message