Skip to content

Commit 785d3cd

Browse files
Nicolas PitreRussell King
authored andcommitted
ARM kprobes: prevent some functions involved with kprobes from being probed
Signed-off-by: Nicolas Pitre <nico@marvell.com>
1 parent d30a0c8 commit 785d3cd

File tree

6 files changed

+20
-13
lines changed

6 files changed

+20
-13
lines changed

arch/arm/kernel/entry-armv.S

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@
5858

5959
.endm
6060

61+
#ifdef CONFIG_KPROBES
62+
.section .kprobes.text,"ax",%progbits
63+
#else
64+
.text
65+
#endif
66+
6167
/*
6268
* Invalid mode handlers
6369
*/
@@ -562,7 +568,7 @@ do_fpe:
562568
.data
563569
ENTRY(fp_enter)
564570
.word no_fp
565-
.text
571+
.previous
566572

567573
no_fp: mov pc, lr
568574

arch/arm/kernel/kprobes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p)
5555
unsigned long addr = (unsigned long)p->addr;
5656
int is;
5757

58-
if (addr & 0x3)
58+
if (addr & 0x3 || in_exception_text(addr))
5959
return -EINVAL;
6060

6161
insn = *p->addr;

arch/arm/kernel/traps.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,6 @@ __setup("user_debug=", user_debug_setup);
4646

4747
static void dump_mem(const char *str, unsigned long bottom, unsigned long top);
4848

49-
static inline int in_exception_text(unsigned long ptr)
50-
{
51-
extern char __exception_text_start[];
52-
extern char __exception_text_end[];
53-
54-
return ptr >= (unsigned long)&__exception_text_start &&
55-
ptr < (unsigned long)&__exception_text_end;
56-
}
57-
5849
void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
5950
{
6051
#ifdef CONFIG_KALLSYMS

arch/arm/kernel/vmlinux.lds.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ SECTIONS
9494
TEXT_TEXT
9595
SCHED_TEXT
9696
LOCK_TEXT
97+
KPROBES_TEXT
9798
#ifdef CONFIG_MMU
9899
*(.fixup)
99100
#endif

arch/arm/mm/fault.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ __do_page_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
239239
return fault;
240240
}
241241

242-
static int
242+
static int __kprobes
243243
do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
244244
{
245245
struct task_struct *tsk;
@@ -338,7 +338,7 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
338338
* interrupt or a critical region, and should only copy the information
339339
* from the master page table, nothing more.
340340
*/
341-
static int
341+
static int __kprobes
342342
do_translation_fault(unsigned long addr, unsigned int fsr,
343343
struct pt_regs *regs)
344344
{

include/asm-arm/traps.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,13 @@ struct undef_hook {
1515
void register_undef_hook(struct undef_hook *hook);
1616
void unregister_undef_hook(struct undef_hook *hook);
1717

18+
static inline int in_exception_text(unsigned long ptr)
19+
{
20+
extern char __exception_text_start[];
21+
extern char __exception_text_end[];
22+
23+
return ptr >= (unsigned long)&__exception_text_start &&
24+
ptr < (unsigned long)&__exception_text_end;
25+
}
26+
1827
#endif

0 commit comments

Comments
 (0)