Commit Graph

2840 Commits

Author SHA1 Message Date
Sergey Bugaev
53647e347f Kernel+Base: Mount root filesystem read-only :^)
We remount /home and /root as read-write, to keep the ability to modify files
there. /tmp remains read-write, as it is mounted from a TmpFS.
2020-05-29 07:53:30 +02:00
Sergey Bugaev
fdb71cdf8f Kernel: Support read-only filesystem mounts
This adds support for MS_RDONLY, a mount flag that tells the kernel to disallow
any attempts to write to the newly mounted filesystem. As this flag is
per-mount, and different mounts of the same filesystems (such as in case of bind
mounts) can have different mutability settings, you have to go though a custody
to find out if the filesystem is mounted read-only, instead of just asking the
filesystem itself whether it's inherently read-only.

This also adds a lot of checks we were previously missing; and moves some of
them to happen after more specific checks (such as regular permission checks).

One outstanding hole in this system is sys$mprotect(PROT_WRITE), as there's no
way we can know if the original file description this region has been mounted
from had been opened through a readonly mount point. Currently, we always allow
such sys$mprotect() calls to succeed, which effectively allows anyone to
circumvent the effect of MS_RDONLY. We should solve this one way or another.
2020-05-29 07:53:30 +02:00
Sergey Bugaev
b905126365 Kernel+LibC: Move O_* and MS_* flags to UnixTypes.h
That's where the other similar definitions reside. Also, use bit shift
operations for MS_* values.
2020-05-29 07:53:30 +02:00
Sergey Bugaev
b6845de3f6 Kernel: Fix error case in Process::create_user_process()
If we fail to exec() the target executable, don't leak the thread (this actually
triggers an assertion when destructing the process), and print an error message.
2020-05-29 07:53:30 +02:00
Sergey Bugaev
6627c3ea3a Kernel: Fix some failing assertions
When mounting Ext2FS, we don't care if the file has a custody (it doesn't if
it's a device, which is a common case). When doing a bind-mount, we do need a
custody; if none is provided, let's return an error instead of crashing.
2020-05-29 07:53:30 +02:00
Sergey Bugaev
f945d7c358 Kernel: Always require read access when mmaping a file
POSIX says, "The file descriptor fildes shall have been opened with read
permission, regardless of the protection options specified."
2020-05-29 07:53:30 +02:00
Sergey Bugaev
6af2418de7 Kernel: Pass a Custody instead of Inode to VFS methods
VFS no longer deals with inodes in public API, only with custodies and file
descriptions. Talk directly to the file system if you need to operate on a
inode. In most cases you actually want to go though VFS, to get proper
permission check and other niceties. For this to work, you have to provide a
custody, which describes *how* you have opened the inode, not just what the
inode is.
2020-05-29 07:53:30 +02:00
Sergey Bugaev
a9946a99f2 Kernel: Pass a FileDescription to File::chmod() and File::chown()
We're going to make use of it in the next commit. But the idea is we want to
know how this File (more specifically, InodeFile) was opened in order to decide
how chown()/chmod() should behave, in particular whether it should be allowed or
not. Note that many other File operations, such as read(), write(), and ioctl(),
already require the caller to pass a FileDescription.
2020-05-29 07:53:30 +02:00
Sergey Bugaev
2d412c5ad1 Kernel: Report source of synthetic filesystems as "none"
As opposed to the fs name.

This matches the new convention we have for specifying it in mount(8).
2020-05-29 07:53:30 +02:00
Andreas Kling
d83d46fd7a Kernel: Remove outdated FIXME in InterruptManagement::locate_apic_data 2020-05-28 10:55:51 +02:00
etaIneLp
7bc871ca8d Kernel: Stop bootloader from setting video mode with Multiboot
Meta: Update INSTALL.md and grub configs for new boot_mode option
2020-05-28 00:50:55 +02:00
Sergey Bugaev
df128821b2 Kernel: Introduce "boot_mode" and "init" cmdline options
Together, they replace the old text_debug option.

* boot_mode should be either "graphical" (the default) or "text". We could
  potentially support other values here in the future.
* init specifies which userspace process the kernel should spawn to bootstrap
  userspace. By default, this is SystemServer, but you can specify e.g.
  init=/bin/Shell to run system diagnostics.
2020-05-27 11:19:38 +02:00
Sergey Bugaev
f11270e7ce Kernel: Port VirtualConsole to LibVT :^)
Unfortunately this drops the feature of preserving VGA buffer contents.

Resolves https://github.com/SerenityOS/serenity/issues/2399
2020-05-27 11:19:38 +02:00
Sergey Bugaev
602c3fdb3a AK: Rename FileSystemPath -> LexicalPath
And move canonicalized_path() to a static method on LexicalPath.

This is to make it clear that FileSystemPath/canonicalized_path() only
perform *lexical* canonicalization.
2020-05-26 14:35:10 +02:00
Sergey Bugaev
cddaeb43d3 Kernel: Introduce "sigaction" pledge
You now have to pledge "sigaction" to change signal handlers/dispositions. This
is to prevent malicious code from messing with assertions (and segmentation
faults), which are normally expected to instantly terminate the process but can
do other things if you change signal disposition for them.
2020-05-26 14:35:10 +02:00
Angel
6137475c39 Kernel: fix assertion on readlink() syscall
The is_error() check on the KResultOr returned when reading the link
target had a stray ! operator which causes link resolution to crash the
kernel with an assertion error.
2020-05-26 12:45:01 +02:00
Brian Gianforcaro
6a74af8063 Kernel: Plumb KResult through FileDescription::read_entire_file() implementation.
Allow file system implementation to return meaningful error codes to
callers of the FileDescription::read_entire_file(). This allows both
Process::sys$readlink() and Process::sys$module_load() to return more
detailed errors to the user.
2020-05-26 10:15:40 +02:00
Brian Gianforcaro
c459e4ecb2 Kernel: Clang format file system in prep for changes. 2020-05-26 10:15:40 +02:00
etaIneLp
82d0352a67 Kernel: Unmap first MB after jumping above 3GB 2020-05-26 09:50:12 +02:00
etaIneLp
826dc94187 Kernel: Create page structures correctly in boot.s 2020-05-26 09:50:12 +02:00
Sergey Bugaev
431bbde6df Kernel: Fix returning random children from waitid(WNOHANG)
In case WNOHANG was specified, we want to always set should_unblock to
true (which we do since commit 4402207b98), not
wait_finished -- the latter causes us to immediately return this child to our
caller, which is not what we want -- perhaps we should return another child
which has actually exited or stopped, or nobody at all.

To avoid confusion, also rename wait_finished to fits_the_spec.

This fixes service keepalive functionality in SystemServer.
2020-05-25 12:38:37 +02:00
Andreas Kling
a75c290e51 Kernel: Use TypedMapping for accessing IOAPIC registers 2020-05-23 15:57:48 +02:00
Andreas Kling
e870b936c3 Kernel: Add non-const version of TypedMapping::operator->() 2020-05-23 15:57:19 +02:00
Andreas Kling
59a56a78c0 Kernel: Oops, we need to use map_typed_writable() for write access :^) 2020-05-23 15:50:50 +02:00
Andreas Kling
a04c8d7101 Kernel: Use TypedMappings when looking for APIC information 2020-05-23 15:46:56 +02:00
Andreas Kling
dd924b730a Kernel+LibC: Fix various build issues introduced by ssize_t
Now that ssize_t is derived from size_t, we have to
2020-05-23 15:27:33 +02:00
Andreas Kling
2fe6b3725a Kernel: Use TypedMappings in the very unfinished APIC code 2020-05-23 15:25:43 +02:00
Andreas Kling
1afbd8936a Kernel+LibC: Let's say that off_t is a ssize_t 2020-05-23 15:25:43 +02:00
Andreas Kling
d63b6287f5 Kernel: Add missing casts when calling AK::min() 2020-05-23 15:25:43 +02:00
Andreas Kling
8ec8304d74 Kernel: Tweak some suspicious casts in InterruptManagement
This code needs a closer looking-into at some point. It doesn't seem
entirely safe to be casting u32's to pointers like it does.
2020-05-23 15:25:43 +02:00
Andreas Kling
7c278eb970 Kernel: Dont't static_assert that size_t is 32-bit :^) 2020-05-23 15:25:43 +02:00
Andreas Kling
b3736c1b1e Kernel: Use a FlatPtr for the "argument" to ioctl()
Since it's often used to pass pointers, it should really be a FlatPtr.
2020-05-23 15:25:43 +02:00
Andreas Kling
b8af5cd8da Kernel: Simplify MP table parser a little bit more
Get rid of the ConfigurationTableEntryLength enum and just look at the
sizeof() for each entry type.
2020-05-23 15:25:43 +02:00
Andreas Kling
7379c589c7 Kernel: Make dump_backtrace_impl() take base pointer as a FlatPtr
Since FlatPtr is register width agnostic. :^)
2020-05-23 15:25:43 +02:00
Sergey Bugaev
799f6f4ec6 Kernel: Return ESPIPE when seeking an unseekable
This is what Dr. POSIX says it should do.
2020-05-22 18:58:36 +02:00
Andreas Kling
53b859c5ad Kernel: Remove some now-unnecessary casts in ProcFS
Now that we can pass arbitrary integer types to the JSON serialization
code, we don't have to cast to u32 as much!
2020-05-22 13:59:18 +02:00
Andreas Kling
ba390f9b34 Kernel: Remove outdated FIXME's in the static ACPI parser
We no longer blindly use PAGE_SIZE here. :^)
2020-05-22 13:38:20 +02:00
Andreas Kling
4b847810bf Kernel: Simplify scanning BIOS/EBDA and MP parser initialization
Add a MappedROM::find_chunk_starting_with() helper since that's a very
common usage pattern in clients of this code.

Also convert MultiProcessorParser from a persistent singleton object
to a temporary object constructed via a failable factory function.
2020-05-22 13:36:57 +02:00
Andreas Kling
84b7bc5e14 Kernel: Add convenient ways to map whole BIOS and EBDA into memory
This patch adds a MappedROM abstraction to the Kernel VM subsystem.
It's basically the read-only byte buffer equivalent of a TypedMapping.

We use this in the ACPI and MP table parsers to scan for interesting
stuff in low memory instead of doing a bunch of address arithmetic.
2020-05-22 13:17:38 +02:00
Andreas Kling
6b5d2afd00 Kernel: Clean up and simplify MP table parsing
Use map_typed<T> to map physically addressed structs into kernel VM.
This is so much easier than doing address arithmetic everywhere. :^)
2020-05-22 12:01:01 +02:00
Yonatan Goldschmidt
3a90a01dd4 Ext2FS: Fix indirect-blocks iteration
For singly-indirect blocks, "callback" is just "add_block".
For doubly-indirect blocks, "callback" is the lambda function
iterating on singly-indirect blocks: so instead of adding itself to the
list, the doubly-indirect block will add all its childs, but they add
themselves again when they run the callback of singly-indirect blocks.
And nothing adds the doubly-indirect block itself :(

This leads to a double free of all child blocks of the doubly-indirect
block, which is the failed assert described in #1549.

Closes: #1549.
2020-05-22 10:50:41 +02:00
Andreas Kling
57b86fd082 Kernel: Fix invalid jump in case RDRAND fails
If RDRAND doesn't give us data, we want to try again, not jump to some
low address like 0x80 :^)
2020-05-20 19:54:56 +02:00
Andreas Kling
0c5e441a0b Revert "Kernel: Add implementation of operator new and delete to kmalloc.cpp"
This reverts commit 6d0d848720.
2020-05-20 16:24:26 +02:00
Andreas Kling
21c3045c47 Revert "Kernel: Don't link against libstdc++"
This reverts commit bde7bc3472.
2020-05-20 16:24:26 +02:00
Andreas Kling
250c3b363d Revert "Build: Include headers from LibC, LibM, and LibPthread with -isystem"
This reverts commit c1eb744ff0.
2020-05-20 16:24:26 +02:00
Andreas Kling
81d35c6891 Kernel: Always inline stac(), clac() and SmapDisabler
Let's not be paying the function call overhead for these tiny ops.
Maybe there's an argument for having fewer gadgets in the kernel but
for now we're actually seeing stac() in profiles so let's put
that above theoretical security issues.
2020-05-20 14:17:01 +02:00
Sergey Bugaev
746db0bedb Kernel: Validate access to whole regions 2020-05-20 14:11:13 +02:00
Sergey Bugaev
0dd68a2949 Kernel: Look for a user region first
We're far more likely to be looking for a user region than otherwise, so
optimize for that case.
2020-05-20 14:11:13 +02:00
Sergey Bugaev
d2b500fbcb AK+Kernel: Help the compiler inline a bunch of trivial methods
If these methods get inlined, the compiler is able to statically eliminate most
of the assertions. Alas, it doesn't realize this, and believes inlining them to
be too expensive. So give it a strong hint that it's not the case.

This *decreases* the kernel binary size.
2020-05-20 14:11:13 +02:00
Andrew Kaster
c1eb744ff0 Build: Include headers from LibC, LibM, and LibPthread with -isystem
Make sure that userspace is always referencing "system" headers in a way
that would build on target :). This means removing the explicit
include_directories of Libraries/LibC in favor of having it export its
headers as SYSTEM. Also remove a redundant include_directories of
Libraries in the 'serenity build' part of the build script. It's already
set at the top.

This causes issues for the Kernel, and for crt0.o. These special cases
are handled individually.
2020-05-20 08:37:50 +02:00