All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com>
To: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>,
	Ananth N Mavinakayanahalli <ananth@linux.vnet.ibm.com>,
	linux-kernel@vger.kernel.org
Subject: [RFC PATCH 2/2] kprobes: Allow specifying names for certain blacklisted address ranges
Date: Thu, 29 Jun 2017 19:38:38 +0530	[thread overview]
Message-ID: <1a6d4df94ee8a61eda657b387f88d9ce1ec1fe3a.1498744665.git.naveen.n.rao@linux.vnet.ibm.com> (raw)
In-Reply-To: <cover.1498744665.git.naveen.n.rao@linux.vnet.ibm.com>
In-Reply-To: <cover.1498744665.git.naveen.n.rao@linux.vnet.ibm.com>

This allows us to provide meaningful names for certain address ranges
that are blacklisted such as those with __kprobes annotation, kernel
entry text, and so on. For such ranges, using the symbol/function name
at the start of the range is misleading.

On a powerpc64le system, before patch:
  root@ubuntu:/sys/kernel/debug# tail kprobes/blacklist
  0xc00000000022d500-0xc00000000022d580	print_type_s64
  0xc00000000022d480-0xc00000000022d500	print_type_s32
  0xc00000000022d400-0xc00000000022d480	print_type_s16
  0xc00000000022d380-0xc00000000022d400	print_type_s8
  0xc00000000022d300-0xc00000000022d380	print_type_u64
  0xc00000000022d280-0xc00000000022d300	print_type_u32
  0xc00000000022d200-0xc00000000022d280	print_type_u16
  0xc00000000022d180-0xc00000000022d200	print_type_u8
  0xc0000000009ed778-0xc0000000009ed778	__irqentry_text_end
  0xc000000000000000-0xc000000000008000	start_first_256B

After patch:
  root@ubuntu:/sys/kernel/debug# tail kprobes/blacklist
  0xc00000000022d540-0xc00000000022d5c0	print_type_s64
  0xc00000000022d4c0-0xc00000000022d540	print_type_s32
  0xc00000000022d440-0xc00000000022d4c0	print_type_s16
  0xc00000000022d3c0-0xc00000000022d440	print_type_s8
  0xc00000000022d340-0xc00000000022d3c0	print_type_u64
  0xc00000000022d2c0-0xc00000000022d340	print_type_u32
  0xc00000000022d240-0xc00000000022d2c0	print_type_u16
  0xc00000000022d1c0-0xc00000000022d240	print_type_u8
  0xc0000000009ed7b8-0xc0000000009ed7b8	[__kprobes]
  0xc000000000000000-0xc000000000008000	[__exceptions]

Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
---
 arch/arm64/kernel/probes/kprobes.c | 10 +++++-----
 arch/powerpc/kernel/kprobes.c      |  4 ++--
 arch/x86/kernel/kprobes/core.c     |  4 ++--
 include/linux/kprobes.h            |  3 ++-
 kernel/kprobes.c                   | 17 ++++++++++++-----
 5 files changed, 23 insertions(+), 15 deletions(-)

diff --git a/arch/arm64/kernel/probes/kprobes.c b/arch/arm64/kernel/probes/kprobes.c
index 7f453a71b5a8..340325ec97c6 100644
--- a/arch/arm64/kernel/probes/kprobes.c
+++ b/arch/arm64/kernel/probes/kprobes.c
@@ -544,17 +544,17 @@ bool arch_within_kprobe_blacklist(unsigned long addr)
 void __init arch_populate_kprobe_blacklist(void)
 {
 	insert_kprobe_blacklist((unsigned long)__kprobes_text_start,
-				(unsigned long)__kprobes_text_end);
+				(unsigned long)__kprobes_text_end, "[__kprobes]");
 	insert_kprobe_blacklist((unsigned long)__entry_text_start,
-				(unsigned long)__entry_text_end);
+				(unsigned long)__entry_text_end, "[__entry]");
 	insert_kprobe_blacklist((unsigned long)__idmap_text_start,
-				(unsigned long)__idmap_text_end);
+				(unsigned long)__idmap_text_end, "[__idmap]");
 
 	if (!is_kernel_in_hyp_mode()) {
 		insert_kprobe_blacklist((unsigned long)__hyp_text_start,
-					(unsigned long)__hyp_text_end);
+					(unsigned long)__hyp_text_end, "[__hyp]");
 		insert_kprobe_blacklist((unsigned long)__hyp_idmap_text_start,
-					(unsigned long)__hyp_idmap_text_end);
+					(unsigned long)__hyp_idmap_text_end, "[__hyp_idmap]");
 	}
 }
 
diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobes.c
index f707e42b3482..1b873e19d29b 100644
--- a/arch/powerpc/kernel/kprobes.c
+++ b/arch/powerpc/kernel/kprobes.c
@@ -52,9 +52,9 @@ int is_current_kprobe_addr(unsigned long addr)
 void __init arch_populate_kprobe_blacklist(void)
 {
 	insert_kprobe_blacklist((unsigned long)__kprobes_text_start,
-				(unsigned long)__kprobes_text_end);
+				(unsigned long)__kprobes_text_end, "[__kprobes]");
 	insert_kprobe_blacklist((unsigned long)_stext,
-				(unsigned long)__head_end);
+				(unsigned long)__head_end, "[__exceptions]");
 }
 
 kprobe_opcode_t *kprobe_lookup_name(const char *name, unsigned int offset)
diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
index 4a5fc04b3e92..20e71d783bcf 100644
--- a/arch/x86/kernel/kprobes/core.c
+++ b/arch/x86/kernel/kprobes/core.c
@@ -1144,9 +1144,9 @@ NOKPROBE_SYMBOL(longjmp_break_handler);
 void __init arch_populate_kprobe_blacklist(void)
 {
 	insert_kprobe_blacklist((unsigned long)__kprobes_text_start,
-				(unsigned long)__kprobes_text_end);
+				(unsigned long)__kprobes_text_end, "[__kprobes]");
 	insert_kprobe_blacklist((unsigned long)__entry_text_start,
-				(unsigned long)__entry_text_end);
+				(unsigned long)__entry_text_end, "[__entry]");
 }
 
 int __init arch_init_kprobes(void)
diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h
index 6d931ea0604e..05a4f2619cdc 100644
--- a/include/linux/kprobes.h
+++ b/include/linux/kprobes.h
@@ -210,6 +210,7 @@ struct kprobe_blacklist_entry {
 	struct list_head list;
 	unsigned long start_addr;
 	unsigned long end_addr;
+	char *name;
 };
 
 #ifdef CONFIG_KPROBES
@@ -271,7 +272,7 @@ extern bool arch_function_offset_within_entry(unsigned long offset);
 extern bool function_offset_within_entry(kprobe_opcode_t *addr, const char *sym, unsigned long offset);
 
 extern bool within_kprobe_blacklist(unsigned long addr);
-extern void insert_kprobe_blacklist(unsigned long start, unsigned long end);
+extern void insert_kprobe_blacklist(unsigned long start, unsigned long end, const char *name);
 extern void arch_populate_kprobe_blacklist(void);
 
 struct kprobe_insn_cache {
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 8ddbee01ce01..fcb1765de49e 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -2125,7 +2125,8 @@ NOKPROBE_SYMBOL(dump_kprobe);
 extern unsigned long __start_kprobe_blacklist[];
 extern unsigned long __stop_kprobe_blacklist[];
 
-void __init insert_kprobe_blacklist(unsigned long start, unsigned long end)
+void __init insert_kprobe_blacklist(unsigned long start, unsigned long end,
+						const char *name)
 {
 	struct kprobe_blacklist_entry *ent;
 
@@ -2137,6 +2138,7 @@ void __init insert_kprobe_blacklist(unsigned long start, unsigned long end)
 
 	ent->start_addr = start;
 	ent->end_addr = end;
+	ent->name = kstrdup(name, GFP_KERNEL);
 	INIT_LIST_HEAD(&ent->list);
 	list_add_tail(&ent->list, &kprobe_blacklist);
 }
@@ -2145,7 +2147,7 @@ void __weak __init arch_populate_kprobe_blacklist(void)
 {
 	/* The __kprobes marked functions and entry code must not be probed */
 	insert_kprobe_blacklist((unsigned long)__kprobes_text_start,
-				(unsigned long)__kprobes_text_end);
+				(unsigned long)__kprobes_text_end, "[__kprobes]");
 }
 
 static void __init populate_kprobe_blacklist(void)
@@ -2165,7 +2167,7 @@ static void __init populate_kprobe_blacklist(void)
 			continue;
 		}
 
-		insert_kprobe_blacklist(entry, entry + size);
+		insert_kprobe_blacklist(entry, entry + size, NULL);
 	}
 
 	/* Let architectures add their own entries as well */
@@ -2378,8 +2380,13 @@ static int kprobe_blacklist_seq_show(struct seq_file *m, void *v)
 	struct kprobe_blacklist_entry *ent =
 		list_entry(v, struct kprobe_blacklist_entry, list);
 
-	seq_printf(m, "0x%p-0x%p\t%ps\n", (void *)ent->start_addr,
-		   (void *)ent->end_addr, (void *)ent->start_addr);
+	if (ent->name)
+		seq_printf(m, "0x%p-0x%p\t%s\n", (void *)ent->start_addr,
+			   (void *)ent->end_addr, ent->name);
+	else
+		seq_printf(m, "0x%p-0x%p\t%ps\n", (void *)ent->start_addr,
+			   (void *)ent->end_addr, (void *)ent->start_addr);
+
 	return 0;
 }
 
-- 
2.13.1

  parent reply	other threads:[~2017-06-29 14:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-29 14:08 [RFC PATCH 0/2] Show kprobe blacklisted address ranges in debugfs Naveen N. Rao
2017-06-29 14:08 ` [RFC PATCH 1/2] kprobes: Simplify kprobe blacklist management Naveen N. Rao
2017-07-03  3:22   ` Masami Hiramatsu
2017-06-29 14:08 ` Naveen N. Rao [this message]
2017-07-03  3:22   ` [RFC PATCH 2/2] kprobes: Allow specifying names for certain blacklisted address ranges Masami Hiramatsu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1a6d4df94ee8a61eda657b387f88d9ce1ec1fe3a.1498744665.git.naveen.n.rao@linux.vnet.ibm.com \
    --to=naveen.n.rao@linux.vnet.ibm.com \
    --cc=ananth@linux.vnet.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=mingo@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.