Commit Graph

291 Commits

Author SHA1 Message Date
Ben Wiederhake
081bb29626 Kernel: Unbreak building with extra debug macros, part 2 2020-08-30 09:43:49 +02:00
Ben Wiederhake
eac3bbdcee Kernel: Unbreak building with extra debug macros, part 1 2020-08-30 09:43:49 +02:00
AnotherTest
688e54eac7 Kernel: Distinguish between new and old process groups with equal pgids
This does not add any behaviour change to the processes, but it ties a
TTY to an active process group via TIOCSPGRP, and returns the TTY to the
kernel when all processes in the process group die.
Also makes the TTY keep a link to the original controlling process' parent (for
SIGCHLD) instead of the process itself.
2020-08-19 21:21:34 +02:00
Brian Gianforcaro
8e97de2df9 Kernel: Use Userspace<T> for the recvfrom syscall, and Socket implementation
This fixes a bunch of unchecked kernel reads and writes, seems like they
would might exploitable :). Write of sockaddr_in size to any address you
please...
2020-08-19 21:05:28 +02:00
Brian Gianforcaro
9f9b05ba0f Kernel: Use Userspace<T> for the sendto syscall, and Socket implementation
Note that the data member is of type ImmutableBufferArgument, which has
no Userspace<T> usage. I left it alone for now, to be fixed in a future
change holistically for all usages.
2020-08-19 21:05:28 +02:00
Itamar
3b422564f3 Kernel: Fix behaviour of PT_TRACEME in ptrace
The behaviour of the PT_TRACEME feature has been broken for some time,
this change fixes it.

When this ptrace flag is used, the traced process should be paused
before exiting execve.
We previously were sending the SIGSTOP signal at a stage where
interrupts are disabled, and the traced process continued executing
normally, without pausing and waiting for the tracer.
This change fixes it.
2020-08-15 15:06:35 +02:00
Andreas Kling
65f2270232 Kernel+LibC+UserspaceEmulator: Bring back sys$dup2()
This is racy in userspace and non-racy in kernelspace so let's keep
it in kernelspace.

The behavior change where CLOEXEC is preserved when dup2() is called
with (old_fd == new_fd) was good though, let's keep that.
2020-08-15 11:11:34 +02:00
Andreas Kling
bf247fb45f Kernel+LibC+UserspaceEmulator: Remove sys$dup() and sys$dup2()
We can just implement these in userspace, so yay two less syscalls!
2020-08-15 01:30:22 +02:00
Ben Wiederhake
42b057b0c9 Kernel: Mark compilation-unit-only functions as static
This enables a nice warning in case a function becomes dead code. Also, in case
of signal_trampoline_dummy, marking it external (non-static) prevents it from
being 'optimized away', which would lead to surprising and weird linker errors.

I found these places by using -Wmissing-declarations.

The Kernel still shows these issues, which I think are false-positives,
but don't want to touch:
- Kernel/Arch/i386/CPU.cpp:1081:17: void Kernel::enter_thread_context(Kernel::Thread*, Kernel::Thread*)
- Kernel/Arch/i386/CPU.cpp:1170:17: void Kernel::context_first_init(Kernel::Thread*, Kernel::Thread*, Kernel::TrapFrame*)
- Kernel/Arch/i386/CPU.cpp:1304:16: u32 Kernel::do_init_context(Kernel::Thread*, u32)
- Kernel/Arch/i386/CPU.cpp:1347:17: void Kernel::pre_init_finished()
- Kernel/Arch/i386/CPU.cpp:1360:17: void Kernel::post_init_finished()
	No idea, not gonna touch it.
- Kernel/init.cpp:104:30: void Kernel::init()
- Kernel/init.cpp:167:30: void Kernel::init_ap(u32, Kernel::Processor*)
- Kernel/init.cpp:184:17: void Kernel::init_finished(u32)
	Called by boot.S.
- Kernel/init.cpp:383:16: int Kernel::__cxa_atexit(void (*)(void*), void*, void*)
- Kernel/StdLib.cpp:285:19: void __cxa_pure_virtual()
- Kernel/StdLib.cpp:300:19: void __stack_chk_fail()
- Kernel/StdLib.cpp:305:19: void __stack_chk_fail_local()
	Not sure how to tell the compiler that the compiler is already using them.
	Also, maybe __cxa_atexit should go into StdLib.cpp?
- Kernel/Modules/TestModule.cpp:31:17: void module_init()
- Kernel/Modules/TestModule.cpp:40:17: void module_fini()
	Could maybe go into a new header. This would also provide type-checking for new modules.
2020-08-12 20:40:59 +02:00
AnotherTest
29035b55b2 Kernel: Allow moving a process to a new pgrp via setpgid() 2020-08-12 11:41:18 +02:00
Andreas Kling
62ec6e5fe0 Kernel: Make Inode::read_entire() return a KBuffer (not ByteBuffer)
ByteBuffer is backed by kmalloc heap memory which is a scarce resource.
This fixes an OOM panic when traversing a large directory.
2020-08-11 20:29:14 +02:00
Brian Gianforcaro
0e627b0273 Kernel: Use Userspace<T> for the exit_thread syscall
Userspace<void*> is a bit strange here, as it would appear to the
user that we intend to de-refrence the pointer in kernel mode.

However I think it does a good join of illustrating that we are
treating the void* as a value type,  instead of a pointer type.
2020-08-10 12:52:15 +02:00
Brian Gianforcaro
d3847b3489 Kernel: Use Userspace<T> for the join_thread syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
e8917cc5f3 Kernel: Use Userspace<T> for the chroot syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
20e2a5c111 Kernel: Use Userspace<T> for the module_unload syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
c4927ceb08 Kernel: Use Userspace<T> for the module_load syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
b5a2a215f6 Kernel: Use Userspace<T> for the getrandom syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
c8ae244ab8 Kernel: Use Userspace<T> for the shbuf_get syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
e073f2b59e Kernel: Use Userspace<T> for the get_thread_name syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
9652b0ae2b Kernel: Use Userspace<T> for the set_thread_name syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
0e20a6df0a Kernel: Use Userspace<T> for the connect syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
8bd9dbc220 Kernel: Use Userspace<T> for the accept syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
02660b5d60 Kernel: Use Userspace<T> for the bind syscall, and implementation 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
2bac7190c8 Kernel: Use Userspace<T> for the chmod syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
82bf6e8133 Kernel: Use Userspace<T> for the umount syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
317800324c Kernel: Use Userspace<T> for the unlink syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
ecfe20efd2 Kernel: Use Userspace<T> for the sigpending syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
fbb26b28b9 Kernel: Use Userspace<T> for the sigprocmask syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
431145148e Kernel: Use Userspace<T> for the fstat syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
8dd78201a4 Kernel: Use Userspace<T> for the uname syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
cfedd62b5c Kernel: Use Userspace<T> for the sethostname syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
1d9554f470 Kernel: Use Userspace<T> for the gethostname syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
b069d757a3 Kernel: Use Userspace<T> for the clock_settime syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
1be6145fdf Kernel: Modifiy clock_settime timespec argument to const
The timeppec paramter is read only, and should be const.
2020-08-10 12:52:15 +02:00
Brian Gianforcaro
b4d04fd8d1 Kernel: Use Userspace<T> for the clock_gettime syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
48d9f3c2e6 Kernel: Use Userspace<T> for the getresgid syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
3ca18a88d7 Kernel: Use Userspace<T> for the getresuid syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
7943655838 Kernel: Use Userspace<T> for the times syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
e7728ca8fd Kernel: Use Userspace<T> for the getgroups syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
80011cd62d Kernel: Use Userspace<T> for the setgroups syscall 2020-08-10 12:52:15 +02:00
Brian Gianforcaro
0f42463eab Kernel: Use Userspace<T> for the execve syscall 2020-08-10 12:52:15 +02:00
Ben Wiederhake
bee08a4b9f Kernel: More PID/TID typing 2020-08-10 11:51:45 +02:00
Ben Wiederhake
7bdf54c837 Kernel: PID/PGID typing
This compiles, and fixes two bugs:
- setpgid() confusion (see previous commit)
- tcsetpgrp() now allows to set a non-empty process group even if
  the group leader has already died. This makes Serenity slightly
  more POSIX-compatible.
2020-08-10 11:51:45 +02:00
Ben Wiederhake
f5744a6f2f Kernel: PID/TID typing
This compiles, and contains exactly the same bugs as before.
The regex 'FIXME: PID/' should reveal all markers that I left behind, including:
- Incomplete conversion
- Issues or things that look fishy
- Actual bugs that will go wrong during runtime
2020-08-10 11:51:45 +02:00
Brian Gianforcaro
35c745ca54 Kernel: Use Userspace<T> for the realpath syscall 2020-08-07 16:18:36 +02:00
Brian Gianforcaro
30b2c0dc85 Kernel: Use Userspace<T> for the getsockopt syscall and Socket interface
The way getsockopt is implemented for socket types requires us to push
down Userspace<T> using into those interfaces. This change does so, and
utilizes proper copy implementations instead of the kind of haphazard
pointer dereferencing that was occurring there before.
2020-08-07 16:18:36 +02:00
Brian Gianforcaro
6920d5f423 Kernel: Use Userspace<T> for the setsockopt syscall 2020-08-07 16:18:36 +02:00
Brian Gianforcaro
8fa46bcb7d Kernel: Use Userspace<T> for the getsockname syscall 2020-08-07 16:18:36 +02:00
Brian Gianforcaro
dc75ea9fc2 Kernel: Use Userspace<T> for the getpeername syscall 2020-08-07 16:18:36 +02:00
Brian Gianforcaro
0db669a9d2 Kernel: Use Userspace<T> for the chown syscall 2020-08-07 16:18:36 +02:00
Brian Gianforcaro
7e7ee2ec94 Kernel: Use Userspace<T> for the mount syscall 2020-08-07 16:18:36 +02:00
Valtteri Koskivuori
00a0e525e6 Kernel+LibKeyboard: Store the keymap name when setting system keymap
This way we can query the kernel to see which keymap is currently in use.
2020-08-06 17:45:06 +02:00
Brian Gianforcaro
7e6fbef8db Kernel: Partial usage of Userspace<T> for the poll syscall
This change mostly converts poll to Userspace<T> with the caveat
of the fds member of SC_poll_params. It's current usage is a bit
too gnarly for me to take on right now, this appears to need a lot
more love.

In addition to enlightening the syscall to use Userspace<T>, I've
also re-worked most of the handling to use validate_read_and_copy
instead of just directly de-referencing the user pointer. We also
appeared to be missing a re-evaluation of the fds array after the
thread block is awoken.
2020-08-06 10:22:44 +02:00
Brian Gianforcaro
946c96dd56 Kernel: Suppress remaining unobserved KResult return codes
These are all cases where there is no clear and easy fix,
I've left FIXME bread crumbs so that these can hopefully
be fixed over time.
2020-08-05 14:36:48 +02:00
Brian Gianforcaro
fa666f6897 Kernel: Use Userspace<T> for the futex syscall
Utilizie Userspace<T> for the syscall argument itself, as well
as internally in the SC_futex_params struct.

We were double validating the SC_futex_params.timeout validation,
that was removed as well.
2020-08-05 13:03:50 +02:00
Brian Gianforcaro
7490ea9449 Kernel + LibPthread: Use Userspace<T> in the create_thread syscall 2020-08-05 09:36:53 +02:00
Brian Gianforcaro
337e8f98cd Kernel: Use Userspace<T> for the rename syscall 2020-08-05 09:36:53 +02:00
Brian Gianforcaro
c1541f4a61 Kernel: Use Userspace<T> for the mknod syscall 2020-08-05 09:36:53 +02:00
Brian Gianforcaro
d949b2a367 Kernel: Use Userspace<T> for the set_mmap_name syscall 2020-08-05 09:36:53 +02:00
Brian Gianforcaro
7449921f53 Kernel: Use Userspace<T> for the readlink syscall 2020-08-05 09:36:53 +02:00
Brian Gianforcaro
901dae0227 Kernel: Use Userspace<T> for the mmap syscall 2020-08-05 09:36:53 +02:00
Brian Gianforcaro
74d3b202f1 Kernel: Use Userspace<T> for the waitid syscall 2020-08-05 09:36:53 +02:00
Brian Gianforcaro
84035e1035 Kernel: Use Userspace<T> for the clock_nanosleep syscall 2020-08-05 09:36:53 +02:00
Brian Gianforcaro
baa070afb8 Kernel: Use Userspace<T> for the gettimeofday syscall 2020-08-05 09:36:53 +02:00
Brian Gianforcaro
1eeaed31c2 Kernel: Use Userspace<T> for the open syscall 2020-08-05 09:36:53 +02:00
Andreas Kling
7a3ab6c517 Kernel: Make File::write() and File::read() return KResultOr<size_t>
Instead of returning a ssize_t where negative values mean error,
we now return KResultOr<size_t> and use the error state to report
errors exclusively.
2020-08-04 18:17:16 +02:00
Andreas Kling
58feebeed2 Kernel+LibC: Tidy up sys$ttyname() and sys$ptsname()
- Remove goofy _r suffix from syscall names.
- Don't take a signed buffer size.
- Use Userspace<T>.
- Make TTY::tty_name() return a String instead of a StringView.
2020-08-04 18:17:16 +02:00
Andreas Kling
7de831efc6 Kernel+LibC: Add sys$disown() for disowning child processes
This syscall allows a parent process to disown a child process, setting
its parent PID to 0.

Unparented processes are automatically reaped by the kernel upon exit,
and no sys$waitid() is required. This will make it much nicer to do
spawn-and-forget which is common in the GUI environment.
2020-08-04 18:17:16 +02:00
Andreas Kling
b139fb9f38 Kernel: Use Userspace<T> in sys$link() and sys$symlink() 2020-08-03 18:40:28 +02:00
Tom
f4a5c9b6c2 Kernel: Consolidate timeout logic
Allow passing in an optional timeout to Thread::block and move
the timeout check out of Thread::Blocker. This way all Blockers
implicitly support timeouts and don't need to implement it
themselves. Do however allow them to override timeouts (e.g.
for sockets).
2020-08-03 18:23:00 +02:00
Brian Gianforcaro
cb167ea388 Kernel: Use for-each loops in unveil syscall 2020-08-03 12:54:51 +02:00
Brian Gianforcaro
2242f69cd6 Kernel: Use Userspace<T> in unveil syscall 2020-08-02 20:54:17 +02:00
Brian Gianforcaro
9db5a1b92f Kernel: Use Userspace<T> in sched_getparam syscall 2020-08-02 20:53:48 +02:00
Tom
538b985487 Kernel: Remove ProcessInspectionHandle and make Process RefCounted
By making the Process class RefCounted we don't really need
ProcessInspectionHandle anymore. This also fixes some race
conditions where a Process may be deleted while still being
used by ProcFS.

Also make sure to acquire the Process' lock when accessing
regions.

Last but not least, there's no reason why a thread can't be
scheduled while being inspected, though in practice it won't
happen anyway because the scheduler lock is held at the same
time.
2020-08-02 17:15:11 +02:00
Andreas Kling
e526fa572a Kernel: Convert some more syscalls to Userspace<T>
These are really straightforward when all the helpers just work.
2020-08-02 11:01:00 +02:00
Brian Gianforcaro
2a74c59dec Kernel: Use Userspace<T> in pledge syscall 2020-08-02 10:56:43 +02:00
Brian Gianforcaro
ba4cf59d04 Kernel: Use Userspace<T> in setkeymap syscall 2020-08-02 10:56:33 +02:00
Brian Gianforcaro
10e912d68c Kernel: Use Userspace<T> in sched_setparam syscall
Note: I switched from copying the single element out of the sched_param
struct, to copy struct it self as it is identical in functionality.
This way the types match up nicer with the Userpace<T> api's and it
conforms to the conventions used in other syscalls.
2020-08-02 10:55:38 +02:00
Brian Gianforcaro
1209bf82c1 Kernel: Use Userspace<T> in ptrace syscall 2020-08-02 00:29:04 +02:00
Andreas Kling
8d4d1c7457 Kernel: Use Userspace<T> in more syscalls 2020-08-01 11:37:40 +02:00
Andreas Kling
628b3badfb Kernel+AK: Add and use Userspace<T>::unsafe_userspace_ptr()
Since we already have the type information in the Userspace template,
it was a bit silly to cast manually everywhere. Just add a sufficiently
scary-sounding getter for a typed pointer.

Thanks @alimpfard for pointing out that I was being silly with tossing
out the type.

In the future we may want to make this API non-public as well.
2020-07-31 20:56:48 +02:00
Itamar
5cd7159629 Kernel: Add _SC_PAGESIZE to sysconf
This unbreaks the gcc and binutils ports.
Previously, when _SC_PAGESIZE was missing, these packages opted to
use their own versions of getpagesize which made their build fail
because of conflicting definitions of the function.
2020-07-31 18:26:33 +02:00
Andreas Kling
180207062c Kernel: Use Userspace<T> in sys$utime()
And again, another helper overload.
2020-07-31 16:38:47 +02:00
Andreas Kling
62a4099581 Kernel: Use Userspace<T> in sys$getcwd() and sys$chdir()
Add more validation helper overloads as we go. :^)
2020-07-31 16:34:47 +02:00
Andreas Kling
314dbc10d4 Kernel: Use Userspace<T> for sys$read() and sys$stat()
Add validation helper overloads as needed.
2020-07-31 16:28:37 +02:00
Andreas Kling
d19d6a63c6 Kernel: Add missing license headers to some syscall files 2020-07-31 01:01:41 +02:00
Andreas Kling
3023a89e9b Kernel: Remove SmapDisabler in sys$setsockopt() 2020-07-31 00:29:26 +02:00
Andreas Kling
292cd53192 Kernel: Remove SmapDisabler in sys$ioctl()
Use copy_{to,from}_user() in the various File::ioctl() implementations
instead of disabling SMAP wholesale in sys$ioctl().

This patch does not port IPv4Socket::ioctl() to those API's since that
will be more involved. That function now creates a local SmapDisabler.
2020-07-31 00:17:25 +02:00
Andreas Kling
be7add690d Kernel: Rename region_from_foo() => find_region_from_foo()
Let's emphasize that these functions actually go out and find regions.
2020-07-30 23:52:28 +02:00
Andreas Kling
2e2de125e5 Kernel: Turn Process::FileDescriptionAndFlags into a proper class 2020-07-30 23:50:31 +02:00
Andreas Kling
949aef4aef Kernel: Move syscall implementations out of Process.cpp
This is something I've been meaning to do for a long time, and here we
finally go. This patch moves all sys$foo functions out of Process.cpp
and into files in Kernel/Syscalls/.

It's not exactly one syscall per file (although it could be, but I got
a bit tired of the repetitive work here..)

This makes hacking on individual syscalls a lot less painful since you
don't have to rebuild nearly as much code every time. I'm also hopeful
that this makes it easier to understand individual syscalls. :^)
2020-07-30 23:40:57 +02:00