summaryrefslogtreecommitdiff
path: root/Kernel
AgeCommit message (Collapse)Author
2020-01-01Build: fix building Kernel/TestModule objectjoshua stein
2020-01-01Kernel: Add a random offset to kernel stacks upon syscall entryAndreas Kling
When entering the kernel from a syscall, we now insert a small bit of stack padding after the RegisterDump. This makes kernel stacks less deterministic across syscalls and may make some bugs harder to exploit. Inspired by Elena Reshetova's talk on kernel stack exploitation.
2020-01-01Kernel: Share code between Region::map() and Region::remap_page()Andreas Kling
These were doing mostly the same things, so let's just share the code.
2020-01-01Kernel: Disable x86 RDTSC instruction in userspaceAndreas Kling
It's still possible to read the TSC via the read_tsc() syscall, but we will now clear some of the bottom bits for unprivileged users.
2020-01-01Demos: Add a dynamic linking demo to show off dlfcn methodsAndrew Kaster
The LinkDemo program calls dlopen/dlsym/dlclose to try and load a dyanmic library from /usr/lib. It read a global variable and calls a global function (extern "C" of course :) ). There a few hacks left in the LinkLib dynamic library, however. In order to get the linker to stop complaining, we have to use -nostartfiles -ffreestanding otherwise it will link crt0.o to our shared object, which is definitely not right as the _init function for a main program (that calls main) is not suitable for our lib
2020-01-01Kernel: Prevent executing I/O instructions in userspaceAndreas Kling
All threads were running with iomapbase=0 in their TSS, which the CPU interprets as "there's an I/O permission bitmap starting at offset 0 into my TSS". Because of that, any bits that were 1 inside the TSS would allow the thread to execute I/O instructions on the port with that bit index. Fix this by always setting the iomapbase to sizeof(TSS32), and also setting the TSS descriptor's limit to sizeof(TSS32), effectively making the I/O permissions bitmap zero-length. This should make it no longer possible to do I/O from userspace. :^)
2020-01-01Kernel: Fix typo in Descriptor::set_limit()Andreas Kling
x86 descriptor limits are 20 bytes, not 24 bytes. This was already a 4-bit wide bitfield, so no damage done, but let's be correct.
2020-01-01Kernel: Switch to eagerly restoring x86 FPU state on context switchAndreas Kling
Lazy FPU restore is well known to be vulnerable to timing attacks, and eager restore is a lot simpler anyway, so let's just do it eagerly.
2020-01-01Kernel: Enable x86 UMIP (User Mode Instruction Prevention) if supportedAndreas Kling
This prevents code running outside of kernel mode from using the following instructions: * SGDT - Store Global Descriptor Table * SIDT - Store Interrupt Descriptor Table * SLDT - Store Local Descriptor Table * SMSW - Store Machine Status Word * STR - Store Task Register There's no need for userspace to be able to use these instructions so let's just disable them to prevent information leakage.
2020-01-01Kernel: Move CPU feature detection to Arch/x86/CPU.{cpp.h}Andreas Kling
We now refuse to boot on machines that don't support PAE since all of our paging code depends on it. Also let's only enable SSE and PGE support if the CPU advertises it.
2020-01-01Kernel: Enable x86 SMEP (Supervisor Mode Execution Protection)Andreas Kling
This prevents the kernel from jumping to code in userspace memory.
2020-01-01Kernel: Make module_load() and module_unload() be superuser-onlyAndreas Kling
These should just fail with EPERM if you're not the superuser.
2019-12-31Kernel: Implement AltGr key supportTibor Nagy
2019-12-31Kernel: Pointer range validation should fail on wraparoundAndreas Kling
Let's reject address ranges that wrap around the 2^32 mark.
2019-12-31Kernel: Write address validation was only checking end of write rangeAndreas Kling
Thanks to yyyyyyy for finding the bug! :^)
2019-12-31ProcFS: Supervisor-only inodes should be owned by UID 0, GID 0Andreas Kling
2019-12-31Kernel: Always reject never-userspace addresses before checking regionsAndreas Kling
At the moment, addresses below 8MB and above 3GB are never accessible to userspace, so just reject them without even looking at the current process's memory regions.
2019-12-31Kernel+ping: Only allow superuser to create SOCK_RAW socketsAndreas Kling
/bin/ping is now setuid-root, and will drop privileges immediately after opening a raw socket.
2019-12-31ProcFS: Reduce the amount of info accessible to non-superusersAndreas Kling
This patch hardens /proc a bit by making many things only accessible to UID 0, and also disallowing access to /proc/PID/ for anyone other than the UID of that process (and superuser, obviously.)
2019-12-31Kernel: Remove some unnecessary leaking of kernel pointers into dmesgAndreas Kling
There's a lot more of this and we need to stop printing kernel pointers anywhere but the debug console.
2019-12-31Kernel: Let's also not consider kernel regions to be valid user stacksAndreas Kling
This one is less obviously exploitable than the previous one, but still a bug nonetheless.
2019-12-31Kernel: User pointer validation should reject kernel-only addressesAndreas Kling
We were happily allowing syscalls with pointers into kernel-only regions (virtual address >= 0xc0000000). This patch fixes that by only considering user regions in the current process, and also double-checking the Region::is_user_accessible() flag before approving an access. Thanks to Fire30 for finding the bug! :^)
2019-12-30Kernel: Also add a process boosting mechanismAndreas Kling
Let's also have set_process_boost() for giving all threads in a process the same boost.
2019-12-30Kernel: Add a basic thread boosting mechanismAndreas Kling
This patch introduces a syscall: int set_thread_boost(int tid, int amount) You can use this to add a permanent boost value to the effective thread priority of any thread with your UID (or any thread in the system if you are the superuser.) This is quite crude, but opens up some interesting opportunities. :^)
2019-12-30Kernel: Refactor scheduler to use dynamic thread prioritiesAndreas Kling
Threads now have numeric priorities with a base priority in the 1-99 range. Whenever a runnable thread is *not* scheduled, its effective priority is incremented by 1. This is tracked in Thread::m_extra_priority. The effective priority of a thread is m_priority + m_extra_priority. When a runnable thread *is* scheduled, its m_extra_priority is reset to zero and the effective priority returns to base. This means that lower-priority threads will always eventually get scheduled to run, once its effective priority becomes high enough to exceed the base priority of threads "above" it. The previous values for ThreadPriority (Low, Normal and High) are now replaced as follows: Low -> 10 Normal -> 30 High -> 50 In other words, it will take 20 ticks for a "Low" priority thread to get to "Normal" effective priority, and another 20 to reach "High". This is not perfect, and I've used some quite naive data structures, but I think the mechanism will allow us to build various new and interesting optimizations, and we can figure out better data structures later on. :^)
2019-12-29Kernel: Retry mmap if MAP_FIXED is not in flags and addr is not 0Andrew Kaster
If an mmap fails to allocate a region, but the addr passed in was non-zero, non-fixed mmaps should attempt to allocate at any available virtual address.
2019-12-29Kernel: Add move assign operator to KResultOrAndrew Kaster
2019-12-29Kernel: Embrace the SerenityOS nameAndreas Kling
2019-12-29Kernel: Add a mode flag to sys$purge and allow purging clean inodesAndreas Kling
2019-12-29Kernel+SystemMonitor: Expose amount of per-process clean inode memoryAndreas Kling
This is memory that's loaded from an inode (file) but not modified in memory, so still identical to what's on disk. This kind of memory can be freed and reloaded transparently from disk if needed.
2019-12-29Kernel+SystemMonitor: Expose amount of per-process dirty private memoryAndreas Kling
Dirty private memory is all memory in non-inode-backed mappings that's process-private, meaning it's not shared with any other process. This patch exposes that number via SystemMonitor, giving us an idea of how much memory each process is responsible for all on its own.
2019-12-28Kernel: Fix code locked behind NETWORK_TASK_DEBUGConrad Pankoff
2019-12-28Kernel: Route all loopback traffic through the loopback adapterConrad Pankoff
2019-12-28Kernel: Move incoming packet buffer off the NetworkTask stackConrad Pankoff
2019-12-27MenuApplets: Add Clock applet, move code from WindowServer to the applet.Hüseyin ASLITÜRK
2019-12-27Build: Allow building serenityOS ext2 root filesystem on macOS hostStefano Cristiano
2019-12-27Kernel: Add kernel-level timer queue (heavily based on @juliusf's work)Conrad Pankoff
PR #591 defines the rationale for kernel-level timers. They're most immediately useful for TCP retransmission, but will most likely see use in many other areas as well.
2019-12-27Kernel: Separate runnable thread queues by priorityAndreas Kling
This patch introduces three separate thread queues, one for each thread priority available to userspace (Low, Normal and High.) Each queue operates in a round-robin fashion, but we now always prefer to schedule the highest priority thread that currently wants to run. There are tons of tweaks and improvements that we can and should make to this mechanism, but I think this is a step in the right direction. This makes WindowServer significantly more responsive while one of its clients is burning CPU. :^)
2019-12-26Kernel: Simplify force_pio logic in PATA driver (#923)Conrad Pankoff
2019-12-26Kernel: Move PC speaker beep timing logic from scheduler to the syscallAndreas Kling
I don't know why I put this in the scheduler to begin with.. the caller can just block until the beeping is finished.
2019-12-26Kernel: Process::for_each_in_pgrp() should not include dead processesAndreas Kling
We don't care about dead processes that were once members of a specific process group. This was causing us to try and send SIGINT to already-dead processes when pressing Ctrl+C in a terminal whose pgrp they were once in. Fixes #922.
2019-12-26Kernel: When physical page allocation fails, try to purge somethingAndreas Kling
Instead of panicking right away when we run out of physical pages, we now try to find a PurgeableVMObject with some volatile pages in it. If we find one, we purge that entire object and steal one of its pages. This makes it possible for the kernel to keep going instead of dying. Very cool. :^)
2019-12-26ProcFS: Fix inconsistent numbers in /proc/memstatAndreas Kling
We were listing the total number of user/super pages as the number of "available" pages in the system. This was then misinterpreted in the SystemMonitor program and displayed wrong in the GUI.
2019-12-26Kernel: Add Lock::is_locked()Andreas Kling
2019-12-26Kernel: Detect support for no-execute (NX) CPU featuresConrad Pankoff
Previously we assumed all hosts would have support for IA32_EFER.NXE. This is mostly true for newer hardware, but older hardware will crash and burn if you try to use this feature. Now we check for support via CPUID.80000001[20].
2019-12-25Kernel+LibPthread+LibC: Add a naive futex and use it for pthread_cond_tAndreas Kling
This patch implements a simple version of the futex (fast userspace mutex) API in the kernel and uses it to make the pthread_cond_t API's block instead of busily sched_yield(). An arbitrary userspace address is passed to the kernel as a "token" that identifies the futex and you can then FUTEX_WAIT and FUTEX_WAKE that specific userspace address. FUTEX_WAIT corresponds to pthread_cond_wait() and FUTEX_WAKE is used for pthread_cond_signal() and pthread_cond_broadcast(). I'm pretty sure I'm missing something in this implementation, but it's hopefully okay for a start. :^)
2019-12-25Kernel: Make kernel memory regions be non-executable by defaultAndreas Kling
From now on, you'll have to request executable memory specifically if you want some.
2019-12-25Kernel: Set NX bit for virtual addresses 0-1MB and 2-8MBAndreas Kling
This removes the ability to jump into kmalloc memory, etc. Only the kernel image itself is allowed to exec, located between 1-2MB.
2019-12-25Kernel: Clarify the various input validity checks in mmap()Andreas Kling
Also share some validation logic between mmap() and mprotect().
2019-12-25run: Run QEMU with "-cpu max"Andreas Kling
This should give us access to the largest set of CPU features available on the host machine.