summaryrefslogtreecommitdiff
path: root/Kernel/Process.h
AgeCommit message (Collapse)Author
2022-12-16Kernel: Reintroduce the msyscall syscall as the annotate_mapping syscallLiav A
This syscall will be used later on to ensure we can declare virtual memory mappings as immutable (which means that the underlying Region is basically immutable for both future annotations or changing the protection bits of it).
2022-12-14Kernel: Add the auxiliary vector to the stack size validationAgustin Gianni
This patch validates that the size of the auxiliary vector does not exceed `Process::max_auxiliary_size`. The auxiliary vector is a range of memory in userspace stack where the kernel can pass information to the process that will be created via `Process:do_exec`. The reason the kernel needs to validate its size is that the about to be created process needs to have remaining space on the stack. Previously only `argv` and `envp` were taken into account for the size validation, with this patch, the size of `auxv` is also checked. All three elements contain values that a user (or an attacker) can specify. This patch adds the constant `Process::max_auxiliary_size` which is defined to be one eight of the user-space stack size. This is the approach taken by `Process:max_arguments_size` and `Process::max_environment_size` which are used to check the sizes of `argv` and `envp`.
2022-12-11Kernel+LibC+Tests: Implement `pwritev(2)`sin-ack
While this isn't really POSIX, it's needed by the Zig port and was simple enough to implement.
2022-12-11Kernel+LibC: Implement `setregid(2)`sin-ack
This copies and adapts the setresgid syscall, following in the footsteps of setreuid and setresuid.
2022-12-11Kernel+LibC+LibCore+UserspaceEmulator: Implement `faccessat(2)`sin-ack
Co-Authored-By: Daniel Bertalan <dani@danielbertalan.dev>
2022-12-11Kernel+LibC+LibCore: Implement `mkdirat(2)`sin-ack
2022-12-11Kernel: Implement Process::custody_for_dirfdsin-ack
This allows deduplicating a bunch of code that has to work with POSIX' *at syscall semantics.
2022-11-26Kernel+LibCore+LibC: Implement support for forcing unveil on execLiav A
To accomplish this, we add another VeilState which is called LockedInherited. The idea is to apply exec unveil data, similar to execpromises of the pledge syscall, on the current exec'ed program during the execve sequence. When applying the forced unveil data, the veil state is set to be locked but the special state of LockedInherited ensures that if the new program tries to unveil paths, the request will silently be ignored, so the program will continue running without receiving an error, but is still can only use the paths that were unveiled before the exec syscall. This in turn, allows us to use the unveil syscall with a special utility to sandbox other userland programs in terms of what is visible to them on the filesystem, and is usable on both programs that use or don't use the unveil syscall in their code.
2022-11-05Kernel: Add support for jailsLiav A
Our implementation for Jails resembles much of how FreeBSD jails are working - it's essentially only a matter of using a RefPtr in the Process class to a Jail object. Then, when we iterate over all processes in various cases, we could ensure if either the current process is in jail and therefore should be restricted what is visible in terms of PID isolation, and also to be able to expose metadata about Jails in /sys/kernel/jails node (which does not reveal anything to a process which is in jail). A lifetime model for the Jail object is currently plain simple - there's simpy no way to manually delete a Jail object once it was created. Such feature should be carefully designed to allow safe destruction of a Jail without the possibility of releasing a process which is in Jail from the actual jail. Each process which is attached into a Jail cannot leave it until the end of a Process (i.e. when finalizing a Process). All jails are kept being referenced in the JailManagement. When a last attached process is finalized, the Jail is automatically destroyed.
2022-10-27Kernel: Make scheduler control syscalls more generickleines Filmröllchen
The syscalls are renamed as they no longer reflect the exact POSIX functionality. They can now handle setting/getting scheduler parameters for both threads and processes.
2022-08-27Kernel: Stop verifying interrupts are disabled in Process::for_eachIdan Horowitz
This is a left-over from back when we didn't have any locking on the global Process list, nor did we have SMP support, so this acted as some kind of locking mechanism. We now have proper locks around the Process list, so this is no longer relevant.
2022-08-24Kernel: Make file-backed memory regions remember description permissionsAndreas Kling
This allows sys$mprotect() to honor the original readable & writable flags of the open file description as they were at the point we did the original sys$mmap(). IIUC, this is what Dr. POSIX wants us to do: https://pubs.opengroup.org/onlinepubs/9699919799/functions/mprotect.html Also, remove the bogus and racy "W^X" checking we did against mappings based on their current inode metadata. If we want to do this, we can do it properly. For now, it was not only racy, but also did blocking I/O while holding a spinlock.
2022-08-24Kernel: Wrap process address spaces in SpinlockProtectedAndreas Kling
This forces anyone who wants to look into and/or manipulate an address space to lock it. And this replaces the previous, more flimsy, manual spinlock use. Note that pointers *into* the address space are not safe to use after you unlock the space. We've got many issues like this, and we'll have to track those down as wlel.
2022-08-23Kernel: Fix boot profilingSamuel Bowman
Boot profiling was previously broken due to init_stage2() passing the event mask to sys$profiling_enable() via kernel pointer, but a user pointer is expected. To fix this, I added Process::profiling_enable() as an alternative to Process::sys$profiling_enable which takes a u64 rather than a Userspace<u64 const*>. It's a bit of a hack, but it works.
2022-08-23Kernel: Remove unused Process::in_group()Anthony Iacono
2022-08-22Kernel: Use Process::credentials() and remove user ID/group ID helpersAnthony Iacono
Move away from using the group ID/user ID helpers in the process to allow for us to take advantage of the immutable credentials instead.
2022-08-21Kernel: Guard Process "protected data" with a spinlockAndreas Kling
This ensures that both mutable and immutable access to the protected data of a process is serialized. Note that there may still be multiple TOCTOU issues around this, as we have a bunch of convenience accessors that make it easy to introduce them. We'll need to audit those as well.
2022-08-21Kernel: Use RefPtr instead of LockRefPtr for CustodyAndreas Kling
By protecting all the RefPtr<Custody> objects that may be accessed from multiple threads at the same time (with spinlocks), we remove the need for using LockRefPtr<Custody> (which is basically a RefPtr with a built-in spinlock.)
2022-08-20Kernel: Add Credentials to hold a set of user and group IDsAndreas Kling
This patch adds a new object to hold a Process's user credentials: - UID, EUID, SUID - GID, EGID, SGID, extra GIDs Credentials are immutable and child processes initially inherit the Credentials object from their parent. Whenever a process changes one or more of its user/group IDs, a new Credentials object is constructed. Any code that wants to inspect and act on a set of credentials can now do so without worrying about data races.
2022-08-20Kernel: Move InodeMetadata methods out of lineAndreas Kling
2022-08-20Kernel: Make self-contained locking smart pointers their own classesAndreas Kling
Until now, our kernel has reimplemented a number of AK classes to provide automatic internal locking: - RefPtr - NonnullRefPtr - WeakPtr - Weakable This patch renames the Kernel classes so that they can coexist with the original AK classes: - RefPtr => LockRefPtr - NonnullRefPtr => NonnullLockRefPtr - WeakPtr => LockWeakPtr - Weakable => LockWeakable The goal here is to eventually get rid of the Lock* classes in favor of using external locking.
2022-08-19Kernel: Require lock rank for Spinlock constructionkleines Filmröllchen
All users which relied on the default constructor use a None lock rank for now. This will make it easier to in the future remove LockRank and actually annotate the ranks by searching for None.
2022-08-17Kernel: Require semicolon after VERIFY_{NO_,}PROCESS_BIG_LOCK_ACQUIREDLinus Groh
This matches out general macro use, and specifically other verification macros like VERIFY(), VERIFY_NOT_REACHED(), VERIFY_INTERRUPTS_ENABLED(), and VERIFY_INTERRUPTS_DISABLED().
2022-08-16Kernel: Don't leak file descriptors in sys$pipe()Andreas Kling
If the final copy_to_user() call fails when writing the file descriptors to the output array, we have to make sure the file descriptors don't remain in the process file descriptor table. Otherwise they are basically leaked, as userspace is not aware of them. This matches the behavior of our sys$socketpair() implementation.
2022-07-25Kernel/LibC: Implement posix syscall clock_getres()zzLinus
2022-07-21Kernel: Clean up sys$futex and add support for cross-process futexesIdan Horowitz
2022-07-21Kernel: Propagate OOM conditions out of sys$futexIdan Horowitz
2022-07-15Kernel+LibC: Add posix_fallocate syscallHendiadyoin1
2022-07-12Everywhere: Add sv suffix to strings relying on StringView(char const*)sin-ack
Each of these strings would previously rely on StringView's char const* constructor overload, which would call __builtin_strlen on the string. Since we now have operator ""sv, we can replace these with much simpler versions. This opens the door to being able to remove StringView(char const*). No functional changes.
2022-07-10Kernel+LibC+LibCore: Pass fcntl extra argument as pointer-sized variablegggggg-gggggg
The extra argument to fcntl is a pointer in the case of F_GETLK/F_SETLK and we were pulling out a u32, leading to pointer truncation on x86_64. Among other things, this fixes Assistant on x86_64 :^)
2022-07-08Kernel: Implement `sigsuspend` using a SignalBlockerTim Schumacher
`sigsuspend` was previously implemented using a poll on an empty set of file descriptors. However, this broke quite a few assumptions in `SelectBlocker`, as it verifies at least one file descriptor to be ready after waking up and as it relies on being notified by the file descriptor. A bare-bones `sigsuspend` may also be implemented by relying on any of the `sigwait` functions, but as `sigsuspend` features several (currently unimplemented) restrictions on how returns work, it is a syscall on its own.
2022-07-05Kernel: Do a POSIX-correct signal handler reset on execTim Schumacher
2022-06-19Kernel: Create /proc/pid/cmdline to expose process arguments in procfsAndrew Kaster
In typical serenity style, they are just a JSON array
2022-05-21Kernel+LibC+VFS: Implement utimensat(3)Ariel Don
Create POSIX utimensat() library call and corresponding system call to update file access and modification times.
2022-05-06Kernel: Add /proc/{pid}/children to ProcFSMacDue
This exposes the child processes for a process as a directory of symlinks to the respective /proc entries for each child. This makes for an easier and possibly more efficient way to find and count a process's children. Previously the only method was to parse the entire /proc/all JSON file.
2022-04-23Kernel+LibC+LibCore: Implement the unlinkat(2) syscallsin-ack
2022-04-09Kernel: Remove big lock from `sys$set_coredump_metadata`Luke Wilde
The only requirement for this syscall is to make Process::m_coredump_properties SpinlockProtected.
2022-04-06Kernel: Track big lock blocked threads in separate listJelle Raaijmakers
When we lock a mutex, eventually `Thread::block` is invoked which could in turn invoke `Process::big_lock().restore_exclusive_lock()`. This would then try to add the current thread to a different blocked thread list then the one in use for the original mutex being locked, and because it's an intrusive list, the thread is removed from its original list during the `.append()`. When the original mutex eventually unblocks, we no longer have the thread in the intrusive blocked threads list and we panic. Solve this by making the big lock mutex special and giving it its own blocked thread list. Because the process big lock is temporary and is being actively removed from e.g. syscalls, it's a matter of time before we can also remove the fix introduced by this commit. Fixes issue #9401.
2022-04-01Everywhere: Run clang-formatIdan Horowitz
2022-03-26Kernel: Add a 'no_error' pledge promiseAli Mohammad Pur
This makes pledge() ignore promises that would otherwise cause it to fail with EPERM, which is very useful for allowing programs to run under a "jail" so to speak, without having them termiate early due to a failing pledge() call.
2022-03-22Kernel: Don't assume paths of TTYs and pseudo terminals anymoreLiav A
The obsolete ttyname and ptsname syscalls are removed. LibC doesn't rely on these anymore, and it helps simplifying the Kernel in many places, so it's an overall an improvement. In addition to that, /proc/PID/tty node is removed too as it is not needed anymore by userspace to get the attached TTY of a process, as /dev/tty (which is already a character device) represents that as well.
2022-03-22Kernel: Make mmap validation functions return ErrorOr<void>int16
2022-03-22Kernel: Move mmap validation functions to Processint16
2022-03-08Kernel: Put Process unveil state in a SpinlockProtected containerAndreas Kling
This makes path resolution safe to perform without holding the big lock.
2022-03-08Kernel: Put Process's current directory in a SpinlockProtectedAndreas Kling
Also let's call it "current_directory" instead of "cwd" everywhere.
2022-03-04Kernel: Fill some siginfo and ucontext fields on SA_SIGINFOAli Mohammad Pur
There's no reason to fill in any of these fields if SA_SIGINFO is not given, as the signal handler won't be reading from them at all.
2022-03-04Kernel: Move signal handlers from being thread state to process stateAli Mohammad Pur
POSIX requires that sigaction() and friends set a _process-wide_ signal handler, so move signal handlers and flags inside Process. This also fixes a "pid/tid confusion" FIXME, as we can now send the signal to the process and let that decide which thread should get the signal (which is the thread with tid==pid, but that's now the Process's problem). Note that each thread still retains its signal mask, as that is local to each thread.
2022-02-28Kernel: Add getrusage() syscallLucas CHOLLET
Only the two timeval fields are maintained, as required by the POSIX standard.
2022-02-27Everywhere: Make JSON serialization fallibleIdan Horowitz
This allows us to eliminate a major source of infallible allocation in the Kernel, as well as lay down the groundwork for OOM fallibility in userland.
2022-02-27Kernel: Add OpenFileDescriptions::try_enumerate for fallible iterationIdan Horowitz
This API will allow users to short circuit iteration and properly propagate errors.