summaryrefslogtreecommitdiff
path: root/Kernel
AgeCommit message (Collapse)Author
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: Handle overflow in FileDescription::seek(, SEEK_CUR)Brian 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: Switch m_signal_action_data to Array<...>Brian Gianforcaro
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: Use uniform initialization instead of memset for a few stack buffer.Brian Gianforcaro
Raw memset is relatively easy to mess up, avoid it when there are better alternatives provided by the compiler in modern C++.
2021-02-21Kernel: Use ByteBuffer::zero_fill() instead of raw memset in Ext2Brian Gianforcaro
There was a typo in one of the memsets, use the type safe wrapper instead. Fix EXt
2021-02-21Kernel: Silence TTY signal debug spamAndreas Kling
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-21Kernel: Make UNMAP_AFTER_INIT imply NEVER_INLINE as wellAndreas Kling
We want to make sure these functions actually do get unmapped. If they were inlined somewhere, the inlined version(s) would remain mapped. Thanks to "thislooksfun" for the suggestion! :^)
2021-02-20Kernel: Mark some IDEController functions with UNMAP_AFTER_INITAndreas Kling
2021-02-20Kernel: Don't take debug logging lock in sprintf()Andreas Kling
This function doesn't write to the log, and so doesn't need to acquire the logging lock. (This is only used by GCC's name demangling thingy.)
2021-02-20Kernel: Slap a handful more things with UNMAP_AFTER_INITAndreas Kling
2021-02-19Kernel: Slap UNMAP_AFTER_INIT on a bunch more functionsAndreas Kling
We're now able to unmap 100 KiB of kernel text after init. :^)
2021-02-19Kernel: Slap UNMAP_AFTER_INIT on a whole bunch of functionsAndreas Kling
There's no real system here, I just added it to various functions that I don't believe we ever want to call after initialization has finished. With these changes, we're able to unmap 60 KiB of kernel text after init. :^)
2021-02-19Kernel: Mark write_cr0() and write_cr4() as UNMAP_AFTER_INITAndreas Kling
This removes a very useful tool for attackers trying to disable SMAP/SMEP/etc. :^)
2021-02-19Kernel: Add .unmap_after_init section for code we don't need after initAndreas Kling
You can now declare functions with UNMAP_AFTER_INIT and they'll get segregated into a separate kernel section that gets completely unmapped at the end of initialization. This can be used for anything we don't need to call once we've booted into userspace. There are two nice things about this mechanism: - It allows us to free up entire pages of memory for other use. (Note that this patch does not actually make use of the freed pages yet, but in the future we totally could!) - It allows us to get rid of obviously dangerous gadgets like write-to-CR0 and write-to-CR4 which are very useful for an attacker trying to disable SMAP/SMEP/etc. I've also made sure to include a helpful panic message in case you hit a kernel crash because of this protection. :^)
2021-02-19Kernel: Add helpers for manipulating x86 control registersAndreas Kling
Use read_cr{0,2,3,4} and write_cr{0,3,4} helpers instead of inline asm.
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-19ProcFS: Fix /proc/PID/* hardening bypassAndreas Kling
This enabled trivial ASLR bypass for non-dumpable programs by simply opening /proc/PID/vm before exec'ing. We now hold the target process's ptrace lock across the refresh/write operations, and deny access if the process is non-dumpable. The lock is necessary to prevent a TOCTOU race on Process::is_dumpable() while the target is exec'ing. Fixes #5270.
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: Convert snprintf() => String::formatted()/number()Andreas Kling
2021-02-17Kernel: Remove kprintf()Andreas Kling
There are no remaining users of this API.
2021-02-17Kernel: Convert dbgprintf()/klog() => dbgln()/dmesgln() in UHCI codeAndreas Kling
2021-02-17Kernel: Remove dbgprintf() from kernelAndreas Kling
There are no remaining users of this API in the kernel.
2021-02-17Kernel: Use dbgln_if() in sys$fork()Andreas Kling
2021-02-17Kernel: Don't go through ARP for IP broadcast messagesAnotherTest
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: Handle 'Menu' key on PS/2 keyboardJean-Baptiste Boric
2021-02-15Meta: Make it possible to (somewhat) build the system inside SerenityAnotherTest
This removes some hard references to the toolchain, some unnecessary uses of an external install command, and disables a -Werror flag (for the time being) - only if run inside serenity. With this, we can build and link the kernel :^)
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-15Kernel+LibC: Stub out SO_{SND_RCV}BUFAnotherTest
2021-02-15Kernel: Avoid some un-necessary copies coming from range based for loopsBrian Gianforcaro
- The irq_controller was getting add_ref/released needlessly during enumeration. - Used ranges were also getting needlessly copied.
2021-02-15Kernel: Initial integration of Kernel Address Sanitizer (KASAN)Brian Gianforcaro
KASAN is a dynamic analysis tool that finds memory errors. It focuses mostly on finding use-after-free and out-of-bound read/writes bugs. KASAN works by allocating a "shadow memory" region which is used to store whether each byte of memory is safe to access. The compiler then instruments the kernel code and a check is inserted which validates the state of the shadow memory region on every memory access (load or store). To fully integrate KASAN into the SerenityOS kernel we need to: a) Implement the KASAN interface to intercept the injected loads/stores. void __asan_load*(address); void __asan_store(address); b) Setup KASAN region and determine the shadow memory offset + translation. This might be challenging since Serenity is only 32bit at this time. Ex: Linux implements kernel address -> shadow address translation like: static inline void *kasan_mem_to_shadow(const void *addr) { return ((unsigned long)addr >> KASAN_SHADOW_SCALE_SHIFT) + KASAN_SHADOW_OFFSET; } c) Integrating KASAN with Kernel allocators. The kernel allocators need to be taught how to record allocation state in the shadow memory region. This commit only implements the initial steps of this long process: - A new (default OFF) CMake build flag `ENABLE_KERNEL_ADDRESS_SANITIZER` - Stubs out enough of the KASAN interface to allow the Kernel to link clean. Currently the KASAN kernel crashes on boot (triple fault because of the crash in strlen other sanitizer are seeing) but the goal here is to just get started, and this should help others jump in and continue making progress on KASAN. References: * ASAN Paper: https://static.googleusercontent.com/media/research.google.com/en//pubs/archive/37752.pdf * KASAN Docs: https://github.com/google/kasan * NetBSD KASAN Blog: https://blog.netbsd.org/tnf/entry/kernel_address_sanitizer_part_3 * LWN KASAN Article: https://lwn.net/Articles/612153/ * Tracking Issue #5351
2021-02-15Kernel: Mark KBuffer and its getters as [[nodiscard]]Brian Gianforcaro
There is no reason to call a getter without observing the result, doing so indicates an error in the code. Mark these methods as [[nodiscard]] to find these cases.
2021-02-15Kernel: Mark Lock getters as [[nodiscard]]Brian Gianforcaro
There is no reason to call a getter without observing the result, doing so indicates an error in the code. Mark these methods as [[nodiscard]] to find these cases.
2021-02-15Kernel: Mark UserOrKernelBuffer and it's getters as [[nodicard]]Brian Gianforcaro
`UserOrKernelBuffer` objects should always be observed when created, in turn there is no reason to call a getter without observing the result. Doing either of these indicates an error in the code. Mark these methods as [[nodiscard]] to find these cases.
2021-02-15Kernel: Mark KResult getters as [[nodiscard]]Brian Gianforcaro
There is no reason to call a getter without observing the result, doing so indicates an error in the code. Mark these methods as [[nodiscard]] to find these cases.
2021-02-15Kernel: Mark PhysicalAddress/VirtualAddress getters as [[nodiscard]]Brian Gianforcaro
There is no reason to call a getter without observing the result, doing so indicates an error in the code. Mark these methods as [[nodiscard]] to find these cases.
2021-02-15Kernel: Mark more StdLib functions as [[nodiscard]]Brian Gianforcaro
In the never ending journey to catch bugs, mark more functions as [[nodiscard]] to find incorrect call sites.
2021-02-15Kernel: Mark BlockResult as [[nodiscard]]Brian Gianforcaro
In the majority of cases we want to force callers to observe the result of a blocking operation as it's not grantee to succeed as they expect. Mark BlockResult as [[nodiscard]] to force any callers to observe the result of the blocking operation.
2021-02-15Kernel: Ignore unobserved BlockResult from Thread::SleepBrian Gianforcaro
Suppress these in preparation for making BlockResult [[nodiscard]].
2021-02-15Kernel: Add WaitQueue::wait_forever and it use it for all infinite waits.Brian Gianforcaro
In preparation for marking BlockingResult [[nodiscard]], there are a few places that perform infinite waits, which we never observe the result of the wait. Instead of suppressing them, add an alternate function which returns void when performing and infinite wait.
2021-02-14Kernel: Forked children should inherit the signal trampoline addressAndreas Kling
Fixes #5347.
2021-02-14Kernel: Mark a handful of things in CPU.cpp as READONLY_AFTER_INITAndreas Kling