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-prev] [thread-next>] [day] [month] [year] [list]
Date:   Wed, 31 Mar 2021 14:44:45 +0900
From:   Masami Hiramatsu <mhiramat@...nel.org>
To:     Josh Poimboeuf <jpoimboe@...hat.com>,
        Ingo Molnar <mingo@...nel.org>
Cc:     X86 ML <x86@...nel.org>, Masami Hiramatsu <mhiramat@...nel.org>,
        Daniel Xu <dxu@...uu.xyz>, linux-kernel@...r.kernel.org,
        bpf@...r.kernel.org, kuba@...nel.org, mingo@...hat.com,
        ast@...nel.org, tglx@...utronix.de, kernel-team@...com, yhs@...com,
        Steven Rostedt <rostedt@...dmis.org>
Subject: [RFC PATCH -tip 2/3] kprobes: Add functions to find instruction buffer entry address

Add find_kprobe_{insn,optinsn}_slot_entry() functions to find
corresponding entry address of the kprobe instrurction buffer
which includes given address.

Signed-off-by: Masami Hiramatsu <mhiramat@...nel.org>
---
 include/linux/kprobes.h |    8 ++++++++
 kernel/kprobes.c        |   25 ++++++++++++++++++-------
 2 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h
index f530f82a046d..08adfd6cf562 100644
--- a/include/linux/kprobes.h
+++ b/include/linux/kprobes.h
@@ -305,6 +305,8 @@ extern void __free_insn_slot(struct kprobe_insn_cache *c,
 /* sleep-less address checking routine  */
 extern bool __is_insn_slot_addr(struct kprobe_insn_cache *c,
 				unsigned long addr);
+extern unsigned long
+__find_insn_slot_entry(struct kprobe_insn_cache *c, unsigned long addr);
 
 #define DEFINE_INSN_CACHE_OPS(__name)					\
 extern struct kprobe_insn_cache kprobe_##__name##_slots;		\
@@ -322,6 +324,12 @@ static inline void free_##__name##_slot(kprobe_opcode_t *slot, int dirty)\
 static inline bool is_kprobe_##__name##_slot(unsigned long addr)	\
 {									\
 	return __is_insn_slot_addr(&kprobe_##__name##_slots, addr);	\
+}									\
+									\
+static inline unsigned long						\
+find_kprobe_##__name##_slot_entry(unsigned long addr)			\
+{									\
+	return __find_insn_slot_entry(&kprobe_##__name##_slots, addr);	\
 }
 #define KPROBE_INSN_PAGE_SYM		"kprobe_insn_page"
 #define KPROBE_OPTINSN_PAGE_SYM		"kprobe_optinsn_page"
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 4ce3e6f5d28d..b62635969fa6 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -277,26 +277,37 @@ void __free_insn_slot(struct kprobe_insn_cache *c,
 }
 
 /*
- * Check given address is on the page of kprobe instruction slots.
- * This will be used for checking whether the address on a stack
- * is on a text area or not.
+ * Find the entry address of the kprobe instruction slots where the
+ * @addr points.
  */
-bool __is_insn_slot_addr(struct kprobe_insn_cache *c, unsigned long addr)
+unsigned long
+__find_insn_slot_entry(struct kprobe_insn_cache *c, unsigned long addr)
 {
 	struct kprobe_insn_page *kip;
-	bool ret = false;
+	unsigned long entry = 0, index;
 
 	rcu_read_lock();
 	list_for_each_entry_rcu(kip, &c->pages, list) {
 		if (addr >= (unsigned long)kip->insns &&
 		    addr < (unsigned long)kip->insns + PAGE_SIZE) {
-			ret = true;
+			index = (addr - (unsigned long)kip->insns) / c->insn_size;
+			entry = (unsigned long)kip->insns + (index * c->insn_size);
 			break;
 		}
 	}
 	rcu_read_unlock();
 
-	return ret;
+	return entry;
+}
+
+/*
+ * Check given address is on the page of kprobe instruction slots.
+ * This will be used for checking whether the address on a stack
+ * is on a text area or not.
+ */
+bool __is_insn_slot_addr(struct kprobe_insn_cache *c, unsigned long addr)
+{
+	return __find_insn_slot_entry(c, addr) != 0;
 }
 
 int kprobe_cache_get_kallsym(struct kprobe_insn_cache *c, unsigned int *symnum,

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ