Commit Graph

854 Commits

Author SHA1 Message Date
Sergey Bugaev
47d83800e1 Kernel+LibC: Do not return -ENAMETOOLONG from sys$readlink()
That's not how readlink() is supposed to work: it should copy as many bytes
as fit into the buffer, and return the number of bytes copied. So do that,
but add a twist: make sys$readlink() actually return the whole size, not
the number of bytes copied. We fix up this return value in userspace, to make
LibC's readlink() behave as expected, but this will also allow other code
to allocate a buffer of just the right size.

Also, avoid an extra copy of the link target.
2020-06-17 15:02:03 +02:00
Hüseyin ASLITÜRK
174987f930 Kernel: Replace char and u8 data types to u32 for code point
Remove character property from event and add code_point property.
2020-06-16 13:15:17 +02:00
Hüseyin ASLITÜRK
f4d14c42d0 Kernel: Process, replace internal data type to CharacterMapData 2020-06-13 12:36:30 +02:00
Sergey Bugaev
31b025fcfc Kernel: Allow sys$accept(address = nullptr) 2020-06-09 21:12:34 +02:00
Sergey Bugaev
05b7fec517 Kernel: Tighten up some promise checks
Since we're not keeping compatibility with OpenBSD about what promises are
required for which syscalls, tighten things up so that they make more sense.
2020-05-31 21:38:50 +02:00
Sergey Bugaev
3847d00727 Kernel+Userland: Support remounting filesystems :^)
This makes it possible to change flags of a mount after the fact, with the
caveats outlined in the man page.
2020-05-29 07:53:30 +02:00
Sergey Bugaev
d395b93b15 Kernel: Misc tweaks 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
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
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
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
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
Sergey Bugaev
7541122206 Kernel+LibC: Switch isatty() to use a fcntl()
We would want it to work with only stdio pledged.
2020-05-20 08:31:31 +02:00
AnotherTest
8582a06899 Kernel + LibC: Handle running processes in do_waitid() 2020-05-17 11:58:08 +02:00
AnotherTest
9d54f21859 Kernel: wait() should not block if WNOHANG is specified 2020-05-17 11:58:08 +02:00
Andreas Kling
f7a75598bb Kernel: Remove Process::any_thread()
This was a holdover from the old times when each Process had a special
main thread with TID 0. Using it was a total crapshoot since it would
just return whichever thread was first on the process's thread list.

Now that I've removed all uses of it, we don't need it anymore. :^)
2020-05-16 12:40:15 +02:00
Andreas Kling
0e7f85c24a Kernel: Sending a signal to a process now goes to the main thread
Instead of falling back to the suspicious "any_thread()" mechanism,
just fail with ESRCH if you try to kill() a PID that doesn't have a
corresponding TID.
2020-05-16 12:33:48 +02:00
Andreas Kling
21d5f4ada1 Kernel: Absorb LibBareMetal back into the kernel
This was supposed to be the foundation for some kind of pre-kernel
environment, but nobody is working on it right now, so let's move
everything back into the kernel and remove all the confusion.
2020-05-16 12:00:04 +02:00
Andreas Kling
204fb27333 Kernel: Remove now-unused KernelInfoPage.h 2020-05-16 11:34:54 +02:00
Andreas Kling
2dc051c866 Kernel: Remove sys$getdtablesize()
I'm not sure why this was a syscall. If we need this we can add it in
LibC as a wrapper around sysconf(_SC_OPEN_MAX).
2020-05-16 11:34:01 +02:00
Andreas Kling
426c4e387d Kernel: Use copy_to_user() in sys$gettimeofday() 2020-05-16 11:34:01 +02:00
Andreas Kling
3a92d0828d Kernel: Remove the "kernel info page" used for fast gettimeofday()
We stopped using gettimeofday() in Core::EventLoop a while back,
in favor of clock_gettime() for monotonic time.

Maintaining an optimization for a syscall we're not using doesn't make
a lot of sense, so let's go back to the old-style sys$gettimeofday().
2020-05-16 11:33:59 +02:00
Sergey Bugaev
752617cbb2 Kernel: Disallow opening socket files
You can still open files that have sockets attached to them from inside
the kernel via VFS::open() (and in fact, that is what LocalSocket itslef uses),
but trying to do that from userspace using open() will now fail with ENXIO.
2020-05-15 11:43:58 +02:00
Andreas Kling
5bfd893292 Kernel+Userland: Add "settime" pledge promise for setting system time
We now require the "settime" promise from pledged processes who want to
change the system time.
2020-05-08 22:54:17 +02:00
Andreas Kling
1cddb1055f Kernel: Only allow superuser to call sys$clock_settime() 2020-05-08 22:47:21 +02:00
Andreas Kling
652b22ee9c Kernel: Remove SmapDisabler in sys$clock_settime() 2020-05-08 22:47:03 +02:00
Andreas Kling
55f61c0004 Kernel: Add for_each_vmobject_of_type<T>
This makes iterating over a specific type of VMObjects a bit nicer.
2020-05-08 22:10:47 +02:00
Andreas Kling
042b1f6814 Kernel: Propagate failure to commit VM regions in more places
Ultimately we should not panic just because we can't fully commit a VM
region (by populating it with physical pages.)

This patch handles some of the situations where commit() can fail.
2020-05-08 21:47:08 +02:00
Andreas Kling
6fe83b0ac4 Kernel: Crash the current process on OOM (instead of panicking kernel)
This patch adds PageFaultResponse::OutOfMemory which informs the fault
handler that we were unable to allocate a necessary physical page and
cannot continue.

In response to this, the kernel will crash the current process. Because
we are OOM, we can't symbolicate the crash like we normally would
(since the ELF symbolication code needs to allocate), so we also
communicate to Process::crash() that we're out of memory.

Now we can survive "allocate 300 MB" (only the allocate process dies.)
This is definitely not perfect and can easily end up killing a random
innocent other process who happened to allocate one page at the wrong
time, but it's a *lot* better than panicking on OOM. :^)
2020-05-06 22:28:23 +02:00
Ben Wiederhake
dce3faff08 Kernel: Don't crash on invalid fcntl 2020-05-03 22:46:28 +02:00
Michael Lelli
58a34fbe09
Kernel: Fix pledge syscall applying new pledges when it fails (#2076)
If the exec promises fail to apply, then the normal promises should
not apply either. Add a test for this fixed functionality.
2020-05-03 00:41:18 +02:00
Brian Gianforcaro
25a620a573 Kernel: Enable timeout support for sys$futex(FUTEX_WAIT)
Utilize the new Thread::wait_on timeout parameter to implement
timeout support for FUTEX_WAIT.

As we compute the relative time from the user specified absolute
time, we try to delay that computation as long as possible before
we call into Thread::wait_on(..). To enable this a small bit of
refactoring was done pull futex_queue fetching out and timeout fetch
and calculation separation.
2020-04-26 21:31:52 +02:00
Andreas Kling
fb826aa59a Kernel: Make sys$sethostname() superuser-only
Also take the hostname string lock exclusively.
2020-04-26 15:51:57 +02:00
Luke Payne
f191b84b50 Kernel: Added the ability to set the hostname via new syscall
Userland/hostname: Now takes parameter to set the hostname
LibC/unistd: Added sethostname function
2020-04-26 12:59:09 +02:00
Brian Gianforcaro
0f3990cfa3 Kernel: Support signaling all processes with pid == -1
This is a special case that was previously not implemented.
The idea is that you can dispatch a signal to all other processes
the calling process has access to.

There was some minor refactoring to make the self signal logic
into a function so it could easily be easily re-used from do_killall.
2020-04-26 12:54:10 +02:00
Brian Gianforcaro
1f64e3eb16 Kernel: Implement FUTEX_WAKE of arbitrary count.
Previously we just woke all waiters no matter how many were
requested. Fix this by implementing WaitQueue::wake_n(..).
2020-04-26 12:35:35 +02:00
Drew Stratford
4a37362249 LibPthread: implicitly call pthread_exit on return from start routine.
Previously, when returning from a pthread's start_routine, we would
segfault. Now we instead implicitly call pthread_exit as specified in
the standard.

pthread_create now creates a thread running the new
pthread_create_helper, which properly manages the calling and exiting
of the start_routine supplied to pthread_create. To accomplish this,
the thread's stack initialization has been moved out of
sys$create_thread and into the userspace function create_thread.
2020-04-25 16:51:35 +02:00
Itamar
edaa9c06d9 LibELF: Make ELF::Loader RefCounted 2020-04-20 17:25:50 +02:00
Sergey Bugaev
54550365eb Kernel: Use shared locking mode in some places
The notable piece of code that remains to be converted is Ext2FS.
2020-04-18 13:58:29 +02:00
Sergey Bugaev
f18d6610d3 Kernel: Don't include null terminator in sys$readlink() result
POSIX says, "Conforming applications should not assume that the returned
contents of the symbolic link are null-terminated."

If we do include the null terminator into the returning string, Python
believes it to actually be a part of the returned name, and gets unhappy
about that later. This suggests other systems Python runs in don't include
it, so let's do that too.

Also, make our userspace support non-null-terminated realpath().
2020-04-14 18:40:24 +02:00
Andreas Kling
815b73bdcc Kernel: Simplify sys$setgroups(0, ...)
If we're dropping all groups, just clear the extra_gids and return.
2020-04-14 15:30:25 +02:00
Andreas Kling
9962db5bf8 Kernel: Remove SmapDisablers in {peek,poke}_user_data() 2020-04-14 09:52:49 +02:00
Itamar
3e9a7175d1 Debugger: Add DebugSession
The DebugSession class wraps the usage of Ptrace.
It is intended to be used by cli & gui debugger programs.

Also, call objdump for disassemly
2020-04-13 00:53:22 +02:00
Itamar
aae3f7b914 Process: Fix siginfo for code CLD_STOPPED
si_code, si_status where swapped
2020-04-13 00:53:22 +02:00
Itamar
9e51e295cf ptrace: Add PT_SETREGS
PT_SETTREGS sets the regsiters of the traced thread. It can only be
used when the tracee is stopped.

Also, refactor ptrace.
The implementation was getting long and cluttered the alraedy large
Process.cpp file.

This commit moves the bulk of the implementation to Kernel/Ptrace.cpp,
and factors out peek & poke to separate methods of the Process class.
2020-04-13 00:53:22 +02:00