From 9201a0602706a463d65ecf4b3623235f1f82cd03 Mon Sep 17 00:00:00 2001 From: Brian Gianforcaro Date: Sun, 18 Jul 2021 11:20:12 -0700 Subject: [PATCH] Kernel: Annotate all syscalls with VERIFY_PROCESS_BIG_LOCK_ACQUIRED Before we start disabling acquisition of the big process lock for specific syscalls, make sure to document and assert that all the lock is held during all syscalls. --- Kernel/API/Syscall.h | 9 +++++++++ Kernel/Syscalls/access.cpp | 1 + Kernel/Syscalls/alarm.cpp | 1 + Kernel/Syscalls/anon_create.cpp | 1 + Kernel/Syscalls/beep.cpp | 1 + Kernel/Syscalls/chdir.cpp | 3 +++ Kernel/Syscalls/chmod.cpp | 2 ++ Kernel/Syscalls/chown.cpp | 2 ++ Kernel/Syscalls/chroot.cpp | 1 + Kernel/Syscalls/clock.cpp | 5 +++++ Kernel/Syscalls/debug.cpp | 3 +++ Kernel/Syscalls/disown.cpp | 1 + Kernel/Syscalls/dup2.cpp | 1 + Kernel/Syscalls/emuctl.cpp | 1 + Kernel/Syscalls/execve.cpp | 1 + Kernel/Syscalls/exit.cpp | 6 ++++++ Kernel/Syscalls/fcntl.cpp | 1 + Kernel/Syscalls/fork.cpp | 1 + Kernel/Syscalls/ftruncate.cpp | 1 + Kernel/Syscalls/futex.cpp | 1 + Kernel/Syscalls/get_dir_entries.cpp | 1 + Kernel/Syscalls/get_stack_bounds.cpp | 1 + Kernel/Syscalls/getrandom.cpp | 1 + Kernel/Syscalls/getuid.cpp | 7 +++++++ Kernel/Syscalls/hostname.cpp | 2 ++ Kernel/Syscalls/inode_watcher.cpp | 3 +++ Kernel/Syscalls/ioctl.cpp | 1 + Kernel/Syscalls/keymap.cpp | 1 + Kernel/Syscalls/kill.cpp | 2 ++ Kernel/Syscalls/link.cpp | 2 ++ Kernel/Syscalls/lseek.cpp | 1 + Kernel/Syscalls/mkdir.cpp | 1 + Kernel/Syscalls/mknod.cpp | 1 + Kernel/Syscalls/mmap.cpp | 8 ++++++++ Kernel/Syscalls/module.cpp | 2 ++ Kernel/Syscalls/mount.cpp | 2 ++ Kernel/Syscalls/open.cpp | 2 ++ Kernel/Syscalls/perf_event.cpp | 1 + Kernel/Syscalls/pipe.cpp | 1 + Kernel/Syscalls/pledge.cpp | 1 + Kernel/Syscalls/prctl.cpp | 1 + Kernel/Syscalls/process.cpp | 5 +++++ Kernel/Syscalls/profiling.cpp | 3 +++ Kernel/Syscalls/ptrace.cpp | 1 + Kernel/Syscalls/purge.cpp | 1 + Kernel/Syscalls/read.cpp | 2 ++ Kernel/Syscalls/readlink.cpp | 1 + Kernel/Syscalls/realpath.cpp | 1 + Kernel/Syscalls/rename.cpp | 1 + Kernel/Syscalls/rmdir.cpp | 1 + Kernel/Syscalls/sched.cpp | 3 +++ Kernel/Syscalls/select.cpp | 2 ++ Kernel/Syscalls/sendfd.cpp | 2 ++ Kernel/Syscalls/setpgid.cpp | 5 +++++ Kernel/Syscalls/setuid.cpp | 8 ++++++++ Kernel/Syscalls/shutdown.cpp | 2 ++ Kernel/Syscalls/sigaction.cpp | 4 ++++ Kernel/Syscalls/socket.cpp | 13 +++++++++++++ Kernel/Syscalls/stat.cpp | 2 ++ Kernel/Syscalls/statvfs.cpp | 2 ++ Kernel/Syscalls/sync.cpp | 1 + Kernel/Syscalls/sysconf.cpp | 1 + Kernel/Syscalls/thread.cpp | 8 ++++++++ Kernel/Syscalls/times.cpp | 1 + Kernel/Syscalls/ttyname.cpp | 2 ++ Kernel/Syscalls/umask.cpp | 1 + Kernel/Syscalls/uname.cpp | 1 + Kernel/Syscalls/unlink.cpp | 1 + Kernel/Syscalls/unveil.cpp | 1 + Kernel/Syscalls/utime.cpp | 1 + Kernel/Syscalls/waitid.cpp | 1 + Kernel/Syscalls/write.cpp | 2 ++ 72 files changed, 165 insertions(+) diff --git a/Kernel/API/Syscall.h b/Kernel/API/Syscall.h index 1357b9fc54..a0f63d6337 100644 --- a/Kernel/API/Syscall.h +++ b/Kernel/API/Syscall.h @@ -33,6 +33,15 @@ enum class NeedsBigProcessLock { No }; +// Declare all syscalls and associated metadata. +// +// NOTE: When declaring a new syscall or modifying an existing, please +// ensure that the proper assert is present at the top of the syscall +// implementation to both verify and document to any readers if the +// syscall aquires the big process lock or not. The asserts are: +// - VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this) +// - VERIFY_NO_PROCESS_BIG_LOCK(this) +// #define ENUMERATE_SYSCALLS(S) \ S(yield, NeedsBigProcessLock::Yes) \ S(open, NeedsBigProcessLock::Yes) \ diff --git a/Kernel/Syscalls/access.cpp b/Kernel/Syscalls/access.cpp index a8dc4c1aa9..267231a6d0 100644 --- a/Kernel/Syscalls/access.cpp +++ b/Kernel/Syscalls/access.cpp @@ -12,6 +12,7 @@ namespace Kernel { KResultOr Process::sys$access(Userspace user_path, size_t path_length, int mode) { + VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this); REQUIRE_PROMISE(rpath); auto path = get_syscall_path_argument(user_path, path_length); if (path.is_error()) diff --git a/Kernel/Syscalls/alarm.cpp b/Kernel/Syscalls/alarm.cpp index 1312b78061..1bbc81963b 100644 --- a/Kernel/Syscalls/alarm.cpp +++ b/Kernel/Syscalls/alarm.cpp @@ -11,6 +11,7 @@ namespace Kernel { KResultOr Process::sys$alarm(unsigned seconds) { + VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this); REQUIRE_PROMISE(stdio); unsigned previous_alarm_remaining = 0; if (m_alarm_timer) { diff --git a/Kernel/Syscalls/anon_create.cpp b/Kernel/Syscalls/anon_create.cpp index 7c95d9e1ac..6a83b9f0d7 100644 --- a/Kernel/Syscalls/anon_create.cpp +++ b/Kernel/Syscalls/anon_create.cpp @@ -13,6 +13,7 @@ namespace Kernel { KResultOr Process::sys$anon_create(size_t size, int options) { + VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this); REQUIRE_PROMISE(stdio); if (!size) diff --git a/Kernel/Syscalls/beep.cpp b/Kernel/Syscalls/beep.cpp index 337f61fa97..0f0a21a640 100644 --- a/Kernel/Syscalls/beep.cpp +++ b/Kernel/Syscalls/beep.cpp @@ -11,6 +11,7 @@ namespace Kernel { KResultOr Process::sys$beep() { + VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this); PCSpeaker::tone_on(440); auto result = Thread::current()->sleep(Time::from_nanoseconds(200'000'000)); PCSpeaker::tone_off(); diff --git a/Kernel/Syscalls/chdir.cpp b/Kernel/Syscalls/chdir.cpp index 995d098890..f3442b695a 100644 --- a/Kernel/Syscalls/chdir.cpp +++ b/Kernel/Syscalls/chdir.cpp @@ -13,6 +13,7 @@ namespace Kernel { KResultOr Process::sys$chdir(Userspace user_path, size_t path_length) { + VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this); REQUIRE_PROMISE(rpath); auto path = get_syscall_path_argument(user_path, path_length); if (path.is_error()) @@ -26,6 +27,7 @@ KResultOr Process::sys$chdir(Userspace user_path, size_t p KResultOr Process::sys$fchdir(int fd) { + VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this); REQUIRE_PROMISE(stdio); auto description = fds().file_description(fd); if (!description) @@ -43,6 +45,7 @@ KResultOr Process::sys$fchdir(int fd) KResultOr Process::sys$getcwd(Userspace buffer, size_t size) { + VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this); REQUIRE_PROMISE(rpath); if (size > NumericLimits::max()) diff --git a/Kernel/Syscalls/chmod.cpp b/Kernel/Syscalls/chmod.cpp index 387581b64c..caf55a939a 100644 --- a/Kernel/Syscalls/chmod.cpp +++ b/Kernel/Syscalls/chmod.cpp @@ -13,6 +13,7 @@ namespace Kernel { KResultOr Process::sys$chmod(Userspace user_path, size_t path_length, mode_t mode) { + VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this); REQUIRE_PROMISE(fattr); auto path = get_syscall_path_argument(user_path, path_length); if (path.is_error()) @@ -22,6 +23,7 @@ KResultOr Process::sys$chmod(Userspace user_path, size_t p KResultOr Process::sys$fchmod(int fd, mode_t mode) { + VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this); REQUIRE_PROMISE(fattr); auto description = fds().file_description(fd); if (!description) diff --git a/Kernel/Syscalls/chown.cpp b/Kernel/Syscalls/chown.cpp index 33e155f12f..6e899ec046 100644 --- a/Kernel/Syscalls/chown.cpp +++ b/Kernel/Syscalls/chown.cpp @@ -11,6 +11,7 @@ namespace Kernel { KResultOr Process::sys$fchown(int fd, uid_t uid, gid_t gid) { + VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this); REQUIRE_PROMISE(chown); auto description = fds().file_description(fd); if (!description) @@ -20,6 +21,7 @@ KResultOr Process::sys$fchown(int fd, uid_t uid, gid_t gid) KResultOr Process::sys$chown(Userspace user_params) { + VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this); REQUIRE_PROMISE(chown); Syscall::SC_chown_params params; if (!copy_from_user(¶ms, user_params)) diff --git a/Kernel/Syscalls/chroot.cpp b/Kernel/Syscalls/chroot.cpp index 67ca084bdb..5f13bccc91 100644 --- a/Kernel/Syscalls/chroot.cpp +++ b/Kernel/Syscalls/chroot.cpp @@ -13,6 +13,7 @@ namespace Kernel { KResultOr Process::sys$chroot(Userspace user_path, size_t path_length, int mount_flags) { + VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this); if (!is_superuser()) return EPERM; REQUIRE_PROMISE(chroot); diff --git a/Kernel/Syscalls/clock.cpp b/Kernel/Syscalls/clock.cpp index ab20e666f0..990447ade2 100644 --- a/Kernel/Syscalls/clock.cpp +++ b/Kernel/Syscalls/clock.cpp @@ -12,6 +12,7 @@ namespace Kernel { KResultOr Process::sys$clock_gettime(clockid_t clock_id, Userspace user_ts) { + VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this); REQUIRE_PROMISE(stdio); if (!TimeManagement::is_valid_clock_id(clock_id)) @@ -26,6 +27,7 @@ KResultOr Process::sys$clock_gettime(clockid_t clock_id, Userspace