Commit Graph

16332 Commits

Author SHA1 Message Date
Andreas Kling
123c37e1c0 Kernel: Fix mix-up between MAP_STACK/MAP_ANONYMOUS in prot validation 2021-01-30 10:30:17 +01:00
Andreas Kling
e55ef70e5e Kernel: Remove "has made executable exception for dynamic loader" flag
As Idan pointed out, this flag is actually not needed, since we don't
allow transitioning from previously-executable to writable anyway.
2021-01-30 10:06:52 +01:00
Andreas Kling
5b37c0a71a LibC: Convert remaining String::format() to formatted()/number() 2021-01-30 09:29:51 +01:00
Ben Wiederhake
ec91f8ad1d LibELF: Avoid quadratic memory usage weakness
Section names are referred to by offset and length. We do not check
(and probably should not check) whether these names overlap in any way.
This opened the door to many sections (in this example: about 2700)
forcing ELF::Image::m_sections to contain endless copies of the same
huge string (in this case: 882K).

Fix this by loading only the first PAGE_SIZE bytes of each name.
Since section names are only relevant for relocations and debug
information and most section names are hard-coded (and far below 4096
bytes) anyway, this should be no restriction at all for 'normal'
executables.

Found by OSS-Fuzz:
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=29187
2021-01-30 09:25:02 +01:00
Ben Wiederhake
4332dfb964 LibGfx: Fix dynamic bitmasks in BMPs
I overlooked a corner case where we might call the built-in ctz() on zero.

Furthermore, the calculation of the shift was wrong and the results were often
unusable.

Both issue were caused by a forgotten 36daeee34f.
This time I made sure to look at bmpsuite_files first, and now they look good.

Found by OSS-Fuzz:
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=28985
2021-01-30 09:23:18 +01:00
Ben Wiederhake
648f153951 Lagom/Fuzzers: Recommend enabling UBSan, extend instructions 2021-01-30 09:23:18 +01:00
Ben Wiederhake
1cbc01e288 Lagom: Don't include Shell/main.cpp
This caused some confusion: Apparently, clang has no trouble overriding Shell's
main, and this issue only surfaced when I tried to build the fuzzers with
wrong configuration (i.e., without the clang-injected 'main').

The diff is suggested by, and work of, @alimpfard.
2021-01-30 09:23:18 +01:00
Jorropo
8f8bbd1bcd
DynamicLoader: load_program_headers use variables to store regions (#5173)
Previously regions were stored in a vector and then a pointer to
regions in this vector were taken and stored. The problem is the vector
were still appended after pointers were taken, if enough regions were
present the vector would grow so large that it needed a resize, this
cause his memory to moved and now the previous pointers are now
pointing to old memory we just freed.

Fixes #5160
2021-01-30 09:21:54 +01:00
Linus Groh
a3da5bc925 Meta: Expect sync-local.sh script at repository root
This used to be in Kernel/, next to the build-root-filesystem.sh script,
which was then moved to Meta/ during the transition to CMake but has the
working directory set to Build/, effectively expecting it there - which
seems silly.

TL;DR: Very confusing. Use an explicit path relative to SERENITY_ROOT
instead and update the .gitignore files.
2021-01-30 09:18:46 +01:00
Linus Groh
c7ca0a5fef Base: Add missing "ß" to DE keymap 2021-01-29 23:21:07 +01:00
Linus Groh
8fa8dda97c Base: Add missing umlauts to DE keymap 2021-01-29 23:21:07 +01:00
Linus Groh
b1b015c052 Base: Fix missing "£" in GB keymap
Shift+3 is "£", not "#".
2021-01-29 23:21:07 +01:00
Linus Groh
f70a364a83 Base: Reformat some keymaps
This is in line with all the other ones, and makes finding the same keys
in each map array a little easier.
2021-01-29 23:21:07 +01:00
Andreas Kling
4ab2ff95ce ls: Lazily align the number of hard links in ls output :^)
Fixes #5155
2021-01-29 23:05:02 +01:00
Ben Wiederhake
0558c74e30 WindowServer: Constrain geometry label on move/resize to desktop
Fixes #5063.
2021-01-29 22:49:12 +01:00
Ben Wiederhake
cf586311a6 WindowServer: Split double-duty Window::normalize_rect()
This commit:
- merges the two(!) places that defined independently the minimum size of a window.
- splits Window::normalize_rect(), which was originally just a function to apply
  the minimum size requirement, and has taken on the additional job of nudging
  windows back onto the desktop.

This inadvertantly fixes a crash that happens when a malicious program creates a
window of size (0, 0). Now, a window at [0,0 50x50] is created instead.
2021-01-29 22:49:12 +01:00
Ben Wiederhake
79f534ef12 WindowServer: Allow superdrags to hide the titlebar
Fixes #5105.
2021-01-29 22:49:12 +01:00
Ben Wiederhake
e200824125 WindowServer: Count titlebar towards visible/grabbable area
This had lead to some surprising asymmetry at the bottom of the screen.
2021-01-29 22:49:12 +01:00
Ben Wiederhake
3fd5aec187 WindowServer: Properly determine where a window may be
This also fixes weird behavior of WindowManager::desktop_rect().
None of the callers seem to ever expect an empty Rect, so return a non-empty Rect.
2021-01-29 22:49:12 +01:00
Linus Groh
af605afb27 Ports: Update neofetch to 7.1.0 2021-01-29 22:48:58 +01:00
Linus Groh
34902f18ce Ports: Revert neofetch shebang patch change
Looks like this was a search & replace from 0bf5669, but it doesn't
actually work in Serenity.
2021-01-29 22:48:58 +01:00
Andreas Kling
7449c1b27f ImageDecoder+LibImageDecoder+LibWeb: Support animations in ImageDecoder
The ImageDecoder service now returns a list of image frames, each with
a duration value.

The code for in-process image decoding is removed from LibWeb, an all
image decode requests are sent out-of-process to ImageDecoder. :^)

This won't scale super well to very long and/or large animations, but
we can work on improving that separately. The main goal here is simply
to stop doing any image decoding inside LibWeb.

Fixes #5165.
2021-01-29 22:38:22 +01:00
Andreas Kling
449d56ef74 LibGfx: Don't use Gfx::Painter in GIF decoder
Painter currently tries to load fonts, which won't work if we're in a
tightly pledged process.

It was only used to fill a rect with transparent pixels, so just do
that manually instead.
2021-01-29 22:30:12 +01:00
Andreas Kling
a8c823f242 Kernel: Bump the number of fd's that can be queued on a local socket 2021-01-29 22:11:59 +01:00
Andreas Kling
0324144e2a LibWeb: Update the ICB's idea of the viewport rect after Frame resize
This makes animations start if they are uncovered by a resize.
2021-01-29 22:03:04 +01:00
Luke
40de84ba67 Kernel/Storage: Rewrite IDE disk detection and disk access
This replaces the current disk detection and disk access code with
code based on https://wiki.osdev.org/IDE

This allows the system to boot on VirtualBox with serial debugging
enabled and VMWare Player.

I believe there were several issues with the current code:
- It didn't utilise the last 8 bits of the LBA in 24-bit mode.
- {read,write}_sectors_with_dma was not setting the obsolete bits,
  which according to OSdev wiki aren't used but should be set.
- The PIO and DMA methods were using slightly different copy
  and pasted access code, which is now put into a single
  function called "ata_access"
- PIO mode doesn't work. This doesn't fix that and should
  be looked into in the future.
- The detection code was not checking for ATA/ATAPI.
- The detection code accidentally had cyls/heads/spt as 8-bit,
  when they're 16-bit.
- The capabilities of the device were not considered. This is now
  brought in and is currently used to check if the device supports
  LBA. If not, use CHS.
2021-01-29 21:20:38 +01:00
Linus Groh
f9b1a9e60c LibJS: Let RegExp.string get RegExp.prototype from the global object directly
We can't assume that RegExp on the global object is still the original
constructor, or an object at all.

This makes '--RegExp<</<</</,/</x/' work. :^)

Found by OSS-Fuzz:
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=29740
2021-01-29 20:50:22 +01:00
Andreas Kling
d0c5979d96 Kernel: Add "prot_exec" pledge promise and require it for PROT_EXEC
This prevents sys$mmap() and sys$mprotect() from creating executable
memory mappings in pledged programs that don't have this promise.

Note that the dynamic loader runs before pledging happens, so it's
unaffected by this.
2021-01-29 18:56:34 +01:00
Jorropo
df30b3e54c
Kernel: RangeAllocator randomized correctly check if size is in bound. (#5164)
The random address proposals were not checked with the size so it was
increasely likely to try to allocate outside of available space with
larger and larger sizes.

Now they will be ignored instead of triggering a Kernel assertion
failure.

This is a continuation of: c8e7baf4b8
2021-01-29 17:18:23 +01:00
Andreas Kling
51df44534b Kernel: Disallow mapping anonymous memory as executable
This adds another layer of defense against introducing new code into a
running process. The only permitted way of doing so is by mmapping an
open file with PROT_READ | PROT_EXEC.

This does make any future JIT implementations slightly more complicated
but I think it's a worthwhile trade-off at this point. :^)
2021-01-29 14:52:34 +01:00
Andreas Kling
af3d3c5c4a Kernel: Enforce W^X more strictly (like PaX MPROTECT)
This patch adds enforcement of two new rules:

- Memory that was previously writable cannot become executable
- Memory that was previously executable cannot become writable

Unfortunately we have to make an exception for text relocations in the
dynamic loader. Since those necessitate writing into a private copy
of library code, we allow programs to transition from RW to RX under
very specific conditions. See the implementation of sys$mprotect()'s
should_make_executable_exception_for_dynamic_loader() for details.
2021-01-29 14:52:27 +01:00
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