Skip to content

Commit ce29856

Browse files
l0kodkees
authored andcommitted
um/ptrace: Fix the syscall number update after a ptrace
Update the syscall number after each PTRACE_SETREGS on ORIG_*AX. This is needed to get the potentially altered syscall number in the seccomp filters after RET_TRACE. This fix four seccomp_bpf tests: > [ RUN ] TRACE_syscall.skip_after_RET_TRACE > seccomp_bpf.c:1560:TRACE_syscall.skip_after_RET_TRACE:Expected -1 (18446744073709551615) == syscall(39) (26) > seccomp_bpf.c:1561:TRACE_syscall.skip_after_RET_TRACE:Expected 1 (1) == (*__errno_location ()) (22) > [ FAIL ] TRACE_syscall.skip_after_RET_TRACE > [ RUN ] TRACE_syscall.kill_after_RET_TRACE > TRACE_syscall.kill_after_RET_TRACE: Test exited normally instead of by signal (code: 1) > [ FAIL ] TRACE_syscall.kill_after_RET_TRACE > [ RUN ] TRACE_syscall.skip_after_ptrace > seccomp_bpf.c:1622:TRACE_syscall.skip_after_ptrace:Expected -1 (18446744073709551615) == syscall(39) (26) > seccomp_bpf.c:1623:TRACE_syscall.skip_after_ptrace:Expected 1 (1) == (*__errno_location ()) (22) > [ FAIL ] TRACE_syscall.skip_after_ptrace > [ RUN ] TRACE_syscall.kill_after_ptrace > TRACE_syscall.kill_after_ptrace: Test exited normally instead of by signal (code: 1) > [ FAIL ] TRACE_syscall.kill_after_ptrace Fixes: 26703c6 ("um/ptrace: run seccomp after ptrace") Signed-off-by: Mickaël Salaün <mic@digikod.net> Acked-by: Kees Cook <keescook@chromium.org> Cc: Jeff Dike <jdike@addtoit.com> Cc: Richard Weinberger <richard@nod.at> Cc: James Morris <jmorris@namei.org> Cc: user-mode-linux-devel@lists.sourceforge.net Signed-off-by: James Morris <james.l.morris@oracle.com> Signed-off-by: Kees Cook <keescook@chromium.org>
1 parent 972939e commit ce29856

3 files changed

Lines changed: 7 additions & 5 deletions

File tree

‎arch/um/kernel/skas/syscall.c‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,7 @@ void handle_syscall(struct uml_pt_regs *r)
2727
if (secure_computing(NULL) == -1)
2828
goto out;
2929

30-
/* Update the syscall number after orig_ax has potentially been updated
31-
* with ptrace.
32-
*/
33-
UPT_SYSCALL_NR(r) = PT_SYSCALL_NR(r->gp);
3430
syscall = UPT_SYSCALL_NR(r);
35-
3631
if (syscall >= 0 && syscall <= __NR_syscall_max)
3732
PT_REGS_SET_SYSCALL_RETURN(regs,
3833
EXECUTE_SYSCALL(syscall, regs));

‎arch/x86/um/ptrace_32.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ int putreg(struct task_struct *child, int regno, unsigned long value)
8484
case EAX:
8585
case EIP:
8686
case UESP:
87+
break;
8788
case ORIG_EAX:
89+
/* Update the syscall number. */
90+
UPT_SYSCALL_NR(&child->thread.regs.regs) = value;
8891
break;
8992
case FS:
9093
if (value && (value & 3) != 3)

‎arch/x86/um/ptrace_64.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ int putreg(struct task_struct *child, int regno, unsigned long value)
7878
case RSI:
7979
case RDI:
8080
case RBP:
81+
break;
82+
8183
case ORIG_RAX:
84+
/* Update the syscall number. */
85+
UPT_SYSCALL_NR(&child->thread.regs.regs) = value;
8286
break;
8387

8488
case FS:

0 commit comments

Comments
 (0)