summaryrefslogtreecommitdiff
path: root/Kernel/Syscalls/pledge.cpp
AgeCommit message (Collapse)Author
2023-02-06Kernel: Remove pledge syscall from the big lockSam Atkins
This already does all its dangerous work inside `with_mutable_protected_data()`.
2022-10-24AK+Everywhere: Turn bool keep_empty to an enum in split* functionsdemostanis
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-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-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-04-01Everywhere: Run clang-formatIdan Horowitz
2022-03-29Kernel: Disallow elevating pledge promises with no_error setAli Mohammad Pur
8233da33985bf834685bc215a8a9ed261e674f5f introduced a not-so-subtle bug where an application with an existing pledge set containing `no_error` could elevate its pledge set by pledging _anything_, this commit makes sure that no new promise is accepted.
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-02-14Kernel: Use StringView::for_each_split_view() in sys$pledgeIdan Horowitz
This let's us avoid the fallible Vector allocation that split_view() entails.
2022-01-02Kernel: Delay Process data unprotection in sys$pledge()Andreas Kling
Don't unprotect the protected data area until we've validated the pledge syscall inputs.
2021-11-08Kernel: Replace KResult and KResultOr<T> with Error and ErrorOr<T>Andreas Kling
We now use AK::Error and AK::ErrorOr<T> in both kernel and userspace! This was a slightly tedious refactoring that took a long time, so it's not unlikely that some bugs crept in. Nevertheless, it does pass basic functionality testing, and it's just real nice to finally see the same pattern in all contexts. :^)
2021-09-05Kernel: Use TRY() in sys$pledge()Andreas Kling
2021-09-05Kernel: Use copy_typed_from_user<T> for fetching syscall parametersAndreas Kling
2021-09-05Kernel: Make copy_{from,to}_user() return KResult and use TRY()Andreas Kling
This makes EFAULT propagation flow much more naturally. :^)
2021-08-12Kernel/Process: Move protected values to the end of the objectLiav A
The compiler can re-order the structure (class) members if that's necessary, so if we make Process to inherit from ProcFSExposedComponent, even if the declaration is to inherit first from ProcessBase, then from ProcFSExposedComponent and last from Weakable<Process>, the members of class ProcFSExposedComponent (including the Ref-counted parts) are the first members of the Process class. This problem made it impossible to safely use the current toggling method with the write-protection bit on the ProcessBase members, so instead of inheriting from it, we make its members the last ones in the Process class so we can safely locate and modify the corresponding page write protection bit of these values. We make sure that the Process class doesn't expand beyond 8192 bytes and the protected values are always aligned on a page boundary.
2021-08-06Kernel: Make Process's m_promises & m_execpromises fields atomicIdan Horowitz
This is essentially free on x86 and allows us to not hold the big process lock just to check the required promises for a syscall.
2021-07-23Kernel: Use StringView when parsing pledges in sys$pledge(..)Brian Gianforcaro
This ensures no potential allocation as in some cases the pledge char* could be promoted to AK::String by the compiler to execute the comparison.
2021-07-23Kernel: Fix bug where we half apply pledges in sys$pledge(..)Brian Gianforcaro
This bug manifests it self when the caller to sys$pledge() passes valid promises, but invalid execpromises. The code would apply the promises and then return an error for the execpromises. This leaves the user in a confusing state, as the promises were silently applied, but we return an error suggesting the operation has failed. Avoid this situation by tweaking the implementation to only apply the promises / execpromises after all validation has occurred.
2021-07-23Kernel: Migrate sys$pledge to use the KString APIBrian Gianforcaro
This avoids potential unhandled OOM that's possible with the old copy_string_from_user API.
2021-07-20Kernel: Annotate all syscalls with VERIFY_PROCESS_BIG_LOCK_ACQUIREDBrian Gianforcaro
Before we start disabling acquisition of the big process lock for specific syscalls, make sure to document and assert that all the lock is held during all syscalls.
2021-07-10Kernel: Logic fix in the pledge syscallRalf Donau
Pledge should check m_has_promises. Calling pledge("", nullptr) does not fail on an already pledged process anymore.
2021-06-28Kernel: Fix the return type for syscallsGunnar Beutner
The Process::Handler type has KResultOr<FlatPtr> as its return type. Using a different return type with an equally-sized template parameter sort of works but breaks once that condition is no longer true, e.g. for KResultOr<int> on x86_64. Ideally the syscall handlers would also take FlatPtrs as their args so we can get rid of the reinterpret_cast for the function pointer but I didn't quite feel like cleaning that up as well.
2021-04-22Everything: Move to SPDX license identifiers in all files.Brian Gianforcaro
SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-03-11Kernel: Don't keep protected Process data in a separate allocationAndreas Kling
The previous architecture had a huge flaw: the pointer to the protected data was itself unprotected, allowing you to overwrite it at any time. This patch reorganizes the protected data so it's part of the Process class itself. (Actually, it's a new ProcessBase helper class.) We use the first 4 KB of Process objects themselves as the new storage location for protected data. Then we make Process objects page-aligned using MAKE_ALIGNED_ALLOCATED. This allows us to easily turn on/off write-protection for everything in the ProcessBase portion of Process. :^) Thanks to @bugaevc for pointing out the flaw! This is still not perfect but it's an improvement.
2021-03-10Kernel: Move process pledge promises into protected dataAndreas Kling
2021-03-01Kernel: Make all syscall functions return KResultOr<T>Andreas Kling
This makes it a lot easier to return errors since we no longer have to worry about negating EFOO errors and can just return them flat.
2021-01-26Kernel: Don't drop pledge()'d promises/execpromises when passing nullptrLinus Groh
When passing nullptr for either promises or execpromises to pledge(), the expected behaviour is to not change their current value at all - we were accidentally resetting them to 0, effectively dropping previously pledge()'d promises.
2021-01-26Kernel: Update process promise states on execve() and fork()Andreas Kling
We now move the execpromises state into the regular promises, and clear the execpromises state. Also make sure to duplicate the promise state on fork. This fixes an issue where "su" would launch a shell which immediately crashed due to not having pledged "stdio".
2021-01-25Kernel: Support pledge() with empty promisesLinus Groh
This tells the kernel that the process wants to use pledge, but without pledging anything - effectively restricting it to syscalls that don't require a certain promise. This is part of OpenBSD's pledge() as well, which served as basis for Serenity's.
2021-01-22Kernel+Userland: Remove "dns" pledge promise aliasAndreas Kling
This was just an alias for "unix" that I added early on back when there was some belief that we might be compatible with OpenBSD. We're clearly never going to be compatible with their pledges so just drop the alias.
2020-09-17Kernel: Unbreak sys$pledge()Andreas Kling
We were dropping all the incoming pledge promise strings and parsing "" instead. Fixes #3519.
2020-09-13Kernel: Make copy_to/from_user safe and remove unnecessary checksTom
Since the CPU already does almost all necessary validation steps for us, we don't really need to attempt to do this. Doing it ourselves doesn't really work very reliably, because we'd have to account for other processors modifying virtual memory, and we'd have to account for e.g. pages not being able to be allocated due to insufficient resources. So change the copy_to/from_user (and associated helper functions) to use the new safe_memcpy, which will return whether it succeeded or not. The only manual validation step needed (which the CPU can't perform for us) is making sure the pointers provided by user mode aren't pointing to kernel mappings. To make it easier to read/write from/to either kernel or user mode data add the UserOrKernelBuffer helper class, which will internally either use copy_from/to_user or directly memcpy, or pass the data through directly using a temporary buffer on the stack. Last but not least we need to keep syscall params trivial as we need to copy them from/to user mode using copy_from/to_user.
2020-08-02Kernel: Use Userspace<T> in pledge syscallBrian Gianforcaro
2020-07-30Kernel: Move syscall implementations out of Process.cppAndreas Kling
This is something I've been meaning to do for a long time, and here we finally go. This patch moves all sys$foo functions out of Process.cpp and into files in Kernel/Syscalls/. It's not exactly one syscall per file (although it could be, but I got a bit tired of the repetitive work here..) This makes hacking on individual syscalls a lot less painful since you don't have to rebuild nearly as much code every time. I'm also hopeful that this makes it easier to understand individual syscalls. :^)