Skip to content

Commit

Permalink
Kernel: Migrate sys$unveil to use the KString API
Browse files Browse the repository at this point in the history
This avoids potential unhandled OOM that's possible with the old
copy_string_from_user API.
  • Loading branch information
bgianfo authored and awesomekling committed Jul 23, 2021
1 parent 2e7728b commit baec9e2
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Kernel/Syscalls/unveil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,17 @@ KResultOr<FlatPtr> Process::sys$unveil(Userspace<const Syscall::SC_unveil_params
if (path.is_empty() || !path.view().starts_with('/'))
return EINVAL;

auto permissions = copy_string_from_user(params.permissions);
if (permissions.is_null())
return EFAULT;
OwnPtr<KString> permissions;
{
auto permissions_or_error = try_copy_kstring_from_user(params.permissions);
if (permissions_or_error.is_error())
return permissions_or_error.error();
permissions = permissions_or_error.release_value();
}

// Let's work out permissions first...
unsigned new_permissions = 0;
for (const char permission : permissions) {
for (const char permission : permissions->view()) {
switch (permission) {
case 'r':
new_permissions |= UnveilAccess::Read;
Expand Down

0 comments on commit baec9e2

Please sign in to comment.