summaryrefslogtreecommitdiff
path: root/Libraries/LibC
AgeCommit message (Collapse)Author
2020-01-21Kernel+LibC: Clean up open() flag (O_*) definitionsAndreas Kling
These were using a mix of decimal, octal and hexadecimal for no reason.
2020-01-21Kernel: Make O_RDONLY non-zeroAndreas Kling
Sergey suggested that having a non-zero O_RDONLY would make some things less confusing, and it seems like he's right about that. We can now easily check read/write permissions separately instead of dancing around with the bits. This patch also fixes unveil() validation for O_RDWR which previously forgot to check for "r" permission.
2020-01-20Kernel: Add a basic implementation of unveil()Andreas Kling
This syscall is a complement to pledge() and adds the same sort of incremental relinquishing of capabilities for filesystem access. The first call to unveil() will "drop a veil" on the process, and from now on, only unveiled parts of the filesystem are visible to it. Each call to unveil() specifies a path to either a directory or a file along with permissions for that path. The permissions are a combination of the following: - r: Read access (like the "rpath" promise) - w: Write access (like the "wpath" promise) - x: Execute access - c: Create/remove access (like the "cpath" promise) Attempts to open a path that has not been unveiled with fail with ENOENT. If the unveiled path lacks sufficient permissions, it will fail with EACCES. Like pledge(), subsequent calls to unveil() with the same path can only remove permissions, not add them. Once you call unveil(nullptr, nullptr), the veil is locked, and it's no longer possible to unveil any more paths for the process, ever. This concept comes from OpenBSD, and their implementation does various things differently, I'm sure. This is just a first implementation for SerenityOS, and we'll keep improving on it as we go. :^)
2020-01-20Kernel+AK: Add/fix uintptr_t and intptr_t definitionsAndreas Kling
We should move towards using uintptr_t instead of u32 for pointers everywhere, to prepare for an eventual 64-bit port.
2020-01-18LibC: Use the templated type consistently in strtol_impl<T>Andreas Kling
2020-01-18Meta: Add license header to source filesAndreas Kling
As suggested by Joshua, this commit adds the 2-clause BSD license as a comment block to the top of every source file. For the first pass, I've just added myself for simplicity. I encourage everyone to add themselves as copyright holders of any file they've added or modified in some significant way. If I've added myself in error somewhere, feel free to replace it with the appropriate copyright holder instead. Going forward, all new source files should include a license header.
2020-01-17Kernel+LibC: Unify sys$open() and sys$openat()Sergey Bugaev
The syscall is now called sys$open(), but it behaves like the old sys$openat(). In userspace, open_with_path_length() is made a wrapper over openat_with_path_length().
2020-01-16LibC: Add strnlen()Andreas Kling
2020-01-15LibC: Add INADDR_LOOPBACKAndreas Kling
2020-01-13LibC: Move even more methods and globals out of crt0.oAndrew Kaster
2020-01-12Kernel+LibC: Allow passing mount flags to chroot()Sergey Bugaev
Since a chroot is in many ways similar to a separate root mount, we can also apply mount flags to it as if it was an actual mount. These flags will apply whenever the chrooted process accesses its root directory, but not when other processes access this same directory for the outside. Since it's common to chdir("/") immediately after chrooting (so that files accessed through the current directory inherit the same mount flags), this effectively allows one to apply additional limitations to a process confined inside a chroot. To this effect, sys$chroot() gains a mount_flags argument (exposed as chroot_with_mount_flags() in userspace) which can be set to all the same values as the flags argument for sys$mount(), and additionally to -1 to keep the flags set for that file system. Note that passing 0 as mount_flags will unset any flags that may have been set for the file system, not keep them.
2020-01-11Kernel: Add pledge() syscall :^)Andreas Kling
This patch implements basic support for OpenBSD-style pledge(). pledge() allows programs to incrementally reduce their set of allowed syscalls, which are divided into categories that each make up a subset of POSIX functionality. If a process violates one of its pledged promises by attempting to call a syscall that it previously said it wouldn't call, the process is immediately terminated with an uncatchable SIGABRT. This is by no means complete, and we'll need to add more checks in various places to ensure that promises are being kept. But it is pretty cool! :^)
2020-01-11Kernel+LibC: Implement a few mount flagsSergey Bugaev
We now support these mount flags: * MS_NODEV: disallow opening any devices from this file system * MS_NOEXEC: disallow executing any executables from this file system * MS_NOSUID: ignore set-user-id bits on executables from this file system The fourth flag, MS_BIND, is defined, but currently ignored.
2020-01-11Kernel+LibC: Add O_EXEC, move exec permission checking to VFS::open()Sergey Bugaev
O_EXEC is mentioned by POSIX, so let's have it. Currently, it is only used inside the kernel to ensure the process has the right permissions when opening an executable.
2020-01-11Kernel+LibC: Add support for mount flagsSergey Bugaev
At the moment, the actual flags are ignored, but we correctly propagate them all the way from the original mount() syscall to each custody that resides on the mounted FS.
2020-01-11Kernel: Use the Syscall string and buffer types moreAndreas Kling
While I was updating syscalls to stop passing null-terminated strings, I added some helpful struct types: - StringArgument { const char*; size_t; } - ImmutableBuffer<Data, Size> { const Data*; Size; } - MutableBuffer<Data, Size> { Data*; Size; } The Process class has some convenience functions for validating and optionally extracting the contents from these structs: - get_syscall_path_argument(StringArgument) - validate_and_copy_string_from_user(StringArgument) - validate(ImmutableBuffer) - validate(MutableBuffer) There's still so much code around this and I'm wondering if we should generate most of it instead. Possible nice little project.
2020-01-11Kernel: Pass a parameter struct to mount()Andreas Kling
This was the last remaining syscall that took a null-terminated string and figured out how long it was by walking it in kernelspace *shudder*.
2020-01-11Kernel: Pass a parameter struct to rename()Andreas Kling
2020-01-11Kernel: Pass a parameter struct to symlink()Andreas Kling
2020-01-11Kernel: Pass a parameter struct to mknod()Andreas Kling
2020-01-11Kernel: Pass a parameter struct to chown()Andreas Kling
2020-01-10Kernel: Add a basic chroot() syscall :^)Andreas Kling
The chroot() syscall now allows the superuser to isolate a process into a specific subtree of the filesystem. This is not strictly permanent, as it is also possible for a superuser to break *out* of a chroot, but it is a useful mechanism for isolating unprivileged processes. The VFS now uses the current process's root_directory() as the root for path resolution purposes. The root directory is stored as an uncached Custody in the Process object.
2020-01-10Kernel: Pass characters+length to link()Andreas Kling
2020-01-10Kernel: Rename Syscall::SyscallString => Syscall::StringArgumentAndreas Kling
2020-01-10Kernel: Pass characters+length to readlink()Andreas Kling
Note that I'm developing some helper types in the Syscall namespace as I go here. Once I settle on some nice types, I will convert all the other syscalls to use them as well.
2020-01-10LibC: Remove useless retry loop in connect_to_lookup_server()Andreas Kling
2020-01-10Kernel: Enable SMAP protection during the execve() syscallAndreas Kling
The userspace execve() wrapper now measures all the strings and puts them in a neat and tidy structure on the stack. This way we know exactly how much to copy in the kernel, and we don't have to use the SMAP-violating validate_read_str(). :^)
2020-01-09LibC: Fail name lookups immediately if we can't connect to LookupServerAndreas Kling
2020-01-09Kernel: Take path+length in the unlink() and umount() syscallsAndreas Kling
2020-01-08LibC: Don't leave /etc/passwd open in getlogin()Andreas Kling
2020-01-07LibC: Add MAP_FILE for mmap()Andreas Kling
2020-01-06LibC: Remove thread-specific TID cacheAndreas Kling
As Sergey pointed out forever ago, this value is wrong after fork().
2020-01-06Kernel: Make utime() take path+length, remove SmapDisablerAndreas Kling
2020-01-06Kernel: Pass name+length to mmap() and remove SmapDisablerAndreas Kling
2020-01-06Kernel: Pass name+length to set_mmap_name() and remove SmapDisablerAndreas Kling
2020-01-06Kernel: Make realpath() take path+length, get rid of SmapDisablerAndreas Kling
2020-01-06Kernel: Make watch_file() syscall take path length as a size_tAndreas Kling
We don't care to handle negative path lengths anyway.
2020-01-06Kernel: Pass path+length to mkdir(), rmdir() and chmod()Andreas Kling
2020-01-06LibC: Make the syscall wrappers for stat/lstat/chdir return EFAULTAndreas Kling
If we pass a null path to these syscall wrappers, just return EFAULT directly from the wrapper instead of segfaulting by calling strlen(). This is a compromise, since we now have to pass the path length to the kernel, so we can't rely on the kernel to tell us that the path is at a bad memory address.
2020-01-06Kernel: Make access() take path+lengthAndreas Kling
Also, let's return EFAULT for nullptr at the LibC layer. We can't do all bad addresses this way, but we can at least do null. :^)
2020-01-06LibC: Remove dubious String ends_with usageShannon Booth
As mentioned in #917, the String destructor could potentially be clobbering the errno. Use memcpy so that we do not need String at all.
2020-01-05Kernel: Make chdir() take path+lengthAndreas Kling
2020-01-05Kernel: Pass path+length to the stat() and lstat() syscallsAndreas Kling
It's not pleasant having to deal with null-terminated strings as input to syscalls, so let's get rid of them one by one.
2020-01-04LibC: Fix broken setgroups() wrapperAndreas Kling
This was invoking the wrong syscall (getgroups), oops! We had not been using it yet, so it makes sense.
2020-01-04LibELF+LibC: Split ELFDynamicObject into a Loader + ObjectAndrew Kaster
Separate some responsibilities: ELFDynamicLoader is responsible for loading elf binaries from disk and performing relocations, calling init functions, and eventually calling finalizer functions. ELFDynamicObject is a helper class to parse the .dynamic section of an elf binary, or the table of Elf32_Dyn entries at the _DYNAMIC symbol. ELFDynamicObject now owns the helper classes for Relocations, Symbols, Sections and the like that ELFDynamicLoader will use to perform relocations and symbol lookup. Because these new helpers are constructed from offsets into the .dynamic section within the loaded .data section of the binary, we don't need the ELFImage for nearly as much of the loading processes as we did before. Therefore we can remove most of the extra DynamicXXX classes and just keep the one that lets us find the location of _DYNAMIC in the new ELF. And finally, since we changed the name of the class that dlopen/dlsym care about, we need to compile/link and use the new ELFDynamicLoader class in LibC.
2020-01-03Kernel: Remove read_tsc() syscallAndreas Kling
Since nothing is using this, let's just remove it. That's one less thing to worry about.
2020-01-03Lib: Remove Stopwatch classAndreas Kling
This was a hack used to profile things before we had a proper profiler. Since RDTSC is not available in userspace, this is not useful anymore.
2020-01-02Build: add support for building on OpenBSDjoshua stein
This requires gcc8 from ports to build the Toolchain.
2020-01-02LibC+Userland: Add a proper syscall wrapper for purge()Andreas Kling
2020-01-02Kernel: Remove broken implementation of Unix SHMAndreas Kling
This code never worked, as was never used for anything. We can build a much better SHM implementation on top of TmpFS or similar when we get to the point when we need one.