lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <alpine.LNX.2.00.1410211744550.24255@pobox.suse.cz>
Date:	Tue, 21 Oct 2014 17:48:30 +0200 (CEST)
From:	Jiri Kosina <jkosina@...e.cz>
To:	Masami Hiramatsu <masami.hiramatsu.pt@...achi.com>,
	Anil S Keshavamurthy <anil.s.keshavamurthy@...el.com>,
	Ananth N Mavinakayanahalli <ananth@...ibm.com>
cc:	linux-kernel@...r.kernel.org, Josh Poimboeuf <jpoimboe@...hat.com>,
	Seth Jennings <sjenning@...hat.com>
Subject: [PATCH] kprobes: add kprobe_is_function_probed()

Add a function that allows external users (such as live patching 
mechanisms) to check whether a given function (identified by symbol name) 
has a kprobe installed in it.

Signed-off-by: Jiri Kosina <jkosina@...e.cz>
---
 include/linux/kprobes.h |  5 +++++
 kernel/kprobes.c        | 28 ++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h
index f7296e5..f760555 100644
--- a/include/linux/kprobes.h
+++ b/include/linux/kprobes.h
@@ -384,6 +384,7 @@ int disable_kprobe(struct kprobe *kp);
 int enable_kprobe(struct kprobe *kp);
 
 void dump_kprobe(struct kprobe *kp);
+bool kprobe_is_function_probed(const char *name);
 
 #else /* !CONFIG_KPROBES: */
 
@@ -459,6 +460,10 @@ static inline int enable_kprobe(struct kprobe *kp)
 {
 	return -ENOSYS;
 }
+static inline bool kprobe_is_function_probed(const char *name)
+{
+	return false;
+}
 #endif /* CONFIG_KPROBES */
 static inline int disable_kretprobe(struct kretprobe *rp)
 {
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 3995f54..27e8ddb 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -2036,6 +2036,34 @@ void dump_kprobe(struct kprobe *kp)
 NOKPROBE_SYMBOL(dump_kprobe);
 
 /*
+ * Check whether a given symbol is a probed function
+ */
+bool kprobe_is_function_probed(const char *name)
+{
+	struct hlist_head *head;
+	struct kprobe *p, *kp;
+	const char *sym = NULL;
+	unsigned long offset = 0;
+	unsigned int i;
+	char *modname, namebuf[KSYM_NAME_LEN];
+
+	preempt_disable();
+	for (i = 0; i < KPROBE_TABLE_SIZE; i++) {
+		head = &kprobe_table[i];
+		hlist_for_each_entry_rcu(p, head, hlist) {
+			sym = kallsyms_lookup((unsigned long)p->addr,
+					NULL, &offset, &modname,
+					namebuf);
+			if (!strcmp(sym, name))
+				return true;
+		}
+	}
+	preempt_enable();
+	return false;
+}
+EXPORT_SYMBOL_GPL(kprobe_is_function_probed);
+
+/*
  * Lookup and populate the kprobe_blacklist.
  *
  * Unlike the kretprobe blacklist, we'll need to determine
-- 
1.9.2
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ