Commit graph

7184 commits

Author SHA1 Message Date
Tim Schumacher cd189999d1 Kernel: Don't let locks of the same owner conflict with each other
Documentation on POSIX locks seems sparse, but this is how the Linux
kernel implementation handles it.
2022-07-08 22:27:38 +00:00
Tim Schumacher dc6016cd18 Kernel: Don't fail on unlocking nonexistent file locks
I haven't found any POSIX specification on this, but the Linux kernel
appears to handle it like that.

This is required by QEMU, as it just bulk-unlocks all its file locking
bytes without checking first if they are held.
2022-07-08 22:27:38 +00:00
Tim Schumacher 7d3f71a648 Kernel: Do not disable userland access to the RDTSC instruction
Access to RDTSC is occasionally restricted to give malware one less
option to accurately time attacks (side-channels, etc.).

However, QEMU requires access to the timestamp counter for the exact
same reason (which is accurately timing its CPU ticks), so lets just
enable it for now.
2022-07-08 22:27:38 +00:00
Tim Schumacher 5efa8e507b Kernel: Implement an axallowed mount option
Similar to `W^X` and `wxallowed`, this allows for anonymous executable
mappings.
2022-07-08 22:27:38 +00:00
Liav A 8de395694d Kernel/Storage: Do proper locking & reset in the AHCIController code
The initialize_hba method now calls the reset method to reset the HBA
and initialize each AHCIPort. Also, after full HBA reset we need to turn
on the AHCI functionality of the HBA and global interrupts since they
are cleared to 0 according to the specification in the GHC register.
2022-07-08 01:06:47 +03:00
Liav A 4d36989954 Kernel/Storage: Move Identify page allocation to the AHCIPort class
Instead of doing this in a parent class like the AHCIController, let's
do that directly in the AHCIPort class as that class is the only user of
these sort of physical pages. While it seems like we waste an entire 4KB
of physical RAM for each allocation, this could serve us later on if we
want to fetch other types of logs from the ATA device.
2022-07-08 01:06:47 +03:00
Liav A bf82c4b81b Kernel/Storage: Rename AHCIPortHandler => AHCIInterruptHandler
This reflects better what this object is all about - handling interrupts
of AHCI ports, and nothing more than that.
2022-07-08 01:06:47 +03:00
Liav A cc734c106e Kernel/Storage: Simplify AHCIPortHandler class
The way AHCIPortHandler held AHCIPorts and even provided them with
physical pages for the ATA identify buffer just felt wrong.
To fix this, AHCIPortHandler is not a ref-counted object anymore. This
solves the big part of the problem, because AHCIPorts can't hold a
reference to this object anymore, only the AHCIController can do that.
Then, most of the responsibilities are shifted to the AHCIController,
making the AHCIPortHandler a handler of port interrupts only.
2022-07-08 01:06:47 +03:00
Liav A 4169ac4a7b Kernel/Storage: Remove 3 stale methods in AHCIPortHandler class 2022-07-08 01:06:47 +03:00
Liav A 9416dede54 Kernel/AHCI: Don't use UNMAP_AFTER_INIT in header files
Instead, declare such methods and functions in the code itself.
2022-07-08 01:06:47 +03:00
Liav A d771ca3278 Kernel: Clean up the AHCI code a bit
The AHCI code is not very good at OOM conditions, so this is a first
step towards OOM correctness. We should not allocate things inside C++
constructors because we can't catch OOM failures, so most allocation
code inside constructors is exported to a different function.

Also, don't use a HashMap for holding RefPtr of AHCIPort objects in
AHCIPortHandler because this structure is not very OOM-friendly. Instead
use a fixed Array of 32 RefPtrs, as at most we can have 32 AHCI ports
per AHCI controller.
2022-07-08 01:06:47 +03:00
Tim Schumacher 67f352b824 Kernel: Copy signal handlers when forking 2022-07-05 20:58:38 +03:00
Tim Schumacher add4dd3589 Kernel: Do a POSIX-correct signal handler reset on exec 2022-07-05 20:58:38 +03:00
Idan Horowitz af71aa4e0b Kernel: Negate condition in ARPTableBlockerSet::should_add_blocker
To prevent a race condition in case we received the ARP response in the
window between creating and initializing the Thread Blocker and the
actual blocking, we were checking if the IP address was updated in the
ARP table just before starting to block.
Unfortunately, the condition was partially flipped, which meant that if
the table was updated with the IP address we would still end up
blocking, at which point we would never end unblocking again, which
would result in LookupServer locking up as well.
2022-07-04 01:56:43 +03:00
b14ckcat 143339767b Kernel/USB: Move buffer allocation from USB transfer to USB pipe
Currently when allocating buffers for USB transfers, it is done
once for every transfer rather than once upon creation of the
USB device. This commit changes that by moving allocation of buffers
to the USB Pipe class where they can be reused.
2022-07-03 01:15:07 +02:00
b14ckcat 13445f5a43 Kernel/USB: Use proper error codes for UHCI transfers 2022-06-29 13:38:13 +01:00
Liav A cd115270fc Kernel/Graphics: Move GenericDisplayConnector code to a new sub-folder
In the same fashion like in the Linux kernel, we support pre-initialized
framebuffers that were set up by either the BIOS or the bootloader.
These framebuffers can be backed by any kind of video hardware, and are
not tied to VGA hardware at all. Therefore, this code should be in a
separate sub-folder in the Graphics subsystem to indicate this.
2022-06-25 11:32:09 +01:00
Brian Gianforcaro 458244c0c1 Kernel: Enable -ftrivial-auto-var-init as a security mitigation
The flag will automatically initialize all variables to a pattern based
on it's type. The goal being here is to eradicate an entire bug class
of issues that can originate from uninitialized stack memory.

Some examples include:

 - Kernel information disclosure, where uninitialized struct members
   or struct padding is copied back to usermode, leaking kernel
   information such as stack or heap addresses, or secret data like
   stack cookies.

 - Control flow based on uninitialized memory can cause a variety of
   issues at runtime, including stack corruptions like buffer
   overflows, heap corruptions due to deleting stray pointers.
   Even basic logic bugs can result from control flow operating on
   uninitialized data.

As of GCC 12 this flag is now supported.
https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=a25e0b5e6ac8a77a71c229e0a7b744603365b0e9

Clang has already supported it for a few releases.
https://reviews.llvm.org/D54604
2022-06-24 12:35:36 +01:00
kleines Filmröllchen f6af357763 Kernel/Audio: Fix buffer size underflow for non-page-aligned sizes
When the size of the audio data was not a multiple of a page size,
subtracting the page size from this unsigned variable would underflow it
close to 2^32 and be clamped to the page size again. This would lead to
writes into garbage addresses because of an incorrect write size,
interestingly only causing the write() call to error out.

Using saturating math neatly fixes this problem and allows buffer
lengths that are not a multiple of a page size.
2022-06-23 23:26:33 +01:00
Michał Lach e2b0f6795f LibVT+Kernel: Separate the caret shapes and its steadiness
Currently CursorStyle enum handles both the styles and the steadiness or
blinking of the terminal caret, which doubles the amount of its entries.
This commit changes CursorStyle to CursorShape and moves the blinking
option to a seperate boolean value.
2022-06-22 12:12:00 +01:00
Idan Horowitz 1950e79d48 Kernel: Eliminate possible KASLR leak by disabling CR4.FSGSBASE
The RDGSBASE userspace instruction allows programs to read the contents
of the gs segment register which contains a kernel pointer to the base
of the current Processor struct.

Since we don't use this instruction in Serenity at the moment, we can
simply disable it for now to ensure we don't break KASLR. Support can
later be restored once proper swapping of the contents of gs is done on
userspace/kernel boundaries.
2022-06-22 07:52:35 +03:00
Tim Schumacher cedec9751a Kernel: Decrease the amount of address space offset randomization
This is basically unchanged since the beginning of 2020, which is a year
before we had proper ASLR.

Now that we have a proper ASLR implementation, we can turn this down a
bit, as it is no longer our only protection against predictable dynamic
loader addresses, and it actually obstructs the default loading address
of x86_64 quite frequently.
2022-06-21 22:38:15 +01:00
Andrew Kaster 455038d6fc Kernel: Add sysconf for IOV_MAX 2022-06-19 09:05:35 +02:00
Andrew Kaster 1d3b5d330d Kernel: Tolerate cloning MAP_STACK regions that are PROT_NONE
There's nothing stopping a userspace program from keeping a bunch of
threads around with a custom signal stack in a suspended state with
their normal thread stack mprotected to PROT_NONE.

OpenJDK seems to do this, for example.
2022-06-19 09:05:35 +02:00
Andrew Kaster 940be19259 Kernel: Create /proc/pid/cmdline to expose process arguments in procfs
In typical serenity style, they are just a JSON array
2022-06-19 09:05:35 +02:00
Andreas Kling 0132e494d6 Kernel: Add missing #include in SysFS.cpp 2022-06-17 12:22:07 +02:00
Liav A 30b58cd06c Kernel/SysFS: Remove derived BIOSSysFSComponent classes
These are not needed, because both do exactly the same thing, so we can
move the code to the BIOSSysFSComponent class.
2022-06-17 11:01:27 +02:00
Liav A 23c1c40e86 Kernel/SysFS: Migrate components code from SysFS.cpp to the SysFS folder 2022-06-17 11:01:27 +02:00
Liav A 4d05a41b30 Kernel/SysFS: Split the bulky BIOS.h file into multiple files 2022-06-17 11:01:27 +02:00
Liav A 9c6834698f Kerenl/Firmware: Add map_ebda and map_bios methods in the original place
In a previous commit I moved everything into the new subdirectories in
FileSystem/SysFS directory without trying to actually make changes in
the code itself too much. Now it's time to split the code to make it
more readable and understandable, hence this change occurs now.
2022-06-17 11:01:27 +02:00
Liav A 7310a9a641 Kernel/Interrupts: Add missing include for IRQController header file
This is necessary for the next commit in the patch, otherwise this can't
be compiled. It seems like this was a hidden issue that is discovered
now only by changing includes in a mass-scale.
2022-06-17 11:01:27 +02:00
Liav A 99bac4f34f Kernel/SysFS: Split bulky SysFSPCI file into separate files 2022-06-17 11:01:27 +02:00
Liav A e488245234 Kernel/SysFS: Split bulky SysFSUSB file into two separate class files 2022-06-17 11:01:27 +02:00
Liav A 290eb53cb5 Kernel/SysFS: Stop cluttering the codebase with pieces of SysFS parts
Instead, start to put everything in one place to resemble the directory
structure of the SysFS when actually using it.
2022-06-17 11:01:27 +02:00
SeekingBlues 8730e56e88 LibC: Add WIFCONTINUED macro
Like other systems, we can encode the continued state with 0xffff in the
status value. This is needed for some ports.
2022-06-17 10:59:26 +02:00
kleines Filmröllchen 1b25513ed7 Kernel: Don't VERIFY that the DMA channel is running on AC'97 interrupt
Fixes #13771; as discussed it's not really a problem to receive an
interrupt while the DMA channel is not running, but we do want to log
it.
2022-06-15 20:53:10 +03:00
Andreas Kling 4e4a930b13 Kernel: Use the system boot time as default timestamp in /sys and /dev 2022-06-15 17:15:04 +02:00
Andreas Kling adaaea4c9a Kernel: Make TimeManagement::boot_time() static 2022-06-15 17:15:04 +02:00
Andreas Kling 9e994da2ac Kernel+AK: Split Weakable.h into userspace and kernel variants
Only the kernel expects AK::Weakable to lock its refcount manipulation,
so let's not force userspace to pay for that as well.
2022-06-15 17:15:04 +02:00
Timur Sultanov 0a63461341 Kernel: Add s6_addr32 field in in6_addr struct 2022-06-12 00:28:26 +01:00
MacDue 1dcdcc7efb Kernel/Console: Fix gaps between background glyph color 2022-06-11 12:19:29 +01:00
Liav A 20c9e4c05c Kernel/Graphics: Ensure VMWare and VirtualBox EDIDs have manufacturer ID 2022-06-10 22:32:54 +01:00
Liav A 3d36b194d1 Kernel/Graphics: Ensure generic EDID always has correct checksum 2022-06-10 22:32:54 +01:00
Liav A 938d579d16 Kernel/Graphics: Re-organize the DisplayConnector class a bit
Move methods that are overriding the virtual methods in the File class,
to a private access scope in the DisplayConnector class because nobody
tries to access them in any derived class of this class.
2022-06-10 22:32:54 +01:00
MacDue 348750a9f4 Kernel/Console: Tidy up code a little
- Remove some magic numbers
- Remove some duplicate branches
- Reduce the amount of casting between u8* and u32*
- Some renaming of confusing variables
2022-06-09 22:06:46 +02:00
MacDue 805a3d5b29 Kernel/Console: Factor out framebuffer offset and support glyph_spacing
This allows the 9px width of Cathode to be preserved without increasing
the bitmap size.
2022-06-09 22:06:46 +02:00
MacDue adef79b793 Kernel/Console: Replace QEMU bitmap font with Cathode
This has very similar look, but was invented here :^)
2022-06-09 22:06:46 +02:00
Liav A b4e409f721 Kernel/Graphics: Drop support for the DisplayConnector write interface
The WindowServer doesn't use this interface anymore and therefore it's
not used by any userspace application, so let's remove this stale method
to ensure we don't have to bother with it anymore.
2022-06-06 20:11:05 +01:00
Liav A e2ed6ef741 Kernel/Graphics: Bring back the mmap interface for DisplayConnectors
The mmap interface was removed when we introduced the DisplayConnector
class, as it was quite unsafe to use and didn't handle switching between
graphical and text modes safely. By using the SharedFramebufferVMObject,
we are able to elegantly coordinate the switch by remapping the attached
mmap'ed-Memory::Region(s) with different mappings, therefore, keeping
WindowServer to think that the mappings it has are still valid, while
they are going to a different physical range until we are back to the
graphical mode (after a switch from text mode).

Most drivers take advantage of the fact that we know where is the actual
framebuffer in physical memory space, the SharedFramebufferVMObject is
created with that information. However, the VirtIO driver is different
in that aspect, because it relies on DMA transactions to show graphics
on the framebuffer, so the SharedFramebufferVMObject is created with
that mindset to support the arbitrary framebuffer location in physical
memory space.
2022-06-06 20:11:05 +01:00
Liav A 3d22917548 Kernel/Memory: Introduce the SharedFramebufferVMObject class
This new type of VMObject will be used to coordinate switching safely
from graphical mode to text mode and vice-versa, by supplying a way to
remap all Regions that were created with this object, so mappings can be
changed according to the given state of system mode. This makes it quite
easy to give applications like WindowServer the feeling of having full
access to the framebuffer device from a DisplayConnector, but still keep
the Kernel in control to be able to safely switch to text console.
2022-06-06 20:11:05 +01:00