lkml.org 
[lkml]   [2022]   [Jun]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 2/2] kprobes: refactor populate_kprobe_blacklist()
Date
From: binglei wang <l3b2w1@gmail.com>

Just make it seems orderly

Signed-off-by: binglei wang <l3b2w1@gmail.com>
---
kernel/kprobes.c | 41 +++++++++++++++++++++++++++--------------
1 file changed, 27 insertions(+), 14 deletions(-)

diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index f4a829d98..b2b1ef7bc 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -2475,6 +2475,26 @@ int kprobe_add_area_blacklist(unsigned long start, unsigned long end)
return 0;
}

+/* Add all symbols marked with NOKPROBE_SYMBOL into kprobe blacklist */
+static int __init kprobe_add_nokpb_blacklist(unsigned long *start,
+ unsigned long *end)
+{
+ unsigned long entry;
+ unsigned long *iter;
+ int ret = 0;
+
+ for (iter = start; iter < end; iter++) {
+ entry = (unsigned long)dereference_symbol_descriptor((void *)*iter);
+ ret = kprobe_add_ksym_blacklist(entry);
+ if (ret == -EINVAL)
+ continue;
+ if (ret < 0)
+ return ret;
+ }
+
+ return ret;
+}
+
/* Remove all symbols in given area from kprobe blacklist */
static void kprobe_remove_area_blacklist(unsigned long start, unsigned long end)
{
@@ -2528,21 +2548,15 @@ int __init __weak arch_populate_kprobe_blacklist(void)
* since a kprobe need not necessarily be at the beginning
* of a function.
*/
-static int __init populate_kprobe_blacklist(unsigned long *start,
- unsigned long *end)
+static int __init populate_kprobe_blacklist(void)
{
- unsigned long entry;
- unsigned long *iter;
int ret;

- for (iter = start; iter < end; iter++) {
- entry = (unsigned long)dereference_symbol_descriptor((void *)*iter);
- ret = kprobe_add_ksym_blacklist(entry);
- if (ret == -EINVAL)
- continue;
- if (ret < 0)
- return ret;
- }
+ /* Symbols in '__start/__stop_kprobe_blacklist' are blacklisted */
+ ret = kprobe_add_nokpb_blacklist(__start_kprobe_blacklist,
+ __stop_kprobe_blacklist);
+ if (ret)
+ return ret;

/* Symbols in '__kprobes_text' are blacklisted */
ret = kprobe_add_area_blacklist((unsigned long)__kprobes_text_start,
@@ -2690,8 +2704,7 @@ static int __init init_kprobes(void)
for (i = 0; i < KPROBE_TABLE_SIZE; i++)
INIT_HLIST_HEAD(&kprobe_table[i]);

- err = populate_kprobe_blacklist(__start_kprobe_blacklist,
- __stop_kprobe_blacklist);
+ err = populate_kprobe_blacklist();
if (err)
pr_err("Failed to populate blacklist (error %d), kprobes not restricted, be careful using them!\n", err);

--
2.27.0
\
 
 \ /
  Last update: 2022-06-13 10:37    [W:0.633 / U:0.072 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site