summaryrefslogtreecommitdiff
path: root/Kernel/Process.h
AgeCommit message (Collapse)Author
2023-02-08Kernel: Add optional userspace backtrace to Process::crashTimon Kruiper
This is very useful for debugging the initial userspace applications, as the CrashReporter is not yet running.
2023-02-06Kernel: Protect Process::m_name with a spinlockSam Atkins
This also lets us remove the `get_process_name` and `set_process_name` syscalls from the big lock. :^)
2023-01-29Kernel/FileSystem: Simplify the ProcFS inode codeLiav A
This is done by merging all scattered pieces of derived classes from the ProcFSInode class into that one class, so we don't use inheritance but rather simplistic checks to determine the proper code for each ProcFS inode with its specific characteristics.
2023-01-27Kernel: Use InterruptsState abstraction in execve.cppTimon Kruiper
This was using the x86_64 specific cpu_flags abstraction, which is not compatible with aarch64.
2023-01-21Kernel+LibC: Move LibC/signal_numbers.h to Kernel/API/POSIXAndrew Kaster
Make Userland and Tests users just include signal.h, and move Kernel users to the new API file.
2023-01-10Kernel+LibCore: Make %sid path parsing not take agesAndreas Kling
Before this patch, Core::SessionManagement::parse_path_with_sid() would figure out the root session ID by sifting through /sys/kernel/processes. That file can take quite a while to generate (sometimes up to 40ms on my machine, which is a problem on its own!) and with no caching, many of our programs were effectively doing this multiple times on startup when unveiling something in /tmp/session/%sid/ While we should find ways to make generating /sys/kernel/processes fast again, this patch addresses the specific problem by introducing a new syscall: sys$get_root_session_id(). This extracts the root session ID by looking directly at the process table and takes <1ms instead of 40ms. This cuts WebContent process startup time by ~100ms on my machine. :^)
2023-01-07Kernel: Mark Process::jail() method as constLiav A
We really don't want callers of this function to accidentally change the jail, or even worse - remove the Process from an attached jail. To ensure this never happens, we can just declare this method as const so nobody can mutate it this way.
2023-01-06Kernel: Add helper function to check if a Process is in jailLiav A
Use this helper function in various places to replace the old code of acquiring the SpinlockProtected<RefPtr<Jail>> of a Process to do that validation.
2023-01-04Everywhere: Make global `inline` functions not `static`Nico Weber
`inline` already assigns vague linkage, so there's no need to also assign per-TU linkage. Allows the linker to dedup these functions across TUs (and is almost always just the Right Thing to do in C++ -- this ain't C).
2023-01-04Everywhere: Remove some redundant `inline` keywordsNico Weber
Functions defined inside class bodies (including static functions) are implicitly inline, no need to type it out.
2023-01-02Kernel: Turn lock ranks into template parameterskleines Filmröllchen
This step would ideally not have been necessary (increases amount of refactoring and templates necessary, which in turn increases build times), but it gives us a couple of nice properties: - SpinlockProtected inside Singleton (a very common combination) can now obtain any lock rank just via the template parameter. It was not previously possible to do this with SingletonInstanceCreator magic. - SpinlockProtected's lock rank is now mandatory; this is the majority of cases and allows us to see where we're still missing proper ranks. - The type already informs us what lock rank a lock has, which aids code readability and (possibly, if gdb cooperates) lock mismatch debugging. - The rank of a lock can no longer be dynamic, which is not something we wanted in the first place (or made use of). Locks randomly changing their rank sounds like a disaster waiting to happen. - In some places, we might be able to statically check that locks are taken in the right order (with the right lock rank checking implementation) as rank information is fully statically known. This refactoring even more exposes the fact that Mutex has no lock rank capabilites, which is not fixed here.
2022-12-30Kernel: Disallow executing SUID binaries if process is jailedLiav A
Check if the process we are currently running is in a jail, and if that is the case, fail early with the EPERM error code. Also, as Brian noted, we should also disallow attaching to a jail in case of already running within a setid executable, as this leaves the user with false thinking of being secure (because you can't exec new setid binaries), but the current program is still marked setid, which means that at the very least we gained permissions while we didn't expect it, so let's block it.
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.