2019-08-25 17:49:17 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-09-04 06:57:42 +08:00
|
|
|
/*
|
2007-10-16 16:27:00 +08:00
|
|
|
* Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
|
2005-09-04 06:57:42 +08:00
|
|
|
*/
|
|
|
|
|
2012-10-08 10:27:32 +08:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/ptrace.h>
|
2015-12-30 04:35:47 +08:00
|
|
|
#include <linux/seccomp.h>
|
2012-10-08 10:27:32 +08:00
|
|
|
#include <kern_util.h>
|
|
|
|
#include <sysdep/ptrace.h>
|
2015-12-30 04:35:44 +08:00
|
|
|
#include <sysdep/ptrace_user.h>
|
2012-10-08 10:27:32 +08:00
|
|
|
#include <sysdep/syscalls.h>
|
2020-02-13 21:26:44 +08:00
|
|
|
#include <linux/time-internal.h>
|
2020-04-15 15:51:52 +08:00
|
|
|
#include <asm/unistd.h>
|
2005-09-04 06:57:42 +08:00
|
|
|
|
2007-10-16 16:26:58 +08:00
|
|
|
void handle_syscall(struct uml_pt_regs *r)
|
2005-09-04 06:57:42 +08:00
|
|
|
{
|
|
|
|
struct pt_regs *regs = container_of(r, struct pt_regs, regs);
|
|
|
|
int syscall;
|
|
|
|
|
2019-05-27 16:34:27 +08:00
|
|
|
/*
|
|
|
|
* If we have infinite CPU resources, then make every syscall also a
|
|
|
|
* preemption point, since we don't have any other preemption in this
|
|
|
|
* case, and kernel threads would basically never run until userspace
|
|
|
|
* went to sleep, even if said userspace interacts with the kernel in
|
|
|
|
* various ways.
|
|
|
|
*/
|
2020-02-13 21:26:47 +08:00
|
|
|
if (time_travel_mode == TT_MODE_INFCPU ||
|
|
|
|
time_travel_mode == TT_MODE_EXTERNAL)
|
2019-05-27 16:34:27 +08:00
|
|
|
schedule();
|
|
|
|
|
2015-12-30 04:35:44 +08:00
|
|
|
/* Initialize the syscall number and default return value. */
|
|
|
|
UPT_SYSCALL_NR(r) = PT_SYSCALL_NR(r->gp);
|
|
|
|
PT_REGS_SET_SYSCALL_RETURN(regs, -ENOSYS);
|
|
|
|
|
2016-06-03 10:59:42 +08:00
|
|
|
if (syscall_trace_enter(regs))
|
2016-08-02 05:01:55 +08:00
|
|
|
goto out;
|
2015-12-30 04:35:47 +08:00
|
|
|
|
2016-06-03 10:59:42 +08:00
|
|
|
/* Do the seccomp check after ptrace; failures should be fast. */
|
2019-09-24 14:44:20 +08:00
|
|
|
if (secure_computing() == -1)
|
2016-08-02 05:01:55 +08:00
|
|
|
goto out;
|
2005-09-04 06:57:42 +08:00
|
|
|
|
2015-12-30 04:35:44 +08:00
|
|
|
syscall = UPT_SYSCALL_NR(r);
|
|
|
|
if (syscall >= 0 && syscall <= __NR_syscall_max)
|
|
|
|
PT_REGS_SET_SYSCALL_RETURN(regs,
|
|
|
|
EXECUTE_SYSCALL(syscall, regs));
|
2005-09-04 06:57:42 +08:00
|
|
|
|
2016-08-02 05:01:55 +08:00
|
|
|
out:
|
2012-05-23 12:18:33 +08:00
|
|
|
syscall_trace_leave(regs);
|
2005-09-04 06:57:42 +08:00
|
|
|
}
|