summaryrefslogtreecommitdiff
path: root/Kernel/Process.cpp
AgeCommit message (Collapse)Author
2020-05-31Kernel: Tighten up some promise checksSergey Bugaev
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-29Kernel+Userland: Support remounting filesystems :^)Sergey Bugaev
This makes it possible to change flags of a mount after the fact, with the caveats outlined in the man page.
2020-05-29Kernel: Misc tweaksSergey Bugaev
2020-05-29Kernel: Support read-only filesystem mountsSergey Bugaev
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-29Kernel: Fix error case in Process::create_user_process()Sergey Bugaev
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-29Kernel: Fix some failing assertionsSergey Bugaev
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-29Kernel: Always require read access when mmaping a fileSergey Bugaev
POSIX says, "The file descriptor fildes shall have been opened with read permission, regardless of the protection options specified."
2020-05-26AK: Rename FileSystemPath -> LexicalPathSergey Bugaev
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-26Kernel: Introduce "sigaction" pledgeSergey Bugaev
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-26Kernel: fix assertion on readlink() syscallAngel
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-26Kernel: Plumb KResult through FileDescription::read_entire_file() ↵Brian Gianforcaro
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-23Kernel+LibC: Fix various build issues introduced by ssize_tAndreas Kling
Now that ssize_t is derived from size_t, we have to
2020-05-23Kernel: Use a FlatPtr for the "argument" to ioctl()Andreas Kling
Since it's often used to pass pointers, it should really be a FlatPtr.
2020-05-20Kernel+LibC: Switch isatty() to use a fcntl()Sergey Bugaev
We would want it to work with only stdio pledged.
2020-05-17Kernel + LibC: Handle running processes in do_waitid()AnotherTest
2020-05-17Kernel: wait() should not block if WNOHANG is specifiedAnotherTest
2020-05-16Kernel: Remove Process::any_thread()Andreas Kling
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-16Kernel: Sending a signal to a process now goes to the main threadAndreas Kling
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-16Kernel: Absorb LibBareMetal back into the kernelAndreas Kling
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-16Kernel: Remove now-unused KernelInfoPage.hAndreas Kling
2020-05-16Kernel: Remove sys$getdtablesize()Andreas Kling
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-16Kernel: Use copy_to_user() in sys$gettimeofday()Andreas Kling
2020-05-16Kernel: Remove the "kernel info page" used for fast gettimeofday()Andreas Kling
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-15Kernel: Disallow opening socket filesSergey Bugaev
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-08Kernel+Userland: Add "settime" pledge promise for setting system timeAndreas Kling
We now require the "settime" promise from pledged processes who want to change the system time.
2020-05-08Kernel: Only allow superuser to call sys$clock_settime()Andreas Kling
2020-05-08Kernel: Remove SmapDisabler in sys$clock_settime()Andreas Kling
2020-05-08Kernel: Add for_each_vmobject_of_type<T>Andreas Kling
This makes iterating over a specific type of VMObjects a bit nicer.
2020-05-08Kernel: Propagate failure to commit VM regions in more placesAndreas Kling
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-06Kernel: Crash the current process on OOM (instead of panicking kernel)Andreas Kling
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-03Kernel: Don't crash on invalid fcntlBen Wiederhake
2020-05-03Kernel: Fix pledge syscall applying new pledges when it fails (#2076)Michael Lelli
If the exec promises fail to apply, then the normal promises should not apply either. Add a test for this fixed functionality.
2020-04-26Kernel: Enable timeout support for sys$futex(FUTEX_WAIT)Brian Gianforcaro
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-26Kernel: Make sys$sethostname() superuser-onlyAndreas Kling
Also take the hostname string lock exclusively.
2020-04-26Kernel: Added the ability to set the hostname via new syscallLuke Payne
Userland/hostname: Now takes parameter to set the hostname LibC/unistd: Added sethostname function
2020-04-26Kernel: Support signaling all processes with pid == -1Brian Gianforcaro
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-26Kernel: Implement FUTEX_WAKE of arbitrary count.Brian Gianforcaro
Previously we just woke all waiters no matter how many were requested. Fix this by implementing WaitQueue::wake_n(..).
2020-04-25LibPthread: implicitly call pthread_exit on return from start routine.Drew Stratford
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-20LibELF: Make ELF::Loader RefCountedItamar
2020-04-18Kernel: Use shared locking mode in some placesSergey Bugaev
The notable piece of code that remains to be converted is Ext2FS.
2020-04-14Kernel: Don't include null terminator in sys$readlink() resultSergey Bugaev
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-14Kernel: Simplify sys$setgroups(0, ...)Andreas Kling
If we're dropping all groups, just clear the extra_gids and return.
2020-04-14Kernel: Remove SmapDisablers in {peek,poke}_user_data()Andreas Kling
2020-04-13Debugger: Add DebugSessionItamar
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-13Process: Fix siginfo for code CLD_STOPPEDItamar
si_code, si_status where swapped
2020-04-13ptrace: Add PT_SETREGSItamar
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-13ptrace: Stop a traced thread when it exists from execveItamar
This was a missing feature in the PT_TRACEME command. This feature allows the tracer to interact with the tracee before the tracee has started executing its program. It will be useful for automatically inserting a breakpoint at a debugged program's entry point.
2020-04-13ptrace: Add PT_POKEItamar
PT_POKE writes a single word to the tracee's address space. Some caveats: - If the user requests to write to an address in a read-only region, we temporarily change the page's protections to allow it. - If the user requests to write to a region that's backed by a SharedInodeVMObject, we replace the vmobject with a PrivateIndoeVMObject.
2020-04-13ptrace: Add PT_PEEKItamar
PT_PEEK reads a single word from the tracee's address space and returns it to the tracer.
2020-04-12Kernel+LibC: Add minherit() and MAP_INHERIT_ZEROAndreas Kling
This patch adds the minherit() syscall originally invented by OpenBSD. Only the MAP_INHERIT_ZERO mode is supported for now. If set on an mmap region, that region will be zeroed out on fork().