summaryrefslogtreecommitdiff
path: root/Kernel/Syscalls
AgeCommit message (Collapse)Author
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-21Kernel/Syscall: Make anon_create to not use Process::allocate_fd methodLiav A
Instead, allocate when acquiring the lock on m_fds struct, which is safer to do in terms of safely mutating the m_fds struct, because we don't use the big process lock in this syscall.
2022-08-20Kernel: Get GID from credentials object in sys$setgroups()Andreas Kling
I missed one instance of these. Thanks Anthony Iacono for spotting it!
2022-08-20Kernel+LibC: Enforce a limit on the number of supplementary group IDsAndreas Kling
This patch adds the NGROUPS_MAX constant and enforces it in sys$setgroups() to ensure that no process has more than 32 supplementary group IDs. The number doesn't mean anything in particular, just had to pick a number. Perhaps one day we'll have a reason to change it.
2022-08-20Kernel: Mark syscalls that get/set user/group ID as not needing big lockAndreas Kling
Now that these operate on the neatly atomic and immutable Credentials object, they should no longer require the process big lock for synchronization. :^)
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: 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-18Kernel: Make sys$anon_create() allocate physical pages immediatelyAndreas Kling
This fixes an issue where a sharing process would map the "lazy committed page" early and then get stuck with that page even after it had been replaced in the VMObject by a page fault. Regressed in 27c1135d307efde8d9baef2affb26be568d50263, which made it happen every time with the backing bitmaps used for WebContent.
2022-08-18Kernel: Fix TOCTOU in sys$unveil()Andreas Kling
Make sure we reject the unveil attempt with EPERM if the veil was locked by another thread while we were parsing argument (and not holding the veil state spinlock.) Thanks Brian for spotting this! :^) Amendment to #14907.
2022-08-18Kernel: Don't do path resolution in sys$chdir() while holding spinlockAndreas Kling
Path resolution may do blocking I/O so we must not do it while holding a spinlock. There are tons of problems like this throughout the kernel and we need to find and fix all of them.
2022-08-18Kernel: Make sys$unveil() not take the big process lockSamuel Bowman
The unveil syscall uses the UnveilData struct which is already SpinlockProtected, so there is no need to take the big lock.
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: Make sys$socketpair() not take the big lockAndreas Kling
This system call mainly accesses the file descriptor table, and this is already guarded by MutexProtected.
2022-08-16Kernel: Only lock file descriptor table once in sys$pipe()Andreas Kling
Instead of locking it twice, we now frontload all the work that doesn't touch the fd table, and then only lock it towards the end of the syscall. The benefit here is simplicity. The downside is that we do a bit of unnecessary work in the EMFILE error case, but we don't need to optimize that case anyway.
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-08-16Kernel: Make sys$pipe() not take the big lockAndreas Kling
This system call mainly accesses the file descriptor table, and this is already guarded by MutexProtected.
2022-08-16Kernel: Remove unnecessary TOCTOU bug in sys$pipe()Andreas Kling
We don't need to explicitly check for EMFILE conditions before doing anything in sys$pipe(). The fd allocation code will take care of it for us anyway.
2022-08-15Kernel: Leak a ref() on the new Process ASAP in sys$fork()Andreas Kling
This fixes an issue where failing the fork due to OOM or other error, we'd end up destroying the Process too early. By the time we got to WaitBlockerSet::finalize(), it was long gone.
2022-08-10Kernel: Validate the sys$alarm signal send always succeedsBrian Gianforcaro
Previously we were ignoring this return code, instead use MUST(..) to make sure it always succeeds.
2022-07-27Everywhere: Make the codebase more architecture awareUndefine
2022-07-25Kernel/LibC: Implement posix syscall clock_getres()zzLinus
2022-07-22Kernel+LibC: Don't hardcode the maximum signal number everywhereTim Schumacher
2022-07-21Kernel: Support F_SETLKW in fcntlIdan Horowitz
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-21Kernel: Remove the Socket::{protocol,}connect ShouldBlock argumentIdan Horowitz
This argument is always set to description.is_blocking(), but description is also given as a separate argument, so there's no point to piping it through separately.
2022-07-15Kernel: Try to set [cm]time in Inode::did_modify_contentsHendiadyoin1
This indirectly resolves a fixme in sys$msync
2022-07-15Kernel: Handle multiple regions in sys$msyncHendiadyoin1
2022-07-15Kernel+LibC: Add posix_fallocate syscallHendiadyoin1
2022-07-15Kernel: Use find_last_split_view to get the executable name in do_execHendiadyoin1
2022-07-12Everywhere: Use default StringView constructor over nullptrsin-ack
While null StringViews are just as bad, these prevent the removal of StringView(char const*) as that constructor accepts a nullptr. No functional changes.
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: Stop leaking first thread on errors in sys$forkIdan Horowitz
Until the thread is first set as Runnable at the end of sys$fork, its state is Invalid, and as a result, the Finalizer which is searching for Dying threads will never find it if the syscall short-circuits due to an error condition like OOM. This also meant the parent Process of the thread would be leaked as well.
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-10Kernel: Stop reporting POLLHUP exclusively when available in sys$pollIdan Horowitz
As per Dr. Posix, unlike POLLERR and POLLNVAL, POLLHUP is only mutually exclusive with POLLOUT, all other events may be reported together with it.
2022-07-10Kernel: Report POLLNVAL events in sys$poll instead of returning EBADFIdan Horowitz
As required by Dr. Posix.
2022-07-10Kernel: Stop providing POLLRDHUP events in sys$poll by defaultIdan Horowitz
Dr. Posix specifies that only POLLERR, POLLHUP & POLLNVAL are provided by default.
2022-07-10Kernel: Set POLLHUP on WriteHangUp in sys$poll instead of POLLNVALIdan Horowitz
POLLNVAL signifies an invalid fd, not a write hang up.
2022-07-10Kernel: Accept SHUT_RD and SHUT_WR as shutdown() how valuesIdan Horowitz
The previous check for valid how values assumed this field was a bitmap and that SHUT_RDWR was simply a bitwise or of SHUT_RD and SHUT_WR, which is not the case.
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-08Kernel: Unblock SignalBlocker if a signal was just unmarked as pendingTim Schumacher
When updating the signal mask, there is a small frame where we might set up the receiving process for handing the signal and therefore remove that signal from the list of pending signals before SignalBlocker has a chance to block. In turn, this might cause SignalBlocker to never notice that the signal arrives and it will never unblock once blocked. Track the currently handled signal separately and include it when determining if SignalBlocker should be unblocking.
2022-07-08Kernel: Implement an `axallowed` mount optionTim Schumacher
Similar to `W^X` and `wxallowed`, this allows for anonymous executable mappings.
2022-07-05Kernel: Do a POSIX-correct signal handler reset on execTim Schumacher
2022-06-19Kernel: Add sysconf for IOV_MAXAndrew Kaster
2022-06-02Kernel: Implement InterruptDisabler using generic Processor functionsTimon Kruiper
Now that the code does not use architectural specific code, it is moved to the generic Arch directory and the paths are modified accordingly.
2022-05-29Kernel/FileSystem: Simplify even more the mount syscallLiav A
As with the previous commit, we put a distinction between filesystems that require a file description and those which don't, but now in a much more readable mechanism - all initialization properties as well as the create static method are grouped to create the FileSystemInitializer structure. Then when we need to initialize an instance, we iterate over a table of these structures, checking for matching structure and then validating the given arguments from userspace against the requirements to ensure we can create a valid instance of the requested filesystem.
2022-05-29Kernel: Simplify mount syscall flow for regular callsLiav A
We do this by putting a distinction between two types of filesystems - the first type is backed in RAM, and includes TmpFS, ProcFS, SysFS, DevPtsFS and DevTmpFS. Because these filesystems are backed in RAM, trying to mount them doesn't require source open file description. The second type is filesystems that are backed by a file, therefore the userspace program has to open them (hence it has a open file description on them) and provide the appropriate source open file description. By putting this distinction, we can early check if the user tried to mount the second type of filesystems without a valid file description, and fail with EBADF then. Otherwise, we can proceed to either mount either type of filesystem, provided that the fs_type is valid.
2022-05-23Kernel: Fix EINVAL when mmaping with address and no MAP_FIXEDPeter Elliott
The current behavior accidently trys to allocate 0 bytes when a non-null address is provided and MAP_FIXED is specified. This is clearly a bug.
2022-05-21Kernel+LibC: Implement futimens(3)Ariel Don
Implement futimes() in terms of utimensat(). Now, utimensat() strays from POSIX compliance because it also accepts a combination of a file descriptor of a regular file and an empty path. utimensat() then uses this file descriptor instead of the path to update the last access and/or modification time of a file. That being said, its prior behavior remains intact. With the new behavior of utimensat(), `path` must point to a valid string; given a null pointer instead of an empty string, utimensat() sets `errno` to `EFAULT` and returns a failure.