summaryrefslogtreecommitdiff
path: root/Kernel
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: 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-20AK+Kernel: Add AK::AtomicRefCounted and use everywhere in the kernelAndreas Kling
Instead of having two separate implementations of AK::RefCounted, one for userspace and one for kernelspace, there is now RefCounted and AtomicRefCounted.
2022-08-19Kernel: Annotate SpinlockProtected<PacketList> in NetworkAdapter classLiav A
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-19Kernel: Add 8-byte atomics for i686 GCCIdan Horowitz
Unlike Clang, GCC does not support 8-byte atomics on i686 with the -mno-80387 flag set, so until that is fixed, implement a minimal set of atomics that are currently required.
2022-08-19Kernel: Put too small unused network packets back into the listTim Schumacher
2022-08-19Kernel: Protect the list of unused network packets with a SpinlockTim Schumacher
2022-08-19Kernel: Don't take thread lock for signal dispatchAndreas Kling
Signal dispatch is already protected by the global scheduler lock, but in some cases we also took Thread::m_lock for some reason. This led to a number of different deadlocks that started showing up with 4+ CPU's attached to the system. As a first step towards solving this, simply don't take the thread lock and let the scheduler lock cover it. Eventually, we should work in the other direction and break the scheduler lock into much finer-grained locks, but let's get out of the deadlock swamp first.
2022-08-19Kernel/Memory: Use scope guard to remove a region if we failed to map itLiav A
2022-08-19Kernel: Don't lock scheduler in ~Thread()Andreas Kling
This is not necessary, and is a leftover from before Thread started using the ListedRefCounted pattern to be safely removed from lists on the last call to unref().
2022-08-19Kernel: Don't lock scheduler while updating thread scheduling timesAndreas Kling
We can use simple atomic variables with relaxed ordering for this, and avoid locking altogether.
2022-08-19Kernel: Reduce time under VMObject lock while handling zero faultsAndreas Kling
We only need to hold the VMObject lock while inspecting and/or updating the physical page array in the VMObject.
2022-08-19Kernel/x86: Re-enable interrupts ASAP when handling page faultsAndreas Kling
As soon as we've saved CR2 (the faulting address), we can re-enable interrupt processing. This should make the kernel more responsive under heavy fault loads.
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: Make Region's physical page accessors safer to useAndreas Kling
Region::physical_page() now takes the VMObject lock while accessing the physical pages array, and returns a RefPtr<PhysicalPage>. This ensures that the array access is safe. Region::physical_page_slot() now VERIFY()'s that the VMObject lock is held by the caller. Since we're returning a reference to the physical page slot in the VMObject's physical page array, this is the best we can do here.
2022-08-18Kernel: Schedule threads on all processors when SMP is enabledAndreas Kling
Note that SMP is still off by default, but this basically removes the weird "SMP on but threads don't get scheduled" behavior we had by default. If you pass "smp=on" to the kernel, you now get SMP. :^)
2022-08-18Kernel: Don't hog VMObject lock when remapping a region pageAndreas Kling
We really only need the VMObject lock when accessing the physical pages array, so once we have a strong pointer to the physical page we want to remap, we can give up the VMObject lock. This fixes a deadlock I encountered while building DOOM on SMP.
2022-08-18Kernel: Move Region physical page accessors out of lineAndreas Kling
2022-08-18Kernel: Add a comment about what the MM lock protectsAndreas Kling
2022-08-18Kernel: Don't require MM lock for Region::set_page_directory()Andreas Kling
The MM lock is not required for this, it's just a simple ref-counted pointer assignment.
2022-08-18Kernel: Fix inconsistent lock acquisition order in kmallocAndreas Kling
We always want to grab the page directory lock before the MM lock. This fixes a deadlock I encountered when building DOOM with make -j4.
2022-08-18Kernel: Don't remap all regions from Region::remap_vmobject_page()Andreas Kling
When handling a page fault, we only need to remap the faulting region in the current process. There's no need to traverse *all* regions that map the same VMObject and remap them cross-process as well. Those other regions will get remapped lazily by their own page fault handlers eventually. Or maybe they won't and we avoided some work. :^)
2022-08-18Kernel: Shorten time under spinlocks while handling inode faultsAndreas Kling
- Instead of holding the VMObject lock across physical page allocation and quick-map + copy, we now only hold it when updating the VMObject's physical page slot.
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/x86: Don't re-enable interrupts too soon when unlocking spinlocksAndreas Kling
To ensure that we stay on the same CPU that acquired the spinlock until we're completely unlocked, we now leave the critical section *before* re-enabling interrupts.
2022-08-18Kernel: Protect the Custody cache with a spinlockAndreas Kling
Protecting it with a mutex meant that anyone unref()'ing a Custody might need to block on said mutex.
2022-08-18Kernel: Remove outdated FIXME in Custody.hAndreas Kling
2022-08-18Kernel: Use consistent lock acquisition order in Thread::block*()Andreas Kling
We want to grab g_scheduler_lock *before* Thread::m_block_lock. This appears to have fixed a deadlock that I encountered while building DOOM with make -j2.
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/x86: Disable interrupts when leaving critical sectionsAndreas Kling
This fixes an issue where we could get preempted after acquiring the current Processor pointer, but before calling methods on it. I strongly suspect this was the cause of "Processor::current() == this" assertion failures.
2022-08-18Kernel/x86: Move Processor::{leave,clear}_critical() out of lineAndreas Kling
I don't think this code needs to be ALWAYS_INLINE, and moving it out of line will make backtraces nicer.
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-16Kernel: Lock the inode before writing in SharedInodeVMObject::syncMike Akers
We ensure that when we call SharedInodeVMObject::sync we lock the inode lock before calling Inode virtual write_bytes method directly to avoid assertion on the unlocked inode lock, as it was regressed recently. This is not a complete fix as the need to lock from each path before calling the write_bytes method should be avoided because it can lead to hard-to-find bugs, and this commit only fixes the problem temporarily.
2022-08-16Kernel: Release 1 page instead of all pages when starved for pagesdylanbobb
Previously, when starved for pages, *all* clean file-backed memory would be released, which is quite excessive. This patch instead releases just 1 page, since only 1 page is needed to satisfy the request to `allocate_physical_page()`
2022-08-16Kernel: Allow release of a specific amount of of clean pagesdylanbobb
Previously, we could only release *all* clean pages. This patch makes it possible to release a specific amount of clean pages. If the attempted number of pages to release is more than the amount of clean pages, all clean pages will be released.
2022-08-15Kernel: Shrink default userspace stack size from 4 MiB to 1 MiBAndreas Kling
This knocks 70 MiB off our idle footprint, (from 350 MiB to 280 MiB.)