Commit Graph

16351 Commits

Author SHA1 Message Date
Andreas Kling
d988bd86e4 LibELF: Map text segments read-only at first
To support upcoming W^X changes in the kernel, the dynamic loader needs
to be careful about the order in which permissions are added to shared
library text segments.

We now start by mapping text segments read-only (no-write, no-exec).
If relocations are needed, we make them writable, and then finally,
for all text segments, we finish by making them read+exec.
2021-01-29 14:52:22 +01:00
Andreas Kling
3438b77aa4 LibELF: Tidy up DynamicLoader::load_program_headers() a bit
Remove a confusing temporary, rename some things and add assertions.
2021-01-29 13:45:41 +01:00
Andreas Kling
c8e7baf4b8 Kernel: Check for alignment size overflow when allocating VM ranges
Also add some sanity check assertions that we're generating and
returning ranges contained within the RangeAllocator's total range.

Fixes #5162.
2021-01-29 12:11:42 +01:00
Andreas Kling
e2abf615b7 pmap: Trim "VMObject" suffix from VMObject types to save space 2021-01-29 11:06:35 +01:00
Andreas Kling
0682a35148 SystemMonitor: Show VM region addresses as zero-padded hex ({:p})
0x1000000 and 0x10000000 looked way too similar without a leading zero.
2021-01-29 11:00:46 +01:00
Andreas Kling
3c7f5392a9 SystemMonitor: Trim "VMObject" suffix from VMObject types
Every VMObject type ends in "VMObject" and it's just taking up space.
2021-01-29 11:00:46 +01:00
Brendan Coles
ef06215e7a pmap: Add shared flag to access column and align-right numeric columns 2021-01-29 09:53:50 +01:00
Andreas Kling
a061bd2ab9 js: Handle exceptions thrown during value printing
If an exception was thrown while printing the last computed value in
the REPL, it would always assert on next input.

Something like this would always assert:

> a=[];Object.defineProperty(a,"0",{get:()=>{throw ""}})
> 1 + 2
2021-01-29 09:16:06 +01:00
Jorropo
c33d50872e
LibELF: perror on failed mmap in load_program_headers (#5159) 2021-01-29 08:50:43 +01:00
Luke
3f5532d43e LibWeb: Flesh out prepare_script and execute_script
This fills in a bunch of the FIXMEs that was in prepare_script.

execute_script is almost finished, it's just missing the module side.

As an aside, let's not assert when inserting a script element with
innerHTML.
2021-01-29 08:49:50 +01:00
Linus Groh
dbbc378fb2 Kernel: Return -ENOTBLK for non-block device Ext2FS mount source
When mounting an Ext2FS, a block device source is required. All other
filesystem types are unaffected, as most of them ignore the source file
descriptor anyway.

Fixes #5153.
2021-01-29 08:45:56 +01:00
Linus Groh
b7b09470ca Kernel: Return -ENOTDIR for non-directory mount target
The absence of this check allowed silly things like this:

    # touch file
    # mount /dev/hda file
2021-01-29 08:45:56 +01:00
Sahan Fernando
6876b9a514 Kernel: Prevent mmap-ing as both fixed and randomized 2021-01-29 07:45:00 +01:00
Jorropo
22b0ff05d4
Kernel: sys$mmap PAGE_ROUND_UP size before calling allocate_randomized (#5154)
`allocate_randomized` assert an already sanitized size but `mmap` were
just forwarding whatever the process asked so it was possible to
trigger a kernel panic from an unpriviliged process just by asking some
randomly placed memory and a size non alligned with the page size.
This fixes this issue by rounding up to the next page size before
calling `allocate_randomized`.

Fixes #5149
2021-01-28 22:36:20 +01:00
Jorropo
eafe4f942d
Ports (jq): Add .patch extension to the diff to fit the wildcard (#5148)
This fixes the build of `jq`.

`diff` were not matched by `patches/*.patch`, this seems to have gone
unnoticed in a refactor.
2021-01-28 22:20:03 +01:00
Luke
449c6c5604 LibWeb: Add simple implementation of Document.createElementNS 2021-01-28 22:18:46 +01:00
Tom
affb4ef01b Kernel: Allow specifying a physical alignment when allocating
Some drivers may require allocating contiguous physical pages with
a specific alignment for the physical address.
2021-01-28 18:52:59 +01:00
Tom
d5472426ec Kernel: Retire SchedulerData and add Thread lookup table
This allows us to get rid of the thread lists in SchedulerData.
Also, instead of iterating over all threads to find a thread by id,
just use a lookup table. In the rare case of having to iterate over
all threads, just iterate the lookup table.
2021-01-28 17:35:41 +01:00
AnotherTest
e55d227f93 AK: Provide traits for DistinctNumeric<T> 2021-01-28 17:35:41 +01:00
Andreas Kling
80837d43a2 Kernel: Remove outdated debug logging from RangeAllocator
If someone wants to debug this code, it's better that they rewrite the
logging code to take randomization and guard pages into account.
2021-01-28 16:23:38 +01:00
Andreas Kling
322c161ee4 LibELF: Implement ASLR for shared libraries :^)
Use mmap() with the new MAP_RANDOMIZED flag to load shared libraries at
random addresses in each process.

To avoid address space collisions, we start by doing a large chunk mmap
that covers enough VM for both text and data, then we unmap and remap
the data segment separately, once we know everything will fit.

This is pretty cool! :^)
2021-01-28 16:23:38 +01:00
Andreas Kling
b6937e2560 Kernel+LibC: Add MAP_RANDOMIZED flag for sys$mmap()
This can be used to request random VM placement instead of the highly
predictable regular mmap(nullptr, ...) VM allocation strategy.

It will soon be used to implement ASLR in the dynamic loader. :^)
2021-01-28 16:23:38 +01:00
Andreas Kling
d3de138d64 Kernel: Add sanity check assertion in RangeAllocator::allocate_specific
The specific virtual address should always be page aligned.
2021-01-28 16:23:38 +01:00
Andreas Kling
27d07796b4 Kernel: Add sanity check assertion in RangeAllocator::allocate_anywhere
The requested alignment should always be a multiple of the page size.
2021-01-28 16:23:38 +01:00
Linus Groh
509e5a3045 LibJS: Fix crash when printing error for missing class extends value prototype
If it's missing we get an empty value, but we can't use that with
to_string_without_side_effects() so we have to use undefined as the
default.

Fixes #5142.
2021-01-28 10:24:18 +01:00
Andreas Kling
803a20fa86 LibJS: Call the correct base class in LexicalEnvironment::visit_edges()
We were calling directly up to Cell, skipping over ScopeObject.
This made us not mark the scope chain parent for lexical environments,
sometimes causing them to get GC'd and use-after-free'd.

Found by Fuzzilli.

Fixes #5140.
2021-01-28 10:15:24 +01:00
Andreas Kling
7ec8f83a7f Lagom+AK: Remove remains of clang -Wconsumed usage
We stopped using that warning ages ago since it confused the compiler.
2021-01-28 09:14:49 +01:00
Andreas Kling
a0bcfa30bf LibWeb: Add simple implementation of Node.removeChild() 2021-01-28 08:58:22 +01:00
Andreas Kling
5a58f42e3c LibWeb: Remove accidentally committed changes from b72f067f0d 2021-01-28 08:57:12 +01:00
Andreas Kling
5ff355c0cd Kernel: Generate coredump backtraces from "threads for coredump" list
This broke with the change that gave each process a list of its own
threads. Since threads are removed slightly earlier from that list
during process teardown, we're not able to use it for generating
coredump backtraces. Fortunately we have the "threads for coredump"
list for just this purpose. :^)
2021-01-28 08:41:18 +01:00
Andreas Kling
b72f067f0d Kernel+Userland: Remove unused "effective priority" from threads
This has been merged with the regular Thread::priority field after
the recent changes to the scheduler.
2021-01-28 08:25:53 +01:00
Zac
aaf691c4ef Vim: Add change word and delete word functionality
Add the functionality of key sequences 'cw', 'ce', 'cb', 'dw', 'de' and 'db'.
2021-01-28 08:17:02 +01:00
Tom
e2d7945e0c Kernel: Make KernelRng thread-safe
This adds an optional argument to get_good_random_bytes that can be
used to only return randomness if it doesn't have to block.
Also add a SpinLock around using FortunaPRNG.

Fixes #5132
2021-01-28 08:15:26 +01:00
Tom
8104abf640 Kernel: Remove colonel special-case from Process::for_each_thread
Since each Process now has its own list of threads, we don't need
to treat colonel any different anymore. This also means that it
reports all kernel threads, not just the idle threads.
2021-01-28 08:14:12 +01:00
Peter Elliott
985ce3b701 BXVGADevice+MBVGADevice: Correctly check page-aligned mmaps
In ab14b0ac64, mmap was changed so that
the size of the region is aligned before it was passed to the device
driver. The previous logic would assert when the framebuffer size was
not a multiple of the page size. I've also taken the liberty of
returning an error on mmap failure rather than asserting.
2021-01-28 08:14:04 +01:00
Andreas Kling
f2decb6665 Revert "Kernel: Fix Thread::relock_process leaving critical section"
This reverts commit e9e76b8074.

This was causing a noticeable slowdown, and we're not sure that it was
actually necessary.
2021-01-27 23:23:21 +01:00
Tom
db1448b21a Kernel: Add a compile-time switch to enable scheduling on all CPUs
This is meant to be temporary only and should be removed once scheduling
on all CPUs is stable.
2021-01-27 22:48:41 +01:00
Tom
e9e76b8074 Kernel: Fix Thread::relock_process leaving critical section
We don't want to explicitly enable interrupts when leaving the
critical section to trigger a context switch.
2021-01-27 22:48:41 +01:00
Tom
ccaeb47401 Kernel: Don't hold scheduler lock while setting up blocker in Thread::block
This fixes a deadlock when one processor is trying to block while another is
trying to unblock the same.
2021-01-27 22:48:41 +01:00
Tom
250a310454 Kernel: Release MM lock while yielding from inode page fault handler
We need to make sure other processors can grab the MM lock while we
wait, so release it when we might block. Reading the page from
disk may also block, so release it during that time as well.
2021-01-27 22:48:41 +01:00
Tom
ac3927086f Kernel: Keep a list of threads per Process
This allow us to iterate only the threads of the process.
2021-01-27 22:48:41 +01:00
Tom
03a9ee79fa Kernel: Implement thread priority queues
Rather than walking all Thread instances and putting them into
a vector to be sorted by priority, queue them into priority sorted
linked lists as soon as they become ready to be executed.
2021-01-27 22:48:41 +01:00
Tom
c531084873 Kernel: Track processor idle state and wake processors when waking threads
Attempt to wake idle processors to get threads to be scheduled more quickly.
We don't want to wait until the next timer tick if we have processors that
aren't doing anything.
2021-01-27 22:48:41 +01:00
Tom
39f408daa0 Kernel: Use the CPU# as logical apic id 2021-01-27 22:48:41 +01:00
Tom
95bfc12ff4 AK: Include the processor id in log messages 2021-01-27 22:48:41 +01:00
Andreas Kling
e67402c702 Kernel: Remove Range "valid" state and use Optional<Range> instead
It's easier to understand VM ranges if they are always valid. We can
simply use an empty Optional<Range> to encode absence when needed.
2021-01-27 21:14:42 +01:00
Andreas Kling
67bc5e0bbd DynamicLoader: Pass MAP_FIXED to mmap() where applicable
Otherwise the kernel is free to allocate a different address.
2021-01-27 21:14:42 +01:00
Andreas Kling
5ab27e4bdc Kernel: sys$mmap() without MAP_FIXED should consider address a hint
If we can't use that specific address, it's still okay to put it
anywhere else in VM.
2021-01-27 21:14:42 +01:00
Tom
e2f9e557d3 Kernel: Make Processor::id a static function
This eliminates the window between calling Processor::current and
the member function where a thread could be moved to another
processor. This is generally not as big of a concern as with
Processor::current_thread, but also slightly more light weight.
2021-01-27 21:12:24 +01:00
Tom
21d288a10e Kernel: Make Thread::current smp-safe
Change Thread::current to be a static function and read using the fs
register, which eliminates a window between Processor::current()
returning and calling a function on it, which can trigger preemption
and a move to a different processor, which then causes operating
on the wrong object.
2021-01-27 21:12:24 +01:00