Skip to content

Commit fa6192a

Browse files
olsajiriIngo Molnar
authored andcommitted
uprobes/x86: Harden uretprobe syscall trampoline check
Jann reported a possible issue when trampoline_check_ip returns address near the bottom of the address space that is allowed to call into the syscall if uretprobes are not set up: https://lore.kernel.org/bpf/202502081235.5A6F352985@keescook/T/#m9d416df341b8fbc11737dacbcd29f0054413cbbf Though the mmap minimum address restrictions will typically prevent creating mappings there, let's make sure uretprobe syscall checks for that. Fixes: ff474a7 ("uprobe: Add uretprobe syscall to speed up return probe") Reported-by: Jann Horn <[email protected]> Signed-off-by: Jiri Olsa <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Reviewed-by: Oleg Nesterov <[email protected]> Reviewed-by: Kees Cook <[email protected]> Acked-by: Andrii Nakryiko <[email protected]> Acked-by: Masami Hiramatsu (Google) <[email protected]> Acked-by: Alexei Starovoitov <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/[email protected]
1 parent 0576388 commit fa6192a

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

arch/x86/kernel/uprobes.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -357,19 +357,23 @@ void *arch_uprobe_trampoline(unsigned long *psize)
357357
return &insn;
358358
}
359359

360-
static unsigned long trampoline_check_ip(void)
360+
static unsigned long trampoline_check_ip(unsigned long tramp)
361361
{
362-
unsigned long tramp = uprobe_get_trampoline_vaddr();
363-
364362
return tramp + (uretprobe_syscall_check - uretprobe_trampoline_entry);
365363
}
366364

367365
SYSCALL_DEFINE0(uretprobe)
368366
{
369367
struct pt_regs *regs = task_pt_regs(current);
370-
unsigned long err, ip, sp, r11_cx_ax[3];
368+
unsigned long err, ip, sp, r11_cx_ax[3], tramp;
369+
370+
/* If there's no trampoline, we are called from wrong place. */
371+
tramp = uprobe_get_trampoline_vaddr();
372+
if (unlikely(tramp == UPROBE_NO_TRAMPOLINE_VADDR))
373+
goto sigill;
371374

372-
if (regs->ip != trampoline_check_ip())
375+
/* Make sure the ip matches the only allowed sys_uretprobe caller. */
376+
if (unlikely(regs->ip != trampoline_check_ip(tramp)))
373377
goto sigill;
374378

375379
err = copy_from_user(r11_cx_ax, (void __user *)regs->sp, sizeof(r11_cx_ax));

include/linux/uprobes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ struct page;
3939

4040
#define MAX_URETPROBE_DEPTH 64
4141

42+
#define UPROBE_NO_TRAMPOLINE_VADDR (~0UL)
43+
4244
struct uprobe_consumer {
4345
/*
4446
* handler() can return UPROBE_HANDLER_REMOVE to signal the need to

kernel/events/uprobes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2169,8 +2169,8 @@ void uprobe_copy_process(struct task_struct *t, unsigned long flags)
21692169
*/
21702170
unsigned long uprobe_get_trampoline_vaddr(void)
21712171
{
2172+
unsigned long trampoline_vaddr = UPROBE_NO_TRAMPOLINE_VADDR;
21722173
struct xol_area *area;
2173-
unsigned long trampoline_vaddr = -1;
21742174

21752175
/* Pairs with xol_add_vma() smp_store_release() */
21762176
area = READ_ONCE(current->mm->uprobes_state.xol_area); /* ^^^ */

0 commit comments

Comments
 (0)