summaryrefslogtreecommitdiff
path: root/Kernel
AgeCommit message (Collapse)Author
2022-12-19Kernel/Graphics: Propagate errors properly around in the VirtIO driverLiav A
This happens to be a sad truth for the VirtIOGPU driver - it lacked any error propagation measures and generally relied on clunky assumptions that most operations with the GPU device are infallible, although in reality much of them could fail, so we do need to handle errors. To fix this, synchronous GPU commands no longer rely on the wait queue mechanism anymore, so instead we introduce a timeout-based mechanism, similar to how other Kernel drivers use a polling based mechanism with the assumption that hardware could get stuck in an error state and we could abort gracefully. Then, we change most of the VirtIOGraphicsAdapter methods to propagate errors properly to the original callers, to ensure that if a synchronous GPU command failed, either the Kernel or userspace could do something meaningful about this situation.
2022-12-19Kernel/Graphics: Disable double buffering for the VirtIO driverLiav A
The performance that we achieve from this technique is visually worse compared to turning off this feature, so let's not use this until we figure out why it happens.
2022-12-19Kernel: Properly propagate errors in VirtIOGPU 3D device initializationLiav A
2022-12-17AK+Everywhere: Move custom deleter capability to OwnPtrLenny Maiorani
`OwnPtrWithCustomDeleter` was a decorator which provided the ability to add a custom deleter to `OwnPtr` by wrapping and taking the deleter as a run-time argument to the constructor. This solution means that no additional space is needed for the `OwnPtr` because it doesn't need to store a pointer to the deleter, but comes at the cost of having an extra type that stores a pointer for every instance. This logic is moved directly into `OwnPtr` by adding a template argument that is defaulted to the default deleter for the type. This means that the type itself stores the pointer to the deleter instead of every instance and adds some type safety by encoding the deleter in the type itself instead of taking a run-time argument.
2022-12-17Kernel: Propagate errors in E1000NetworkAdapterBaitinq
We now move the ErrorOr returning functions in the constructor to the try_to_initialize() factory, which allows us to handle the errors and removes two FIXME's :))
2022-12-17Kernel/Plan9FS: Propagate errors in Plan9FSMessage::append_dataFreakness109
2022-12-16Kernel: Propagate properly errors from ISAIDEController initializationLiav A
2022-12-16Kernel/Memory: Add option to annotate region mapping as immutableLiav A
We add this basic functionality to the Kernel so Userspace can request a particular virtual memory mapping to be immutable. This will be useful later on in the DynamicLoader code. The annotation of a particular Kernel Region as immutable implies that the following restrictions apply, so these features are prohibited: - Changing the region's protection bits - Unmapping the region - Annotating the region with other virtual memory flags - Applying further memory advises on the region - Changing the region name - Re-mapping the region
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-15Kernel: Allocate VirtIOGPU context IDs from a bitmap, with ErrorOrSam Atkins
As is, we never *deallocate* them, so we will run out eventually. Creating a context, or allocating a context ID, now returns ErrorOr if there are no available free context IDs. `number_of_fixmes--;` :^)
2022-12-15Kernel: Remove unimplemented VirGL adapter's edid_feature_accepted()Sam Atkins
2022-12-15Kernel: Remove Badged `VirtIOGraphicsAdapter::allocate_FOO_id()` methodsSam Atkins
These are unused, so let's remove them. `number_of_fixmes--;` :^)
2022-12-14Kernel: Ignore an invalid QEMU multiboot entryimplicitfield
This was introduced in the QEMU commit 8504f12 and was causing the kernel to fail to boot on the q35 machine. Fixes #14952.
2022-12-14Kernel: Start implementing `kmalloc_aligned` more efficientlyTim Schumacher
This now only requires `size + alignment` bytes while searching for a free memory location. For the actual allocation, the memory area is properly trimmed to the required alignment.
2022-12-14Kernel: Check against TCP packet size overflows in checksum calculationTim Schumacher
2022-12-14Kernel: Convert TCP pseudo-headers through a unionTim Schumacher
This keeps us from tripping strict aliasing, which previously made TCP connections inoperable when building without `-fsanitize=undefined` or `-fno-strict-aliasing`.
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-14Everywhere: Stop shoving things into ::std and mentioning them as suchAli Mohammad Pur
Note that this still keeps the old behaviour of putting things in std by default on serenity so the tools can be happy, but if USING_AK_GLOBALLY is unset, AK behaves like a good citizen and doesn't try to put things in the ::std namespace. std::nothrow_t and its friends get to stay because I'm being told that compilers assume things about them and I can't yeet them into a different namespace...for now.
2022-12-13Kernel: Propagate errors during network adapter detection/initializationAndreas Kling
When scanning for network adapters, we give each driver a chance to claim the PCI device and whoever claims it first gets to keep it. Before this patch, the driver API returned a LockRefPtr<AdapterType>, which made it impossible to propagate errors that occurred during detection and/or initialization. This patch changes the API so that errors can bubble all the way out the PCI enumeration in NetworkingManagement::initialize() where we perform all the network adapter auto-detection on boot. When we eventually start to support hot-plugging network adapter in the future, it will be even more important to propagate errors instead of swallowing them. Importantly, before this patch, some errors were "handled" by panicking the kernel. This is no longer the case. 7 FIXMEs were killed in the making of this commit. :^)
2022-12-12Kernel: Use `size_t` to keep track of the number of pages in a regionTim Schumacher
We were previously using a 32-bit unsigned integer for this, which caused us to start truncating region sizes when multiplied with `PAGE_SIZE` on hardware with a lot of memory.
2022-12-11Kernel: Bump maximum pthread stack size to 32MiBsin-ack
The Zig compiler asks for this much stack on its main thread via the use of PT_GNU_STACK.
2022-12-11Kernel+LibC+LibELF: Set stack size based on PT_GNU_STACK during execvesin-ack
Some programs explicitly ask for a different initial stack size than what the OS provides. This is implemented in ELF by having a PT_GNU_STACK header which has its p_memsz set to the amount that the program requires. This commit implements this policy by reading the p_memsz of the header and setting the main thread stack size to that. ELF::Image::validate_program_headers ensures that the size attribute is a reasonable value.
2022-12-11Kernel: Implement flock downgradingsin-ack
This commit makes it possible for a process to downgrade a file lock it holds from a write (exclusive) lock to a read (shared) lock. For this, the process must point to the exact range of the flock, and must be the owner of the lock.
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: Use real UID/GID when checking for file accesssin-ack
This aligns the rest of the system with POSIX, who says that access(2) must check against the real UID and GID, not effective ones.
2022-12-11Kernel: Remove InodeMetadata::may_{read,write,execute}(Process const&)sin-ack
These have no definition and are never used.
2022-12-11Kernel+LibC+LibCore: Implement `renameat(2)`sin-ack
Now with the ability to specify different bases for the old and new paths.
2022-12-11Kernel+LibC+LibCore: Implement `mkdirat(2)`sin-ack
2022-12-11Kernel+LibC: Implement `readlinkat(2)`sin-ack
Co-Authored-By: Daniel Bertalan <dani@danielbertalan.dev>
2022-12-11Kernel+LibC+LibCore: Implement `symlinkat(2)`sin-ack
Co-Authored-By: Daniel Bertalan <dani@danielbertalan.dev>
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-12-11Kernel: Allow dead threads to be joinedkleines Filmröllchen
Joining dead threads is allowed for two main reasons: - Thread join behavior should not be racy when a thread is joined and exiting at roughly the same time. This is common behavior when threads are given a signal to end (meaning they are going to exit ASAP) and then joined. - POSIX requires that exited threads are joinable (at least, there is no language in the specification forbidding it). The behavior is still well-defined; e.g. it doesn't allow a dead detached thread to be joined or a thread to be joined more than once.
2022-12-10Kernel: Use HashMap::try_ensure_capacityThomas Queiroz
2022-12-10Kernel: Set EFLAGS/RFLAGS to a known-good value on signal entrySergey Lisov
2022-12-09Kernel/FileSystem: Convert the mount table from Vector to IntrusiveListLiav A
The fact that we used a Vector meant that even if creating a Mount object succeeded, we were still at a risk that appending to the actual mounts Vector could fail due to OOM condition. To guard against this, the mount table is now an IntrusiveList, which always means that when allocation of a Mount object succeeded, then inserting that object to the list will succeed, which allows us to fail early in case of OOM condition.
2022-12-09Kernel: Allow opening some device nodes sparingly for jailed processesLiav A
From now on, we don't allow jailed processes to open all device nodes in /dev, but only allow jailed processes to open /dev/full, /dev/zero, /dev/null, and various TTY and PTY devices (and not including virtual consoles) so we basically restrict applications to what they can do when they are in jail. The motivation for this type of restriction is to ensure that even if a remote code execution occurred, the damage that can be done is very small. We also don't restrict reading and writing on device nodes that were already opened, because that limit seems not useful, especially in the case where we do want to provide an OpenFileDescription to such device but nothing further than that.
2022-12-09Kernel: Add callback on ".." directory entry for a TmpFS root directoryLiav A
2022-12-08Kernel/aarch64: Initialize components that are already workingFiliph Sandström
`SysFSComponentRegistry`, `ProcFSComponentRegistry` and `attach_null_device` "just work" already; let's include them to match x86_64 as closely as possible.
2022-12-07Kernel: Add missing VERIFY in MM::allocate_committed_physical_pageThomas Queiroz
2022-12-07Kernel: Don't panic if MemoryManager::find_free_physical_page failsThomas Queiroz
2022-12-07Kernel: Return nullptr instead of PANICking in KmallocSlabHeapThomas Queiroz
I dared to return nullptr :^)
2022-12-06AK+Everywhere: Rename String to DeprecatedStringLinus Groh
We have a new, improved string type coming up in AK (OOM aware, no null state), and while it's going to use UTF-8, the name UTF8String is a mouthful - so let's free up the String name by renaming the existing class. Making the old one have an annoying name will hopefully also help with quick adoption :^)
2022-12-05Kernel: Don't memset() allocated memory twice in kcalloc()Andreas Kling
This patch adds a way to ask the allocator to skip its internal scrubbing memset operation. Before this change, kcalloc() would scrub twice: once internally in kmalloc() and then again in kcalloc(). The same mechanism already existed in LibC malloc, and this patch brings it over to the kernel heap allocator as well. This solves one FIXME in kcalloc(). :^)
2022-12-03Everywhere: Remove 'clang-format off' comments that are no longer neededLinus Groh
https://github.com/SerenityOS/serenity/pull/15654#issuecomment-1322554496
2022-12-03Everywhere: Run clang-formatLinus Groh
2022-12-03Kernel: Implement PIT::set_periodic() and PIT::set_non_periodic()Vitriol1744
2022-12-03Kernel: Reject create links on paths that were not unveiled as writableLiav A
This solves one of the security issues being mentioned in issue #15996. We simply don't allow creating hardlinks on paths that were not unveiled as writable to prevent possible bypass on a certain path that was unveiled as non-writable.
2022-12-03Kernel+SystemServer: Don't hardcode coredump directory pathLiav A
Instead, allow userspace to decide on the coredump directory path. By default, SystemServer sets it to the /tmp/coredump directory, but users can now change this by writing a new path to the sysfs node at /sys/kernel/variables/coredump_directory, and also to read this node to check where coredumps are currently generated at.