summaryrefslogtreecommitdiff
path: root/Kernel
AgeCommit message (Collapse)Author
2020-01-02Kernel: Move kernel symbols to /res/kernel.map and make it root-onlyAndreas Kling
Let's lock down access to the kernel symbol table, since it trivializes learning where the kernel functions are. Of course, you can just build the same revision yourself locally and learn the information, but we're taking one step at a time here. :^)
2020-01-02Kernel: Add some missing error checks to the setpgid() syscallAndreas Kling
2020-01-02Kernel: Remove debug spam about marking threads for deathAndreas Kling
2020-01-02Kernel: Make the purge() syscall superuser-onlyAndreas Kling
I don't think we need to give unprivileged users access to what is essentially a kernel testing mechanism.
2020-01-02Kernel: writev() should fail with EINVAL if total length > INT32_MAXAndreas Kling
2020-01-02Kernel: Remove broken implementation of Unix SHMAndreas Kling
This code never worked, as was never used for anything. We can build a much better SHM implementation on top of TmpFS or similar when we get to the point when we need one.
2020-01-02Kernel: sys$mprotect protects sub-regions as well as whole onesAndrew Kaster
Split a region into two/three if the desired mprotect range is a strict subset of an existing region. We can then set the access bits on a new region that is just our desired range and add both the new desired subregion and the leftovers back to our page tables.
2020-01-02Kernel: Make mknod() respect the process umaskAndreas Kling
Otherwise the /bin/mknod command would create world-writable inodes by default (when run by superuser) which you probably don't want.
2020-01-02Kernel: mknod() should not allow unprivileged users to create devicesAndreas Kling
In fact, unless you are superuser, you may only create a regular file, a named pipe, or a local domain socket. Anything else should EPERM.
2020-01-02Kernel: Validate the full range of user memory passed to syscallsAndreas Kling
We now validate the full range of userspace memory passed into syscalls instead of just checking that the first and last byte of the memory are in process-owned regions. This fixes an issue where it was possible to avoid rejection of invalid addresses that sat between two valid ones, simply by passing a valid address and a size large enough to put the end of the range at another valid address. I added a little test utility that tries to provoke EFAULT in various ways to help verify this. I'm sure we can think of more ways to test this but it's at least a start. :^) Thanks to mozjag for pointing out that this code was still lacking! Incidentally this also makes backtraces work again. Fixes #989.
2020-01-02Kernel: Create support for PCI ECAMLiav A
The new PCI subsystem is initialized during runtime. PCI::Initializer is supposed to be called during early boot, to perform a few tests, and initialize the proper configuration space access mechanism. Kernel boot parameters can be specified by a user to determine what tests will occur, to aid debugging on problematic machines. After that, PCI::Initializer should be dismissed. PCI::IOAccess is a class that is derived from PCI::Access class and implements PCI configuration space access mechanism via x86 IO ports. PCI::MMIOAccess is a class that is derived from PCI::Access and implements PCI configurtaion space access mechanism via memory access. The new PCI subsystem also supports determination of IO/MMIO space needed by a device by checking a given BAR. In addition, Every device or component that use the PCI subsystem has changed to match the last changes.
2020-01-02Kernel: Create a basic SMBIOS DecoderLiav A
We use DMI decoding now just to determine if PCI is available. The DMIDecoder is initialized during early boot, thus making it possible to probe useful data about the machine. Other purposes are not supported yet.
2020-01-02Kernel: Introduce the ACPI subsystemLiav A
ACPI subsystem includes 3 types of parsers that are created during runtime, each one capable of parsing ACPI tables at different level. ACPIParser is the most basic parser which is essentialy a parser that can't parse anything useful, due to a user request to disable ACPI support in a kernel boot parameter. ACPIStaticParser is a derived class from ACPIParser, which is able to parse only static data (e.g. FADT, HPET, MCFG and other tables), thus making it not able to parse AML (ACPI Machine Language) nor to support handling of hardware events and power management. This type of parser can be created with a kernel boot parameter. ACPIDynamicParser is a derived class from ACPIStaticParser, which includes all the capabilities of the latter, but *should* implement an AML interpretation, (by building the ACPI AML namespace) and handling power & hardware events. Currently the methods to support AML interpretation are not implemented. This type of parser is created automatically during runtime if the user didn't specify a boot parameter related to ACPI initialization. Also, adding strncmp function definition in StdLib.h, to be able to use it in ACPIStaticParser class.
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.