^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/seccomp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <kern_util.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <sysdep/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <sysdep/ptrace_user.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <sysdep/syscalls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/time-internal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <asm/unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) void handle_syscall(struct uml_pt_regs *r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) struct pt_regs *regs = container_of(r, struct pt_regs, regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) int syscall;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * If we have infinite CPU resources, then make every syscall also a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * preemption point, since we don't have any other preemption in this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * case, and kernel threads would basically never run until userspace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * went to sleep, even if said userspace interacts with the kernel in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * various ways.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) if (time_travel_mode == TT_MODE_INFCPU ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) time_travel_mode == TT_MODE_EXTERNAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) schedule();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) /* Initialize the syscall number and default return value. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) UPT_SYSCALL_NR(r) = PT_SYSCALL_NR(r->gp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) PT_REGS_SET_SYSCALL_RETURN(regs, -ENOSYS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) if (syscall_trace_enter(regs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) /* Do the seccomp check after ptrace; failures should be fast. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) if (secure_computing() == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) syscall = UPT_SYSCALL_NR(r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) if (syscall >= 0 && syscall <= __NR_syscall_max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) PT_REGS_SET_SYSCALL_RETURN(regs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) EXECUTE_SYSCALL(syscall, regs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) syscall_trace_leave(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) }