summaryrefslogtreecommitdiff
path: root/Kernel/Syscalls/unveil.cpp
AgeCommit message (Collapse)Author
2021-11-08Kernel: Replace KResult and KResultOr<T> with Error and ErrorOr<T>Andreas Kling
We now use AK::Error and AK::ErrorOr<T> in both kernel and userspace! This was a slightly tedious refactoring that took a long time, so it's not unlikely that some bugs crept in. Nevertheless, it does pass basic functionality testing, and it's just real nice to finally see the same pattern in all contexts. :^)
2021-09-06Kernel: Make KString factories return KResultOr + use TRY() everywhereAndreas Kling
There are a number of places that don't have an error propagation path right now, so I've added FIXME's about that.
2021-09-06Kernel: Improvements to Custody absolute path serializationAndreas Kling
- Renamed try_create_absolute_path() => try_serialize_absolute_path() - Use KResultOr and TRY() to propagate errors - Don't call this when it's only for debug logging
2021-09-05Kernel: Use copy_typed_from_user<T> for fetching syscall parametersAndreas Kling
2021-09-05Kernel: Make copy_{from,to}_user() return KResult and use TRY()Andreas Kling
This makes EFAULT propagation flow much more naturally. :^)
2021-09-05Kernel: Use TRY() in sys$unveil()Andreas Kling
2021-08-15Kernel+Userland: Remove chroot functionalityAndreas Kling
We are not using this for anything and it's just been sitting there gathering dust for well over a year, so let's stop carrying all this complexity around for no good reason.
2021-08-14Kernel: Stop allowing implicit conversion from KResult to intAndreas Kling
This patch removes KResult::operator int() and deals with the fallout. This forces a lot of code to be more explicit in its handling of errors, greatly improving readability.
2021-07-23Kernel: Migrate sys$unveil to use the KString APIBrian Gianforcaro
This avoids potential unhandled OOM that's possible with the old copy_string_from_user API.
2021-07-20Kernel: Annotate all syscalls with VERIFY_PROCESS_BIG_LOCK_ACQUIREDBrian Gianforcaro
Before we start disabling acquisition of the big process lock for specific syscalls, make sure to document and assert that all the lock is held during all syscalls.
2021-07-11Kernel: Rename VFS => VirtualFileSystemAndreas Kling
2021-07-07Kernel: Custody::absolute_path() => try_create_absolute_path()Max Wipfli
This converts most users of Custody::absolute_path() to use the new try_create_absolute_path() API, and return ENOMEM if the KString allocation fails.
2021-07-07Kernel: Replace usage of LexicalPath with KLexicalPathMax Wipfli
This replaces all uses of LexicalPath in the Kernel with the functions from KLexicalPath. This also allows the Kernel to stop including AK::LexicalPath.
2021-06-30AK+Everywhere: Use mostly StringView in LexicalPathMax Wipfli
This changes the m_parts, m_dirname, m_basename, m_title and m_extension member variables to StringViews onto the m_string String. It also removes the m_is_absolute member in favour of computing if a path is absolute in the is_absolute() getter. Due to this, the canonicalize() method has been completely rewritten. The parts() getter still returns a Vector<String>, although it is no longer a const reference as m_parts is no longer a Vector<String>. Rather, it is constructed from the StringViews in m_parts upon request. The parts_view() getter has been added, which returns Vector<StringView> const&. Most previous users of parts() have been changed to use parts_view(), except where Strings are required. Due to this change, it's is now no longer allow to create temporary LexicalPath objects to call the dirname, basename, title, or extension getters on them because the returned StringViews will point to possible freed memory.
2021-06-30AK+Everywhere: Add and use static APIs for LexicalPathMax Wipfli
The LexicalPath instance methods dirname(), basename(), title() and extension() will be changed to return StringView const& in a further commit. Due to this, users creating temporary LexicalPath objects just to call one of those getters will recieve a StringView const& pointing to a possible freed buffer. To avoid this, static methods for those APIs have been added, which will return a String by value to avoid those problems. All cases where temporary LexicalPath objects have been used as described above haven been changed to use the static APIs.
2021-06-28Kernel: Fix the return type for syscallsGunnar Beutner
The Process::Handler type has KResultOr<FlatPtr> as its return type. Using a different return type with an equally-sized template parameter sort of works but breaks once that condition is no longer true, e.g. for KResultOr<int> on x86_64. Ideally the syscall handlers would also take FlatPtrs as their args so we can get rid of the reinterpret_cast for the function pointer but I didn't quite feel like cleaning that up as well.
2021-06-08Kernel: Change unveil state to dropped even when node already existsMax Wipfli
This also changes the UnveilState to Dropped when the path unveil() is called for already has a node. This fixes a bug where unveiling "/" would previously keep the UnveilState as None, which meant that everything was still accessible until unveil() was called with any non-root path (or nullptr).
2021-06-08Kernel: Update intermediate nodes when changing unveil permissionsMax Wipfli
When changing the unveil permissions of a preexisting node, we need to make sure that any intermediate nodes that were created before and should inherit permissions from the updated node are updated properly. This fixes the following bug: unveil("/home/anon/Documents", "r"); unveil("/home", "r"); Now there was a intermediate node for "/home/anon" which still had no permission, even though it should have inherited the permissions from "/home".
2021-06-08Kernel: Allow unveiling subfolders regardless of parent's permissionsMax Wipfli
This fixes a bug where unveiling a subdirectory of an already unveiled path would sometimes be allowed and sometimes not (depending on what other unveil calls have been made). Now, it is always allowed to unveil a subdirectory of an already unveiled directory, even if it has higher permissions. This removes the need for the permissions_inherited_from_root flag in UnveilMetadata, so it has been removed.
2021-06-08Kernel: Use LexicalPath to avoid two consecutive slashes in unveil pathMax Wipfli
This patch fixes a bug in the unveil syscall where an UnveilNode's path would start with two slashes if it's parent node was "/".
2021-05-29Kernel: Convert Process::get_syscall_path_argument() to KStringAndreas Kling
This API now returns a KResultOr<NonnullOwnPtr<KString>> and allocation failures should be propagated everywhere nicely. :^)
2021-04-22Everything: Move to SPDX license identifiers in all files.Brian Gianforcaro
SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-03-01Kernel: Make all syscall functions return KResultOr<T>Andreas Kling
This makes it a lot easier to return errors since we no longer have to worry about negating EFOO errors and can just return them flat.
2021-02-23Everywhere: Rename ASSERT => VERIFYAndreas Kling
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED) Since all of these checks are done in release builds as well, let's rename them to VERIFY to prevent confusion, as everyone is used to assertions being compiled out in release. We can introduce a new ASSERT macro that is specifically for debug checks, but I'm doing this wholesale conversion first since we've accumulated thousands of these already, and it's not immediately obvious which ones are suitable for ASSERT.
2020-12-26Kernel: Allow 'elevating' unveil permissions if implicitly inherited from '/'AnotherTest
This can happen when an unveil follows another with a path that is a sub-path of the other one: ```c++ unveil("/home/anon/.config/whoa.ini", "rw"); unveil("/home/anon", "r"); // this would fail, as "/home/anon" inherits // the permissions of "/", which is None. ```
2020-12-26Kernel: Implement unveil() as a prefix-treeAnotherTest
Fixes #4530.
2020-11-23Kernel: Add unveil('b')Sergey Bugaev
This is a new "browse" permission that lets you open (and subsequently list contents of) directories underneath the path, but not regular files or any other types of files.
2020-11-10Kernel: Prevent `unveil` returning ENOENT with cpath permissionsJesse Buhagiar
This addresses the issue first enountered in #3644. If a path is first unveiled with "c" permissions, we should NOT return ENOENT if the node does not exist on the disk, as the program will most likely be creating it at a later time.
2020-09-13Kernel: Make copy_to/from_user safe and remove unnecessary checksTom
Since the CPU already does almost all necessary validation steps for us, we don't really need to attempt to do this. Doing it ourselves doesn't really work very reliably, because we'd have to account for other processors modifying virtual memory, and we'd have to account for e.g. pages not being able to be allocated due to insufficient resources. So change the copy_to/from_user (and associated helper functions) to use the new safe_memcpy, which will return whether it succeeded or not. The only manual validation step needed (which the CPU can't perform for us) is making sure the pointers provided by user mode aren't pointing to kernel mappings. To make it easier to read/write from/to either kernel or user mode data add the UserOrKernelBuffer helper class, which will internally either use copy_from/to_user or directly memcpy, or pass the data through directly using a temporary buffer on the stack. Last but not least we need to keep syscall params trivial as we need to copy them from/to user mode using copy_from/to_user.
2020-08-03Kernel: Use for-each loops in unveil syscallBrian Gianforcaro
2020-08-02Kernel: Use Userspace<T> in unveil syscallBrian Gianforcaro
2020-07-30Kernel: Move syscall implementations out of Process.cppAndreas Kling
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. :^)