浏览代码

[PATCH] kprobes/ia64: refuse kprobe on ivt code

Not safe to insert kprobes on IVT code.

This patch checks to see if the address on which Kprobes is being inserted is
in ivt code and if it is in ivt code then refuse to register kprobe.

Signed-off-by: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
Acked-by: David Mosberger <davidm@napali.hpl.hp.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Keshavamurthy Anil S 20 年之前
父节点
当前提交
c7b645f934
共有 3 个文件被更改,包括 23 次插入3 次删除
  1. 16 2
      arch/ia64/kernel/kprobes.c
  2. 6 1
      arch/ia64/kernel/vmlinux.lds.S
  3. 1 0
      include/asm-ia64/sections.h

+ 16 - 2
arch/ia64/kernel/kprobes.c

@@ -34,6 +34,7 @@
 
 
 #include <asm/pgtable.h>
 #include <asm/pgtable.h>
 #include <asm/kdebug.h>
 #include <asm/kdebug.h>
+#include <asm/sections.h>
 
 
 extern void jprobe_inst_return(void);
 extern void jprobe_inst_return(void);
 
 
@@ -263,14 +264,27 @@ static inline void get_kprobe_inst(bundle_t *bundle, uint slot,
 	}
 	}
 }
 }
 
 
+/* Returns non-zero if the addr is in the Interrupt Vector Table */
+static inline int in_ivt_functions(unsigned long addr)
+{
+	return (addr >= (unsigned long)__start_ivt_text
+		&& addr < (unsigned long)__end_ivt_text);
+}
+
 static int valid_kprobe_addr(int template, int slot, unsigned long addr)
 static int valid_kprobe_addr(int template, int slot, unsigned long addr)
 {
 {
 	if ((slot > 2) || ((bundle_encoding[template][1] == L) && slot > 1)) {
 	if ((slot > 2) || ((bundle_encoding[template][1] == L) && slot > 1)) {
-		printk(KERN_WARNING "Attempting to insert unaligned kprobe at 0x%lx\n",
-				addr);
+		printk(KERN_WARNING "Attempting to insert unaligned kprobe "
+				"at 0x%lx\n", addr);
 		return -EINVAL;
 		return -EINVAL;
 	}
 	}
 
 
+ 	if (in_ivt_functions(addr)) {
+ 		printk(KERN_WARNING "Kprobes can't be inserted inside "
+				"IVT functions at 0x%lx\n", addr);
+ 		return -EINVAL;
+ 	}
+
 	if (slot == 1 && bundle_encoding[template][1] != L) {
 	if (slot == 1 && bundle_encoding[template][1] != L) {
 		printk(KERN_WARNING "Inserting kprobes on slot #1 "
 		printk(KERN_WARNING "Inserting kprobes on slot #1 "
 		       "is not supported\n");
 		       "is not supported\n");

+ 6 - 1
arch/ia64/kernel/vmlinux.lds.S

@@ -8,6 +8,11 @@
 #define LOAD_OFFSET	(KERNEL_START - KERNEL_TR_PAGE_SIZE)
 #define LOAD_OFFSET	(KERNEL_START - KERNEL_TR_PAGE_SIZE)
 #include <asm-generic/vmlinux.lds.h>
 #include <asm-generic/vmlinux.lds.h>
 
 
+#define IVT_TEXT							\
+		VMLINUX_SYMBOL(__start_ivt_text) = .;			\
+		*(.text.ivt)						\
+		VMLINUX_SYMBOL(__end_ivt_text) = .;
+
 OUTPUT_FORMAT("elf64-ia64-little")
 OUTPUT_FORMAT("elf64-ia64-little")
 OUTPUT_ARCH(ia64)
 OUTPUT_ARCH(ia64)
 ENTRY(phys_start)
 ENTRY(phys_start)
@@ -39,7 +44,7 @@ SECTIONS
 
 
   .text : AT(ADDR(.text) - LOAD_OFFSET)
   .text : AT(ADDR(.text) - LOAD_OFFSET)
     {
     {
-	*(.text.ivt)
+	IVT_TEXT
 	*(.text)
 	*(.text)
 	SCHED_TEXT
 	SCHED_TEXT
 	LOCK_TEXT
 	LOCK_TEXT

+ 1 - 0
include/asm-ia64/sections.h

@@ -17,6 +17,7 @@ extern char __start_gate_vtop_patchlist[], __end_gate_vtop_patchlist[];
 extern char __start_gate_fsyscall_patchlist[], __end_gate_fsyscall_patchlist[];
 extern char __start_gate_fsyscall_patchlist[], __end_gate_fsyscall_patchlist[];
 extern char __start_gate_brl_fsys_bubble_down_patchlist[], __end_gate_brl_fsys_bubble_down_patchlist[];
 extern char __start_gate_brl_fsys_bubble_down_patchlist[], __end_gate_brl_fsys_bubble_down_patchlist[];
 extern char __start_unwind[], __end_unwind[];
 extern char __start_unwind[], __end_unwind[];
+extern char __start_ivt_text[], __end_ivt_text[];
 
 
 #endif /* _ASM_IA64_SECTIONS_H */
 #endif /* _ASM_IA64_SECTIONS_H */