summaryrefslogtreecommitdiff
path: root/Kernel
AgeCommit message (Collapse)Author
2020-12-25AK: Remove custom %w format string specifierAndreas Kling
This was a non-standard specifier alias for %04x. This patch replaces all uses of it with new-style formatting functions instead.
2020-12-25AK: Remove custom %b format string specifierAndreas Kling
This was a non-standard specifier alias for %02x. This patch replaces all uses of it with new-style formatting functions instead.
2020-12-25Kernel: Allocate new main thread stack before committing to execAndreas Kling
If the allocation fails (e.g ENOMEM) we want to simply return an error from sys$execve() and continue executing the current executable. This patch also moves make_userspace_stack_for_main_thread() out of the Thread class since it had nothing in particular to do with Thread.
2020-12-25Kernel: Move ELF auxiliary vector building out of Process classAndreas Kling
Process had a couple of members whose only purpose was holding on to some temporary data while building the auxiliary vector. Remove those members and move the vector building to a free function in execve.cpp
2020-12-25LibELF: Move AuxiliaryValue into the ELF namespaceAndreas Kling
2020-12-25Kernel+LibELF: Abort ELF executable load sooner when something failsAndreas Kling
Make it possible to bail out of ELF::Image::for_each_program_header() and then do exactly that if something goes wrong during executable loading in the kernel. Also make the errors we return slightly more nuanced than just ENOEXEC.
2020-12-25Kernel: Remove an unnecessary cast in sys$execve()Andreas Kling
2020-12-25Kernel: Don't fetch full inode metadata in sys$execve()Andreas Kling
We only need the size, so let's not fetch all the metadata.
2020-12-25Kernel: Add back missing ELF::Image validity checkAndreas Kling
If the image is not a valid ELF we should just fail ASAP.
2020-12-25Kernel: Convert dbg() => dbgln() in sys$execve()Andreas Kling
2020-12-25Kernel: Add formatter for VirtualAddressAndreas Kling
2020-12-25Kernel: Simplify ELF loading logic in sys$execve() somewhatAndreas Kling
Get rid of the lambda functions and put the logic inline in the program header traversal loop instead. This makes the code quite a bit shorter and hopefully makes it easier to see what's going on.
2020-12-25LibELF: Remove ELF::Loader and move everyone to ELF::ImageAndreas Kling
This commit gets rid of ELF::Loader entirely since its very ambiguous purpose was actually to load executables for the kernel, and that is now handled by the kernel itself. This patch includes some drive-by cleanup in LibDebug and CrashDaemon enabled by the fact that we no longer need to keep the ref-counted ELF::Loader around.
2020-12-25Kernel+LibELF: Move sys$execve()'s loading logic from LibELF to KernelAndreas Kling
It was really weird that ELF loading was performed by the ELF::Loader class instead of just being done by the kernel itself. This patch moves all the layout logic from ELF::Loader over to sys$execve(). The kernel no longer cares about ELF::Loader and instead only uses an ELF::Image as an interpreting wrapper around executables.
2020-12-25Kernel+LibELF: Stop doing ELF symbolication in the kernelAndreas Kling
Now that the CrashDaemon symbolicates crashes in userspace, let's take this one step further and stop trying to symbolicate userspace programs in the kernel at all.
2020-12-24Kernel+LibELF: Allow Non ET_DYN executables to have an interpreterItamar
2020-12-24Kernel: Fix mmap with specific address for file backed mappingsItamar
2020-12-24ProcFS: pid_vm: Replace duplicated purgeable key with kernel+cacheableBrendan Coles
ProcFS /proc/<pid>/vm map info no longer contains two `purgeable` keys. The second `purgeable` key has been removed and replaced with keys for `kernel` and `cacheable`.
2020-12-23Kernel: Tweak parameter name in Inode::read_entire()Andreas Kling
This is a descriptION, not a descriptOR. :^)
2020-12-23Kernel: Fix wrong-looking overflow check in sys$execve()Andreas Kling
This was harmless since sizeof(length) and sizeof(strings) are both 4 on x86 but let's check the right things regardless.
2020-12-23Kernel: Don't assert when reading from a listening-mode local socketAndreas Kling
Instead just fail with EINVAL as a listening socket is never suitable for reading from. Fixes #4511.
2020-12-23Kernel: Ptrace::handle_syscall() should return errors as KResultAndreas Kling
2020-12-23Kernel: Don't assert on PT_PEEK with kernelspace addressAndreas Kling
We were casting the address to Userspace<T> without validating it first which is no good and will trap an assertion soon after. Let's catch this sooner with an ASSERT in the Userspace<T> constructor and update the PT_PEEK and PT_POKE handlers to avoid it. Fixes #4505.
2020-12-23Kernel: Panic if we're about to switch to a user thread with IOPL!=0Andreas Kling
This is a crude protection against IOPL elevation attacks. If for any reason we find ourselves about to switch to a user mode thread with IOPL != 0, we'll now simply panic the kernel. If this happens, it basically means that something tricked the kernel into incorrectly modifying the IOPL of a thread, so it's no longer safe to trust the kernel anyway.
2020-12-23Kernel: Make KBuffer::try_create_with_bytes() actually copy the bytesAndreas Kling
KBuffers created with this API were actually just zero-filled instead of being populated with the provided bytes. Fixes #4493.
2020-12-22Kernel: Don't allow modifying IOPL via sys$ptrace() or sys$sigreturn()Andreas Kling
It was possible to overwrite the entire EFLAGS register since we didn't do any masking in the ptrace and sigreturn syscalls. This made it trivial to gain IO privileges by raising IOPL to 3 and then you could talk to hardware to do all kinds of nasty things. Thanks to @allesctf for finding these issues! :^) Their exploit/write-up: https://github.com/allesctf/writeups/blob/master/2020/hxpctf/wisdom2/writeup.md
2020-12-22Kernel: Allow sys$chmod() to modify the set-gid bitAndreas Kling
We were incorrectly masking off the set-gid bit. Fixes #4060.
2020-12-22Kernel/Net: Support all E1000 devices in the spec sheetLuke
Since they're all covered by the same spec sheet, we can expect the same code to cover most of the devices. It can't currently differentiate between them, which would be nice to add for determining what registers we can access.
2020-12-22Kernel: Abort core dump generation if any substep failsAndreas Kling
And make an effort to propagate errors out from the inner parts. This fixes an issue where the kernel would infinitely loop in coredump generation if the TmpFS filled up.
2020-12-22Kernel/PCI: Add a bunch of debug output to accessorsLuke
This was useful for debugging this issue.
2020-12-22Kernel/PCI: Create device configuration space mapping before creating a ↵Luke
physical ID When enumerating the hardware using MMIO mode, it would attempt to create a physical ID first. To create a physical ID, it needs to retrieve the capabilities of the device. When enumerating the first device, there would be no device configuration space mappings. Access::get_capabilities_pointer calls PCI::read16, which in turn goes to MMIOAccess::read16_field. MMIOAccess::read16_field attempts to get a device configuration space and fully expects to get one. However, since this is the first device, there are none and it crashes with an m_has_value assertion failure. This fixes this by creating the device configuration space mapping before creating the physical ID. Testing with VMware Player 16.1.0.
2020-12-22Kernel/Net: E1000 interrupt rate register is 32-bit, not 16-bitLuke
I looked at the spec sheet and noticed that it's 32-bit, not 16-bit. This fixes E1000 causing an MMIO fault on VirtualBox. Spec: https://www.intel.com/content/dam/doc/manual/pci-pci-x-family-gbe-controllers-software-dev-manual.pdf Section 13.4.18
2020-12-21Kernel: Improve time keeping and dramatically reduce interrupt loadTom
This implements a number of changes related to time: * If a HPET is present, it is now used only as a system timer, unless the Local APIC timer is used (in which case the HPET timer will not trigger any interrupts at all). * If a HPET is present, the current time can now be as accurate as the chip can be, independently from the system timer. We now query the HPET main counter for the current time in CPU #0's system timer interrupt, and use that as a base line. If a high precision time is queried, that base line is used in combination with quering the HPET timer directly, which should give a much more accurate time stamp at the expense of more overhead. For faster time stamps, the more coarse value based on the last interrupt will be returned. This also means that any missed interrupts should not cause the time to drift. * The default system interrupt rate is reduced to about 250 per second. * Fix calculation of Thread CPU usage by using the amount of ticks they used rather than the number of times a context switch happened. * Implement CLOCK_REALTIME_COARSE and CLOCK_MONOTONIC_COARSE and use it for most cases where precise timestamps are not needed.
2020-12-21Kernel: Introduce the StorageManagement classLiav A
The StorageManagement class has 2 roles: 1. During boot, it should find all storage controllers in the machine, and then determine what is the boot device. 2. Later on boot, it is a registrar of all storage controllers and storage devices. Thus, it could be used to show information about these devices when implemented. This change allows the user to specify a boot driver other than /dev/hda and if it's connected in the machine - it will boot.
2020-12-21Kernel: Change the indexing of storage devices in IDEController classLiav A
Previously, the indexing scheme was that 0 is Primary-Master, 1 is Primary-Slave, 2 is Secondary-Master, 3 is Secondary-Slave. Instead of merely matching between numbers to the channel & position, the IDEController code will try to find all available drives connected to the two channels, then it will create a Vector with nonnull RefPtr to them. Then we take use the given index with this Vector.
2020-12-21Kernel: Add a method to gather the devices count of a Storage controllerLiav A
Also, change device() method to be const.
2020-12-21Kernel: Add a method to check the type of a StorageControllerLiav A
Also, the device method in the StorageController class is public now.
2020-12-21Kernel: Allow to initialize an IDE device on the secondary channelLiav A
We now use major number 3, and the minor number is set to 0 or 2 if initialized on the primary channel, otherwise 1 or 3 on the secondary channel.
2020-12-21Kernel: Introduce the new Storage subsystemLiav A
This new subsystem is somewhat replacing the IDE disk code we had with a new flexible design. StorageDevice is a generic class that represent a generic storage device. It is meant that specific storage hardware will override the interface. StorageController is a generic class that represent a storage controller that can be found in a machine. The IDEController class governs two IDEChannels. An IDEChannel is responsible to manage the master & slave devices of the channel, therefore an IDEChannel is an IRQHandler.
2020-12-21Kernel: Allow to install a real IRQ handler on a spurious oneLiav A
IRQ 7 and 15 on the PIC architecture are used for spurious interrupts. IRQ 7 could also be used for LPT connection, and IRQ 15 can be used for the secondary IDE channel. Therefore, we need to allow to install a real IRQ handler and check if a real IRQ was asserted. If so, we handle them in the usual way. A note on this fix - unregistering or registering a new IRQ handler after we already registered one in the spurious interrupt handler is not supported yet.
2020-12-21Kernel: Add various methods to handle interrupts in the PCI subsystemLiav A
For now, we only are able to enable or disable pin based interrupts. Later, when implemented, we could utilize MSI & MSI-X interrupts.
2020-12-21Kernel: Add a method to retrieve the Physical ID for a PCI addressLiav A
2020-12-21PCI: Add list of capabilities for each device during first enumerationLiav A
2020-12-21Kernel: Add the DeviceController class in the PCI subsystemLiav A
Such device is not an IRQHandler by itself, but actually a controller of many IRQ or MSI devices. The purpose of this class is to manage multiple sources of interrupts. For example, a generic ISA IDE controller controls 2 IRQ sources - 14 and 15. So, when we initialize the IDE controller, it will initialize two IDE channels (also known as PATAChannels) to utilize IRQ 14 and 15, respectively. NVMe with MSI-X support can theoretically handle up to 2048 interrupts.
2020-12-21Kernel: Don't skip if found free page to allocate from a super regionLiav A
This was a bad pattern that wasn't detected because we only had one super physical region that was initialized by MemoryManager.
2020-12-21Everywhere: Switch from (void) to [[maybe_unused]] (#4473)Lenny Maiorani
Problem: - `(void)` simply casts the expression to void. This is understood to indicate that it is ignored, but this is really a compiler trick to get the compiler to not generate a warning. Solution: - Use the `[[maybe_unused]]` attribute to indicate the value is unused. Note: - Functions taking a `(void)` argument list have also been changed to `()` because this is not needed and shows up in the same grep command.
2020-12-20Kernel: Randomize memory location of the dynamic loader :^)Andreas Kling
This should make it a little bit harder for those who would mess with our loader.
2020-12-20Kernel: Ptrace should not assert on poke in non-mapped tracee memoryAndreas Kling
2020-12-20Kernel: Activate SUID/SGID credentials earlier in sys$execve()Andreas Kling
Switch on the new credentials before loading the new executable into memory. This ensures that attempts to ptrace() the program from an unprivileged process will fail. This covers one bug that was exploited in the 2020 HXP CTF: https://hxp.io/blog/79/hxp-CTF-2020-wisdom2/ Thanks to yyyyyyy for finding the bug! :^)
2020-12-20Kernel: Silence debug spam about select() being interruptedAndreas Kling