summaryrefslogtreecommitdiff
path: root/Kernel/Syscalls
AgeCommit message (Collapse)Author
2021-03-10Kernel: Move process pledge promises into protected dataAndreas Kling
2021-03-10Kernel: Move process parent PID into protected data :^)Andreas Kling
2021-03-10Kernel: Move process extra_gids into protected data :^)Andreas Kling
2021-03-10Kernel: Move select Process members into protected memoryAndreas Kling
Process member variable like m_euid are very valuable targets for kernel exploits and until now they have been writable at all times. This patch moves m_euid along with a whole bunch of other members into a new Process::ProtectedData struct. This struct is remapped as read-only memory whenever we don't need to write to it. This means that a kernel write primitive is no longer enough to overwrite a process's effective UID, you must first unprotect the protected data where the UID is stored. :^)
2021-03-09Kernel+UserspaceEmulator: Add sys$emuctl() system callAndreas Kling
This returns ENOSYS if you are running in the real kernel, and some other result if you are running in UserspaceEmulator. There are other ways we could check if we're inside an emulator, but it seemed easier to just ask. :^)
2021-03-08Kernel: Add bitwise operators for Thread::FileBlocker::BlockFlags enumBrian Gianforcaro
Switch to using type-safe bitwise operators for the BlockFlags class, this cleans up a lot of boilerplate casts which are necessary when the enum is declared as `enum class`.
2021-03-07Kernel: Fix pointer over/underflow in create_threadBen Wiederhake
The expression (u8*)params.m_stack_location + stack_size … causes UBSan to spit out the warning KUBSAN: addition of unsigned offset to 0x00000002 overflowed to 0xb0000003 … even though there is no actual overflow happening here. This can be reproduced by running: $ syscall create_thread 0 [ 0 0 0 0 0xb0000001 2 ] Technically, this is a true-positive: The C++-reference is incredibly strict about pointer-arithmetic: > A pointer to non-array object is treated as a pointer to the first element > of an array with size 1. […] [A]ttempts to generate a pointer that isn't > pointing at an element of the same array or one past the end invoke > undefined behavior. https://en.cppreference.com/w/cpp/language/operator_arithmetic Frankly, this feels silly. So let's just use FlatPtr instead. Found by fuzz-syscalls. Undocumented bug. Note that FlatPtr is an unsigned type, so user_esp.value() - 4 is defined even if we end up with a user_esp of 0 (this can happen for example when params.m_stack_size = 0 and params.m_stack_location = 0). The result would be a Kernelspace-pointer, which would then be immediately flagged by 'MM.validate_user_stack' as invalid, as intended.
2021-03-03Kernel: Skip TLB flushes while cloning regions in sys$fork()Andreas Kling
Since we know for sure that the virtual memory regions in the new process being created are not being used on any CPU, there's no need to do TLB flushes for every mapped page.
2021-03-03Kernel: Avoid transient kmalloc heap allocations in sys$select()Andreas Kling
Dynamic Vector allocations in sys$select() were showing up in the full-system profile and since there will never be more than FD_SETSIZE file descriptors to worry about, we can confidently add enough inline capacity to this Vector that it never has to kmalloc. To compensate for the increased stack usage, reduce the size of the FDInfo struct while we're here. :^)
2021-03-02Kernel+Profiler: Capture metadata about all profiled processesAndreas Kling
The perfcore file format was previously limited to a single process since the pid/executable/regions data was top-level in the JSON. This patch moves the process-specific data into a top-level array named "processes" and we now add entries for each process that has been sampled during the profile run. This makes it possible to see samples from multiple threads when viewing a perfcore file with Profiler. This is extremely cool! :^)
2021-03-02Kernel: Start work on full system profiling :^)Andreas Kling
The superuser can now call sys$profiling_enable() with PID -1 to enable profiling of all running threads in the system. The perf events are collected in a global PerformanceEventBuffer (currently 32 MiB in size.) The events can be accessed via /proc/profile
2021-03-02Kernel: Better handling of allocation failure in profilingAndreas Kling
If we can't allocate a PerformanceEventBuffer to store the profiling events, we now fail sys$profiling_enable() and sys$perf_event() with ENOMEM instead of carrying on with a broken buffer.
2021-03-02Kernel: Make sockets use AK::TimeBen Wiederhake
2021-03-02Kernel: Make kgettimeofday use AK::TimeBen Wiederhake
2021-03-02Kernel: Make TimeManagement use AK::Time internallyBen Wiederhake
I don't dare touch the multi-threading logic and locking mechanism, so it stays timespec for now. However, this could and should be changed to AK::Time, and I bet it will simplify the "increment_time_since_boot()" code.
2021-03-02Kernel: Make Thread use AK::Time internallyBen Wiederhake
This commit is very invasive, because Thread likes to take a pointer and write to it. This means that translating between timespec/timeval/Time would have been more difficult than just changing everything that hands a raw pointer to Thread, in bulk.
2021-03-02Kernel: Sanitize all user-supplied timeval's/timespec'sBen Wiederhake
This also removes a bunch of unnecessary EINVAL. Most of them weren't even recommended by POSIX.
2021-03-01Kernel: Fix build with IO_DEBUGAndreas Kling
2021-03-01Kernel: Use Userspace<T> in sys${munmap,mprotect,madvise,msyscall}()Andreas Kling
2021-03-01Kernel: Use Userspace<T> in sys$select()Andreas Kling
2021-03-01Kernel: Use Userspace<T> in sys$get_dir_entries()Andreas Kling
2021-03-01Kernel: Use Userspace<T> in sys$get_stack_bounds()Andreas Kling
2021-03-01Kernel: Use Userspace<T> in sys$write()Andreas Kling
2021-03-01Kernel: Use Userspace<T> in sys$sigaction()Andreas Kling
fuzz-syscalls found a bunch of unaligned accesses into struct sigaction via this syscall. This patch fixes that issue by porting the syscall to Userspace<T> which we should have done anyway. :^) Fixes #5500.
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-02-25Kernel: Don't disable interrupts while exiting a thread or processAndreas Kling
This was another vestige from a long time ago, when exiting a thread would mutate global data structures that were only protected by the interrupt flag.
2021-02-25Kernel: Don't disable interrupts while dealing with a process crashAndreas Kling
This was necessary in the past when crash handling would modify various global things, but all that stuff is long gone so we can simplify crashes by leaving the interrupt flag alone.
2021-02-25Kernel: Move SMAP disabler RAII helper to its own fileAndreas Kling
Added this in a new directory called Kernel/Arch/x86/ where stuff that applies to both i386 and x86_64 can live.
2021-02-25Kernel: Take some baby steps towards x86_64Andreas Kling
Make more of the kernel compile in 64-bit mode, and make some things pointer-size-agnostic (by using FlatPtr.) There's a lot of work to do here before the kernel will even compile.
2021-02-25Kernel: Move sys$sigaction() implementation inside ARCH(i386)Andreas Kling
2021-02-25Kernel: Tighten some typing in Arch/i386/CPU.hAndreas Kling
Use more appropriate types for some things.
2021-02-24Kernel: Fix pointer overflow in create_threadBrian Gianforcaro
KUBSAN found this overflow from syscall fuzzing. Fixes #5498
2021-02-24Kernel: Oops, fix broken sys$uname() function definitionAndreas Kling
2021-02-24Kernel: Don't dereference untrusted userspace pointer in sys$uname()Andreas Kling
Instead of writing to the userspace utsname struct one field at a time, build up a utsname on the kernel stack and copy it out to userspace once it's finished. This is both simpler and gets validity checking built-in for free. Found by KUBSAN! :^) Fixes #5499.
2021-02-23Everywhere: Rename ASSERT => VERIFYAndreas Kling
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED) Since all of these checks are done in release builds as well, let's rename them to VERIFY to prevent confusion, as everyone is used to assertions being compiled out in release. We can introduce a new ASSERT macro that is specifically for debug checks, but I'm doing this wholesale conversion first since we've accumulated thousands of these already, and it's not immediately obvious which ones are suitable for ASSERT.
2021-02-21Kernel: Use copy_n_from_user in sys$setgroups to check for overflowBrian Gianforcaro
2021-02-21Kernel: Use already computed nfds_checked value when copying from user mode.Brian Gianforcaro
- We've already computed the number of fds * sizeof(pollfd), so use it instead of needlessly doing it again. - Use fds_copy.data() instead off address of indexing the vector.
2021-02-21Kernel: Use copy_n_from_user in sys$setkeymapBrian Gianforcaro
2021-02-21Kernel: Populate ELF::AuxilaryValue::Platform from Processor object.Brian Gianforcaro
Move this to the processor object so it can easily be implemented when Serenity is compiled for a different architecture.
2021-02-21Kernel: Remove unneeded Thread::set_default_signal_dispositionsBrian Gianforcaro
The `default_signal_action(u8 signal)` function already has the full mapping. The only caveat being that now we need to make sure the thread constructor and clear_signals() method do the work of resetting the m_signal_action_data array, instead or relying on the previous logic in set_default_signal_dispositions.
2021-02-21Kernel: Add "map_fixed" pledge promiseAndreas Kling
This is a new promise that guards access to mmap() with MAP_FIXED. Fixed-address mappings are rarely used, but can be useful if you are trying to groom the process address space for malicious purposes. None of our programs need this at the moment, as the only user of MAP_FIXED is DynamicLoader, but the fixed mappings are constructed before the process has had a chance to pledge anything.
2021-02-19Kernel: Release ptrace lock in exec before stopping due to PT_TRACE_MEAndreas Kling
If we have a tracer process waiting for us to exec, we need to release the ptrace lock before stopping ourselves, since otherwise the tracer will block forever on the lock. Fixes #5409.
2021-02-18Kernel: Factor out mmap & friends range expansion to a helper functionAndreas Kling
sys$mmap() and related syscalls must pad to the nearest page boundary below the base address *and* above the end address of the specified range. Since we have to do this in many places, let's make a helper.
2021-02-18Kernel: Use KResult a bit more in sys$execve()Andreas Kling
2021-02-17Kernel: Use dbgln_if() in sys$fork()Andreas Kling
2021-02-16Kernel: Make sys$msyscall() EFAULT on non-user addressAndreas Kling
Fixes #5361.
2021-02-15Kernel: Refuse excessively long iovec list, also in readvBen Wiederhake
This bug is a good example why copy-paste code should eventually be eliminated from the code base: Apparently the code was copied from read.cpp before c6027ed7cce901dc0d2b6f68002a911178ae587f, so the same bug got introduced here. To recap: A malicious program can ask the Kernel to prepare sys-ing to a huge amount of iovecs. The Kernel must first copy all the vector locations into 'vecs', and before that allocates an arbitrary amount of memory: vecs.resize(iov_count); This can cause Kernel memory exhaustion, triggered by any malicious userland program.
2021-02-15Kernel+LibC: Add the _SC_GETPW_R_SIZE_MAX sysconf enumAnotherTest
It just returns 4096 :P
2021-02-15Kernel+LibC: Implement readvAnotherTest
We already had writev, so let's just add readv too.
2021-02-14Kernel: Forked children should inherit the signal trampoline addressAndreas Kling
Fixes #5347.