Skip to content

Commit

Permalink
uprobes: Initialize uprobes earlier
Browse files Browse the repository at this point in the history
In order to have a separate address space for text poking, we need to
duplicate init_mm early during start_kernel(). This, however, introduces
a problem since uprobes functions are called from dup_mmap(), but
uprobes is still not initialized in this early stage.

Since uprobes initialization is necassary for fork, and since all the
dependant initialization has been done when fork is initialized (percpu
and vmalloc), move uprobes initialization to fork_init(). It does not
seem uprobes introduces any security problem for the poking_mm.

Crash and burn if uprobes initialization fails, similarly to other early
initializations. Change the init_probes() name to probes_init() to match
other early initialization functions name convention.

Reported-by: kernel test robot <[email protected]>
Signed-off-by: Nadav Amit <[email protected]>
Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Cc: Andy Lutomirski <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: H. Peter Anvin <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Rick Edgecombe <[email protected]>
Cc: Rik van Riel <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
  • Loading branch information
anadav authored and Ingo Molnar committed Apr 30, 2019
1 parent d97080e commit aad42dd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
5 changes: 5 additions & 0 deletions include/linux/uprobes.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ struct uprobes_state {
struct xol_area *xol_area;
};

extern void __init uprobes_init(void);
extern int set_swbp(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr);
extern int set_orig_insn(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr);
extern bool is_swbp_insn(uprobe_opcode_t *insn);
Expand Down Expand Up @@ -154,6 +155,10 @@ extern void arch_uprobe_copy_ixol(struct page *page, unsigned long vaddr,
struct uprobes_state {
};

static inline void uprobes_init(void)
{
}

#define uprobe_get_trap_addr(regs) instruction_pointer(regs)

static inline int
Expand Down
8 changes: 3 additions & 5 deletions kernel/events/uprobes.c
Original file line number Diff line number Diff line change
Expand Up @@ -2294,16 +2294,14 @@ static struct notifier_block uprobe_exception_nb = {
.priority = INT_MAX-1, /* notified after kprobes, kgdb */
};

static int __init init_uprobes(void)
void __init uprobes_init(void)
{
int i;

for (i = 0; i < UPROBES_HASH_SZ; i++)
mutex_init(&uprobes_mmap_mutex[i]);

if (percpu_init_rwsem(&dup_mmap_sem))
return -ENOMEM;
BUG_ON(percpu_init_rwsem(&dup_mmap_sem));

return register_die_notifier(&uprobe_exception_nb);
BUG_ON(register_die_notifier(&uprobe_exception_nb));
}
__initcall(init_uprobes);
1 change: 1 addition & 0 deletions kernel/fork.c
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,7 @@ void __init fork_init(void)
#endif

lockdep_init_task(&init_task);
uprobes_init();
}

int __weak arch_dup_task_struct(struct task_struct *dst,
Expand Down

0 comments on commit aad42dd

Please sign in to comment.