Skip to content

Commit

Permalink
core/entry: Report syscall correctly for trace and audit
Browse files Browse the repository at this point in the history
On v5.8 when doing seccomp syscall rewrites (e.g. getpid into getppid
as seen in the seccomp selftests), trace (and audit) correctly see the
rewritten syscall on entry and exit:

	seccomp_bpf-1307  [000] .... 22974.874393: sys_enter: NR 110 (...
	seccomp_bpf-1307  [000] .N.. 22974.874401: sys_exit: NR 110 = 1304

With mainline we see a mismatched enter and exit (the original syscall
is incorrectly visible on entry):

	seccomp_bpf-1030  [000] ....    21.806766: sys_enter: NR 39 (...
	seccomp_bpf-1030  [000] ....    21.806767: sys_exit: NR 110 = 1027

When ptrace or seccomp change the syscall, this needs to be visible to
trace and audit at that time as well. Update the syscall earlier so they
see the correct value.

Fixes: d88d59b ("core/entry: Respect syscall number rewrites")
Reported-by: Michael Ellerman <mpe@ellerman.id.au>
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20200912005826.586171-1-keescook@chromium.org
  • Loading branch information
kees authored and Thomas Gleixner committed Sep 14, 2020
1 parent 856deb8 commit b6ec413
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions kernel/entry/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,15 @@ static long syscall_trace_enter(struct pt_regs *regs, long syscall,
return ret;
}

/* Either of the above might have changed the syscall number */
syscall = syscall_get_nr(current, regs);

if (unlikely(ti_work & _TIF_SYSCALL_TRACEPOINT))
trace_sys_enter(regs, syscall);

syscall_enter_audit(regs, syscall);

/* The above might have changed the syscall number */
return ret ? : syscall_get_nr(current, regs);
return ret ? : syscall;
}

static __always_inline long
Expand Down

0 comments on commit b6ec413

Please sign in to comment.