Commit graph

1131 commits

Author SHA1 Message Date
MacDue d951e2ca97 Kernel: Add /proc/{pid}/children to ProcFS
This exposes the child processes for a process as a directory
of symlinks to the respective /proc entries for each child.

This makes for an easier and possibly more efficient way
to find and count a process's children. Previously the only
method was to parse the entire /proc/all JSON file.
2022-05-06 02:12:51 +04:30
Andrew Kaster f08e91f67e Kernel: Don't check pledges or veil against code coverage data files
Coverage tools like LLVM's source-based coverage or GNU's --coverage
need to be able to write out coverage files from any binary, regardless
of its security posture. Not ignoring these pledges and veils means we
can't get our coverage data out without playing some serious tricks.

However this is pretty terrible for normal exeuction, so only skip these
checks when we explicitly configured userspace for coverage.
2022-05-02 01:46:18 +02:00
kleines Filmröllchen b0a2572577 Kernel: Don't require AnonymousFiles to be mmap'd completely
AnonymousFile always allocates in multiples of a page size when created
with anon_create. This is especially an issue if we use AnonymousFile
shared memory to store a shared data structure that isn't exactly a
multiple of a page in size. Therefore, we can just allow mmaps of
AnonymousFile to map only an initial part of the shared memory.

This makes SharedSingleProducerCircularQueue work when it's introduced
later.
2022-04-21 13:55:00 +02:00
Idan Horowitz 086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Liav A ae2ec45e78 Kernel: Allow SysFS components to have non-zero size
This is important for dmidecode because it does an fstat on the DMI
blobs, trying to figure out their size. Because we already know the size
of the blobs when creating the SysFS components, there's no performance
penalty whatsoever, and this allows dmidecode to not use the /dev/mem
device as a fallback.
2022-04-01 11:27:19 +02:00
Liav A b5ef900ccd Kernel: Don't assume paths of TTYs and pseudo terminals anymore
The obsolete ttyname and ptsname syscalls are removed.
LibC doesn't rely on these anymore, and it helps simplifying the Kernel
in many places, so it's an overall an improvement.

In addition to that, /proc/PID/tty node is removed too as it is not
needed anymore by userspace to get the attached TTY of a process, as
/dev/tty (which is already a character device) represents that as well.
2022-03-22 20:26:05 +01:00
Lenny Maiorani 190cf1507b Kernel: Use default constructors/destructors
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules

"The compiler is more likely to get the default semantics right and
you cannot implement these functions better than the compiler."
2022-03-17 00:51:36 -07:00
Andreas Kling 580d89f093 Kernel: Put Process unveil state in a SpinlockProtected container
This makes path resolution safe to perform without holding the big lock.
2022-03-08 00:19:49 +01:00
Idan Horowitz feb00b7105 Everywhere: Make JSON serialization fallible
This allows us to eliminate a major source of infallible allocation in
the Kernel, as well as lay down the groundwork for OOM fallibility in
userland.
2022-02-27 20:37:57 +01:00
Idan Horowitz 316fa0c3f3 AK+Kernel: Specialize Trie for NNOP<KString> and use it in UnveilNode
This let's us avoid the infallible String allocations.
2022-02-16 22:21:37 +01:00
Ali Mohammad Pur a1cb2c371a AK+Kernel: OOM-harden most parts of Trie
The only part of Unveil that can't handle OOM gracefully is the
String::formatted() use in the node metadata.
2022-02-15 18:03:02 +02:00
Liav A e23dda81de Kernel: Honor permission mode when creating new directories in DevTmpFS 2022-02-14 08:45:32 -05:00
Idan Horowitz e37e4a7980 Kernel: Make Inode::set_shared_vmobject() OOM-fallible
Allocating a WeakPtr can fail, so this let's us properly propagate said
failure.
2022-02-14 11:35:20 +01:00
Idan Horowitz c8ab7bde3b Kernel: Use try_make_weak_ptr() instead of make_weak_ptr() 2022-02-13 23:02:57 +01:00
Max Wipfli b0df096298 Kernel/VFS: Add FIXMEs about error codes leaking data from veiled paths
Error codes can leak information about veiled paths, if the path
resolution fails with e.g. EACCESS.

This is non-trivial to fix, as there is a group of error codes we want
to propagate to the caller, such as ENOMEM.
2022-02-13 21:58:26 +02:00
Max Wipfli e8f491b01d Kernel/VFS: Validate paths against process veil in mkdir()
VirtualFileSystem::mkdir() relies on resolve_path() returning an error,
since it is only interested in the out_parent passed as a pointer. Since
resolve_path_without_veil returns an error, no process veil validation
is done by resolve_path() in that case. Due to this problem, mkdir()
should use resolve_path_without_veil() and then manually validate if the
parent directory of the to-be-created directory is unveiled with 'c'
permissions.

This fixes a bug where the mkdir syscall would not respect the process
veil at all.
2022-02-13 21:58:26 +02:00
Max Wipfli 8c7010f282 Kernel/VFS: Clear out_parent if path is veiled
Previously, VirtualFileSystem::resolve_path() could return a non-null
RefPtr<Custody>* out_parent even if the function errored because the
path has been veiled.

If code relies on recieving the parent custody even if the path is
veiled, it should just call resolve_path_without_veil and do the veil
validation manually. This is because it could be that the parent is
unveiled but the child isn't or the other way round.
2022-02-13 21:58:26 +02:00
Andreas Kling cda56f8049 Kernel: Robustify and rename Inode bound socket API
Rename the bound socket accessor from socket() to bound_socket().
Also return RefPtr<LocalSocket> instead of a raw pointer, to make it
harder for callers to mess up.
2022-02-07 13:02:34 +01:00
Andreas Kling 34f6c88ffd Revert "Kernel: Protect InodeWatcher internals with spinlock instead of mutex"
This reverts commit 0bebf013e3.

This caused a deadlock when handling a crashed process, so let's revert
it until we can figure out what went wrong.
2022-02-03 18:25:55 +01:00
Andreas Kling e7dc9f71b8 Kernel: Protect Inode flock list with spinlock instead of mutex 2022-02-03 17:28:45 +01:00
Andreas Kling 0bebf013e3 Kernel: Protect InodeWatcher internals with spinlock instead of mutex 2022-02-03 16:11:26 +01:00
Andreas Kling e0d9472ced Kernel: Protect Inode's list of watchers with spinlock instead of mutex 2022-02-03 16:11:26 +01:00
Andreas Kling 210689281f Kernel: Protect mounted filesystem list with spinlock instead of mutex 2022-02-03 16:11:26 +01:00
Andreas Kling 248832f438 Kernel: Convert OpenFileDescriptor from mutex to spinlock
A mutex is useful when we need to be able to block the current thread
until it's available. This is overkill for OpenFileDescriptor.

First off, this patch wraps the main state member variables inside a
SpinlockProtected<State> to enforce synchronized access. This also
avoids "free locking" where figuring out which variables are guarded
by which lock is left as an unamusing exercise for the reader.

Then we remove mutex locking from the functions that simply call through
to the underlying File or Inode, since those fields never change anyway,
and the target objects perform their own synchronization.
2022-02-03 16:11:26 +01:00
Idan Horowitz 2e5a9b4fab Kernel: Use HashCompatible HashMap lookups instead of specifying a hash 2022-01-29 23:01:23 +02:00
Idan Horowitz a9cd8ca841 Kernel: Make Inode::register_watcher() OOM-fallible 2022-01-26 02:37:03 +02:00
Idan Horowitz 87bd930e7e Kernel: Make InodeWatcher inode registration completely OOM-fallible
InodeWatcher::register_inode was already partially fallible, but the
insertion of the inodes and watch descriptions into their respective
hash maps was not. Note that we cannot simply TRY the insertion into
both, as that could result in an inconsistent state, instead we must
remove the inode from the inode hash map if the insertion into the
watch description hash map failed.
2022-01-26 02:37:03 +02:00
Idan Horowitz 2065a73727 Kernel: Use u64 instead of size_t for BlockBasedFileSystem::read_block
This ensures offsets will not be truncated on large filesystems on i686
2022-01-25 22:41:17 +02:00
Idan Horowitz 0b2e93cf43 Kernel: Use u64 instead of size_t for BlockBasedFileSystem::write_block
This ensures offsets will not be truncated on large filesystems on i686
2022-01-25 22:41:17 +02:00
Idan Horowitz 664ca58746 Kernel: Use u64 instead of size_t for File::can_write offset
This ensures offsets will not be truncated on large files on i686.
2022-01-25 22:41:17 +02:00
Idan Horowitz 9ce537d703 Kernel: Use u64 instead of size_t for File::can_read offset
This ensures offsets will not be truncated on large files on i686.
2022-01-25 22:41:17 +02:00
Idan Horowitz 67ce9e28a5 AK: Standardize the behaviour of GenericLexer::consume_until overloads
Before this commit all consume_until overloads aside from the Predicate
one would consume (and ignore) the stop char/string, while the
Predicate overload would not, in order to keep behaviour consistent,
the other overloads no longer consume the stop char/string as well.
2022-01-25 13:41:09 +03:30
Sam Atkins 45cf40653a Everywhere: Convert ByteBuffer factory methods from Optional -> ErrorOr
Apologies for the enormous commit, but I don't see a way to split this
up nicely. In the vast majority of cases it's a simple change. A few
extra places can use TRY instead of manual error checking though. :^)
2022-01-24 22:36:09 +01:00
Idan Horowitz f39e9b19c6 Kernel: Make DiskCache::ensure OOM-fallible using ErrorOr 2022-01-24 14:09:55 +02:00
David Briggs cf45370c47 Kernel: Use ErrorOr in BlockBased and Ext2 filesystem raw read and write
These functions used to return booleans which withheld useful
error information for callers. Internally they would suppress
and convert Error objects. We now log or propagate these errors
up the stack.
2022-01-23 14:36:01 +00:00
Idan Horowitz 3c1ca61e74 Kernel: Use KString instead of String in InodeWatcher::Event's path 2022-01-21 16:27:21 +01:00
Idan Horowitz 77a81f5eed Kernel: Use KString instead of String in Ext2FSInode's lookup cache 2022-01-21 16:27:21 +01:00
Andreas Kling cda8f34876 Kernel/TmpFS: Remove inode map from TmpFS
The HashMap of InodeIndex->Inode in TmpFS only had one purpose: looking
up parent inodes by index.

Instead of using a map for this, we can simply give each inode a WeakPtr
to its parent inode. This saves us the trouble of dealing with the
fallibility of HashMap allocations, and it just generally simpler. :^)
2022-01-14 12:15:36 +01:00
Idan Horowitz 215e031bf5 Kenrel: Use a KString for Ext2FSDirectoryEntry::name
This brings Ext2FileSystem one step closer to being OOM-safe.
2022-01-13 00:20:08 -08:00
Idan Horowitz 709fe64c1b Revert "Kernel: Use a StringView for Ext2FSDirectoryEntry::name"
This reverts commit d1d24eaef4.

I missed the fact that traverse_as_directory uses a temporary buffer,
meaning that entries created based on its callback will point to free'd
memory.
2022-01-12 21:26:03 +02:00
Idan Horowitz e236f9d85a Kernel: Convert Inode event APIs to use StringViews instead of Strings
These APIs allocate a copy internally anyways, so there's no point to
making another one for them.
2022-01-12 16:09:09 +02:00
Idan Horowitz d1d24eaef4 Kernel: Use a StringView for Ext2FSDirectoryEntry::name
This is a temporary struct, so there's no need to allocate a long term
storage for these strings.
2022-01-12 16:09:09 +02:00
Idan Horowitz d2ffcfb762 Kernel: Remove the Custody::absolute_path() API
With the last user removed this non-fallible API can now be removed.
2022-01-12 16:09:09 +02:00
Idan Horowitz 4e7d307166 Kernel: Convert Mount::absolute_path to ErrorOr<NonnullOwnPtr<KString>> 2022-01-12 16:09:09 +02:00
Idan Horowitz 6be2a51b10 Kernel: Use Vector::try_append in Custody::try_serialize_absolute_path 2022-01-12 16:09:09 +02:00
Daniel Bertalan 182016d7c0 Kernel+LibC+LibCore+UE: Implement fchmodat(2)
This function is an extended version of `chmod(2)` that lets one control
whether to dereference symlinks, and specify a file descriptor to a
directory that will be used as the base for relative paths.
2022-01-12 14:54:12 +01:00
Brian Gianforcaro f8ad3cc6a0 Kernel: Harden DevPtsFSInode::traverse_as_directory against OOM
Use the try variants of AK::StringBuilder append APIs to harden this
function against OOM.
2022-01-12 13:03:44 +01:00
Andreas Kling 08e927f084 Kernel: Synchronize removals from TmpFS inode map
Previously we were uncaching inodes from TmpFSInode::one_ref_left().
This was not safe, since one_ref_left() was effectively being called
on a raw pointer after decrementing the local ref count and observing
it become 1. There was a race here where someone else could trigger
the destructor by unreffing to 0 before one_ref_left() got called,
causing us to call one_ref_left() on a deleted inode.

We fix this by using the new remove_from_secondary_lists() mechanism
in ListedRefCounted and synchronizing all access to the TmpFS inode
map with the main Inode::all_instances() lock.

There's probably a nicer way to solve this.
2022-01-11 01:12:16 +01:00
Andreas Kling a4b3bf1d63 Kernel: Remove empty Ext2FSInode::one_ref_left() 2022-01-11 01:12:16 +01:00
Andreas Kling b66bb11ed1 Kernel: Remove empty ISO9660Inode::one_ref_left() 2022-01-11 01:12:16 +01:00