Commit graph

24473 commits

Author SHA1 Message Date
Brian Gianforcaro
c2282ee28d Tests: Add test coverage for sys$pledge(..) argument validation 2021-07-23 19:02:25 +02:00
Brian Gianforcaro
e4b86aa5d8 Kernel: Fix bug where we half apply pledges in sys$pledge(..)
This bug manifests it self when the caller to sys$pledge() passes valid
promises, but invalid execpromises. The code would apply the promises
and then return an error for the execpromises. This leaves the user in
a confusing state, as the promises were silently applied, but we return
an error suggesting the operation has failed.

Avoid this situation by tweaking the implementation to only apply the
promises / execpromises after all validation has occurred.
2021-07-23 19:02:25 +02:00
Brian Gianforcaro
36ff717c54 Kernel: Migrate sys$pledge to use the KString API
This avoids potential unhandled OOM that's possible with the old
copy_string_from_user API.
2021-07-23 19:02:25 +02:00
Brian Gianforcaro
8acbe03342 Kernel: Annotate kernel_base and friends as READONLY_AFTER_INIT
We don't want kernel_base to be modifiable by an attacker or a stray
memory scribbler bug, so lets mark it as READONLY_AFTER_INIT.
2021-07-23 19:02:25 +02:00
Brian Gianforcaro
fa448456a9 Tests: Add test coverage for sys$unveil(..) argument validation 2021-07-23 19:02:25 +02:00
Brian Gianforcaro
baec9e2d2d Kernel: Migrate sys$unveil to use the KString API
This avoids potential unhandled OOM that's possible with the old
copy_string_from_user API.
2021-07-23 19:02:25 +02:00
Brian Gianforcaro
2e7728bb05 Kernel: Use StringView literals for fs_type match in sys$mount(..) 2021-07-23 19:02:25 +02:00
Brian Gianforcaro
a3787b9db7 Kernel: Remove another ARCH ifdef using RegisterState::flags() 2021-07-23 19:02:25 +02:00
Itamar
8241a6c8eb TextEditor: Allow starting with a file argument that doesn't exist
If TextEditor is started with an argument for a file that doesn't
exist, we now allow editing it.

The file will be created once it is saved.
2021-07-23 21:19:30 +04:30
Ali Mohammad Pur
36bfc912fc LibRegex: Switch to east-const style 2021-07-23 21:19:21 +04:30
Ali Mohammad Pur
c8b2199251 LibRegex: Clear previous capture group contents in ECMA262 mode
ECMA262 requires that the capture groups only contain the values from
the last iteration, e.g. `((c)(a)?(b))` should _not_ contain 'a' in the
second capture group when matching "cabcb".
2021-07-23 21:19:21 +04:30
Idan Horowitz
34ec0fa8ad CI: Skip commit linter line length check on lines that contain URLs 2021-07-23 20:27:12 +04:30
Ali Mohammad Pur
7b88857c5a LibWeb: Manually convert the js bigint to a wasm i64 value
SignedBigInteger::export() generates sign-magnitude, but the native i64
type uses 2's comp, make this work by exporting it as unsigned and
tweaking the sign later.
2021-07-23 17:36:15 +04:30
Ali Mohammad Pur
03629a2b3c LibWeb: Read the correct types in WebAssembly's to_js_value()
A wasm value containing an F64 does not contain a float, etc.
2021-07-23 17:36:15 +04:30
Andreas Kling
13a2e91fc5 Kernel: No need to use safe_memcpy() when handling an inode fault
We're copying the inode contents from a stack buffer into a page that
we just quick-mapped, so there's no reason for this memcpy() to fail.
2021-07-23 14:19:47 +02:00
stelar7
8264511d32 LibWeb: Dont try to parse "data" urls as links 2021-07-23 14:18:17 +02:00
Brian Gianforcaro
204d5ff8f8 Kernel: Reduce useful ROP gadgets by zeroing used function registers
GCC-11 added a new option `-fzero-call-used-regs` which causes the
compiler to zero function arguments before return of a function. The
goal being to reduce the possible attack surface by disarming ROP
gadgets that might be potentially useful to attackers, and reducing
the risk of information leaks via stale register data. You can find
the GCC commit below[0].

This is a mitigation I noticed on the Linux KSPP issue tracker[1] and
thought it would be useful mitigation for the SerenityOS Kernel.

The reduction in ROP gadgets is observable using the ropgadget utility:

    $ ROPgadget --nosys --nojop --binary Kernel | tail -n1
    Unique gadgets found: 42754

    $ ROPgadget --nosys --nojop --binary Kernel.RegZeroing | tail -n1
    Unique gadgets found: 41238

The size difference for the i686 Kernel binary is negligible:

    $ size Kernel Kernel.RegZerogin
        text    data     bss     dec      hex filename
    13253648 7729637 6302360 27285645 1a0588d Kernel
    13277504 7729637 6302360 27309501 1a0b5bd Kernel.RegZeroing

We don't have any great workloads to measure regressions in Kernel
performance, but Kees Cook mentioned he measured only around %1
performance regression with this enabled on his Linux kernel build.[2]

References:
[0] d10f3e900b
[1] https://github.com/KSPP/linux/issues/84
[2] https://lore.kernel.org/lkml/20210714220129.844345-1-keescook@chromium.org/
2021-07-23 14:18:04 +02:00
davidot
4ef9edbff7 LibWeb: Fix that empty event handlers return null instead of crashing 2021-07-23 14:15:28 +02:00
Linus Groh
080112eb82 LibJS: Implement Temporal.PlainDateTime.prototype.getISOFields() 2021-07-23 08:18:11 +01:00
Linus Groh
18fd0d4011 LibJS: Implement Temporal.PlainDateTime.prototype.toPlainDate() 2021-07-23 08:18:11 +01:00
Linus Groh
61b2780853 LibJS: Fix return type of PlainDateTime::iso_{milli,micro,nano}second() 2021-07-23 08:18:11 +01:00
Andreas Kling
082ed6f417 Kernel: Simplify VMObject locking & page fault handlers
This patch greatly simplifies VMObject locking by doing two things:

1. Giving VMObject an IntrusiveList of all its mapping Region objects.
2. Removing VMObject::m_paging_lock in favor of VMObject::m_lock

Before (1), VMObject::for_each_region() was forced to acquire the
global MM lock (since it worked by walking MemoryManager's list of
all regions and checking for regions that pointed to itself.)

With each VMObject having its own list of Regions, VMObject's own
m_lock is all we need.

Before (2), page fault handlers used a separate mutex for preventing
overlapping work. This design required multiple temporary unlocks
and was generally extremely hard to reason about.

Instead, page fault handlers now use VMObject's own m_lock as well.
2021-07-23 03:24:44 +02:00
Andreas Kling
64babcaa83 Kernel: Remove unused MAP_SHARED_ZERO_PAGE_LAZILY code path 2021-07-23 03:24:44 +02:00
Gunnar Beutner
59007bba84 Hearts: Avoid redrawing the UI unnecessarily 2021-07-23 02:34:59 +02:00
Andreas Kling
3f9e018d9a CrashDaemon: Remove BACKTRACE_DEBUG debugging code
This thing seems to work fine, no need to hang on to old debug code.
2021-07-22 23:34:33 +02:00
Andreas Kling
cdae397e6a DynamicLoader: Don't truncate dynamic section address on x86_64 2021-07-22 23:34:33 +02:00
Andreas Kling
e44a41d0bf Kernel: Convert Region to east-const style 2021-07-22 23:34:33 +02:00
Peter Elliott
bf16591c07 Assistant: Only open one Assistant at once
I found myself accidentally opening two assistants at once with the
Window+Space shortcut. Since only one assistant window is usable at the
same time, I made assistant only spawn 1 instance at most.
2021-07-22 23:34:15 +02:00
Peter Elliott
fdcfd2816e LibCore: Add LockFile, a filesystem based mutex
This API wraps flock(2) and also handles the file creation and deletion
when the LockFile goes out of scope.
2021-07-22 23:34:15 +02:00
Hendiadyoin1
7da12f0faf UserspaceEmulator: Move to using the new SoftFPU 2021-07-22 23:33:21 +02:00
Hendiadyoin1
45d0f84a27 UserspaceEmulator: Implement SoftFPU instructions
This implements almost all instructions related to the FPU, including
all MMX instructions as well.
A lot of these were copied and adjusted from the SoftCPU implementation.

The next big milestone would be QNan detection and ShadowValue handling.
2021-07-22 23:33:21 +02:00
Hendiadyoin1
09a1a0b319 UserspaceEmulator: Sketch out a SoftFPU interface 2021-07-22 23:33:21 +02:00
Hendiadyoin1
1d74742c29 AK: Add char SIMD types
These are used in intrinsics, which do not recognize any signed version
of the char type
2021-07-22 23:33:21 +02:00
Hendiadyoin1
eb6af29421 LibX86: Add missing MovD and MovQ instructions
These are placeholders for now
2021-07-22 23:33:21 +02:00
Hendiadyoin1
efa42c4d45 LibX86: Use names closer to the spec for the Modrm
This gets rid of a lot of magic number shifts and ands.
2021-07-22 23:33:21 +02:00
Sam Atkins
68193c365f LibWeb: Resolve CSS text-decoration from value list
This detects and resolves these in the text-decoration property, in any
order:

- text-decoration-color
- text-decoration-line
- text-decoration-style

Only the solid underline renders, but all three sub-properties are
assigned correctly.
2021-07-22 23:09:01 +02:00
Sam Atkins
29b61123a4 LibWeb: Resolve background properties from ValueListStyleValue
As before, there are several sub-properties that we do not support, and
we ignore anything after the first comma.
2021-07-22 23:09:01 +02:00
Sam Atkins
6e08b200d4 LibWeb: Implement ImageStyleValue parsing
Later we will want to make a distinction between URL and Image values,
but this works for now.
2021-07-22 23:09:01 +02:00
Sam Atkins
82f3228dd2 LibWeb: Resolve CSS font property from value list
The font property now resolves into its various parts:

- font-family
- font-weight
- font-size
- font-style
- line-height

The font-variant and font-stretch parts are left unparsed since LibWeb
doesn't know how to render those.

Added `fonts.html` as a test for various forms of `font` declarations,
based on the examples in the spec.
2021-07-22 23:09:01 +02:00
Sam Atkins
a44d7670ab LibWeb: Resolve CSS list-style from value list
This resolves the three sub-properties, appearing in any order:

- list-style-image
- list-style-position
- list-style-type

Added `list-style-position` values to support this, though they are not
yet used in rendering.
2021-07-22 23:09:01 +02:00
Sam Atkins
b693a22c2d LibWeb: Resolve CSS flex/flex-flow from value list
Also moved the 'flex' code in StyleResolver to be next to
the 'flex-flow' code, because that seemed more reasonable.
2021-07-22 23:09:01 +02:00
Sam Atkins
7abfb18656 LibWeb: Implement CSS color parsing from Tokens
This was broken when we switched away from using StringStyleValues.
While I was at it, I have implemented hsl/a() and the percentage
syntax for rgb/a().

As a bonus, added `colors.html` as a test page for the various CSS
color syntaxes, since nothing was testing rgb() or rgba() before.

Much of the parsing code in LibGFX/Color.h seems to be centered
around CSS color values, but this is not used by the new Parser.
(And can't be used, because it requires a String value and we have
a list of Tokens of some kind instead.) Maybe that should be removed
from there when the new CSS parser is operational.
2021-07-22 23:09:01 +02:00
Sam Atkins
fabbd06de4 LibGfx: Implement Color::from_hsl/hsla()
This is required by CSS, and implemented based on the CSS standard's
algorithm.
2021-07-22 23:09:01 +02:00
Sam Atkins
4853c89c42 LibWeb: Handle ValueListStyleValues in StyleResolver
This implements a lot of cases, but not all of them. The following
need more infrastructure first:

- Flex
- FlexFlow
- Background
- BackgroundImage
- BackgroundRepeat
- ListStyle and parts
- Font

Also, colors are not parsed correctly. This will be handled next.
2021-07-22 23:09:01 +02:00
Sam Atkins
6e0376361a LibWeb: Expose StyleValue parsing method in CSS Parser
Now that StyleResolver is going to deal with StyleComponentValueRules,
it will need to be able to parse those into StyleValues, using
`parse_css_value()`.

Also added StyleValue::is_builtin_or_dynamic(), which returns true for
values that are valid anywhere - things like `initial` and `inherit`,
along with `var()`, `attr()` and `calc()` - which we want to test for
easily.
2021-07-22 23:09:01 +02:00
Sam Atkins
57d34f1966 LibWeb: Convert StyleResolver.{h,cpp} to east const 2021-07-22 23:09:01 +02:00
Sam Atkins
d72ce7b989 LibWeb: Generate a ValueListStyleValue when parsing CSS values
We skip whitespace tokens while doing this. As far as I can tell,
whitespace is not useful once we get to this point, and it legally
may or may not appear between any two tokens. By not including it
in the ValueListStyleValue, we make the "if it has 3 parts"-type
checks a lot more straightforward.
2021-07-22 23:09:01 +02:00
Sam Atkins
4a03279539 LibWeb: Add CSS ValueListStyleValue
As the new CSS parser tokenizes its input, we can no longer easily
rely on a StringStyleValue for multi-value properties. (eg, border)
ValueListStyleValue lets us wrap all of the ComponentValues that
the Parser produced for one declaration, as a single StyleValue, to
then be parsed into StyleValues by the StyleResolver.

Originally, I wanted it to be a list of StyleValues, but several
properties use syntax that makes use of non-StyleValue tokens, eg:
```css
/* Syntax using a / */
font: 12px/14px sans-serif;
/* Multiple values separated by commas */
background: url(catdog.png), url(another-image.jpg), blue;
```
Passing the ComponentValue tokens themselves means that all that
information is carried over. The alternative might be to create a
StyleValue subclass for each property and parse them fully inside
the Parser. (eg, `FontStyleValue`)

I decided against `ListStyleValue` as a name, to avoid confusion
with list styles. It's not ideal, but names are hard.
2021-07-22 23:09:01 +02:00
Karol Kosek
8c2be4b3dc LibAudio: Implement loaded_samples() in the FLAC Loader
This makes aplay show current playback position.
2021-07-22 22:57:05 +02:00
Karol Kosek
01e1e2c2c5 LibAudio: Read custom block sizes and sample rates as big endian
This fixes stucking in a loop at the end of the file, as
(a) custom block sizes are usually placed there, as the remaining
size might not be simply calculated as a power of two, and
(b) the number of bytes to read was incorrect (the program said
the block size was 32525, where flac -a said it's actually 3200).

Unfortunately, I couldn't trigger the bug for the sample rates,
so it may be not true, but I'd doubt it, giving the fact that flac
almost everywhere uses big endian numbers.
2021-07-22 22:57:05 +02:00