mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-11 17:00:37 +00:00
Kernel: Use copy_typed_from_user<T> for fetching syscall parameters
This commit is contained in:
parent
d7e5768763
commit
789db813d3
Notes:
sideshowbarker
2024-07-18 04:41:47 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/789db813d39
24 changed files with 42 additions and 81 deletions
|
@ -23,8 +23,8 @@ KResultOr<FlatPtr> Process::sys$chown(Userspace<const Syscall::SC_chown_params*>
|
|||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
|
||||
REQUIRE_PROMISE(chown);
|
||||
Syscall::SC_chown_params params;
|
||||
TRY(copy_from_user(¶ms, user_params));
|
||||
auto params = TRY(copy_typed_from_user(user_params));
|
||||
|
||||
auto path = TRY(get_syscall_path_argument(params.path));
|
||||
return VirtualFileSystem::the().chown(path->view(), params.uid, params.gid, current_directory());
|
||||
}
|
||||
|
|
|
@ -66,9 +66,7 @@ KResultOr<FlatPtr> Process::sys$clock_nanosleep(Userspace<const Syscall::SC_cloc
|
|||
{
|
||||
VERIFY_NO_PROCESS_BIG_LOCK(this);
|
||||
REQUIRE_PROMISE(stdio);
|
||||
|
||||
Syscall::SC_clock_nanosleep_params params;
|
||||
TRY(copy_from_user(¶ms, user_params));
|
||||
auto params = TRY(copy_typed_from_user(user_params));
|
||||
|
||||
Optional<Time> requested_sleep = copy_time_from_user(params.requested_sleep);
|
||||
if (!requested_sleep.has_value())
|
||||
|
|
|
@ -939,8 +939,7 @@ KResultOr<FlatPtr> Process::sys$execve(Userspace<const Syscall::SC_execve_params
|
|||
|
||||
// NOTE: Be extremely careful with allocating any kernel memory in exec().
|
||||
// On success, the kernel stack will be lost.
|
||||
Syscall::SC_execve_params params;
|
||||
TRY(copy_from_user(¶ms, user_params));
|
||||
auto params = TRY(copy_typed_from_user(user_params));
|
||||
|
||||
if (params.arguments.length > ARG_MAX || params.environment.length > ARG_MAX)
|
||||
return E2BIG;
|
||||
|
|
|
@ -25,8 +25,7 @@ void Process::clear_futex_queues_on_exec()
|
|||
KResultOr<FlatPtr> Process::sys$futex(Userspace<const Syscall::SC_futex_params*> user_params)
|
||||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
|
||||
Syscall::SC_futex_params params;
|
||||
TRY(copy_from_user(¶ms, user_params));
|
||||
auto params = TRY(copy_typed_from_user(user_params));
|
||||
|
||||
Thread::BlockTimeout timeout;
|
||||
u32 cmd = params.futex_op & FUTEX_CMD_MASK;
|
||||
|
|
|
@ -46,9 +46,7 @@ KResultOr<FlatPtr> Process::sys$inode_watcher_add_watch(Userspace<const Syscall:
|
|||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||
REQUIRE_PROMISE(rpath);
|
||||
|
||||
Syscall::SC_inode_watcher_add_watch_params params;
|
||||
TRY(copy_from_user(¶ms, user_params));
|
||||
auto params = TRY(copy_typed_from_user(user_params));
|
||||
|
||||
auto description = fds().file_description(params.fd);
|
||||
if (!description)
|
||||
|
|
|
@ -19,8 +19,7 @@ KResultOr<FlatPtr> Process::sys$setkeymap(Userspace<const Syscall::SC_setkeymap_
|
|||
if (!is_superuser())
|
||||
return EPERM;
|
||||
|
||||
Syscall::SC_setkeymap_params params;
|
||||
TRY(copy_from_user(¶ms, user_params));
|
||||
auto params = TRY(copy_typed_from_user(user_params));
|
||||
|
||||
Keyboard::CharacterMapData character_map_data;
|
||||
|
||||
|
@ -44,9 +43,7 @@ KResultOr<FlatPtr> Process::sys$getkeymap(Userspace<const Syscall::SC_getkeymap_
|
|||
{
|
||||
VERIFY_NO_PROCESS_BIG_LOCK(this);
|
||||
REQUIRE_PROMISE(getkeymap);
|
||||
|
||||
Syscall::SC_getkeymap_params params {};
|
||||
TRY(copy_from_user(¶ms, user_params));
|
||||
auto params = TRY(copy_typed_from_user(user_params));
|
||||
|
||||
String keymap_name = HIDManagement::the().keymap_name();
|
||||
const Keyboard::CharacterMapData& character_maps = HIDManagement::the().character_maps();
|
||||
|
|
|
@ -14,8 +14,7 @@ KResultOr<FlatPtr> Process::sys$link(Userspace<const Syscall::SC_link_params*> u
|
|||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||
REQUIRE_PROMISE(cpath);
|
||||
Syscall::SC_link_params params;
|
||||
TRY(copy_from_user(¶ms, user_params));
|
||||
auto params = TRY(copy_typed_from_user(user_params));
|
||||
auto old_path = TRY(try_copy_kstring_from_user(params.old_path));
|
||||
auto new_path = TRY(try_copy_kstring_from_user(params.new_path));
|
||||
return VirtualFileSystem::the().link(old_path->view(), new_path->view(), current_directory());
|
||||
|
@ -25,8 +24,8 @@ KResultOr<FlatPtr> Process::sys$symlink(Userspace<const Syscall::SC_symlink_para
|
|||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||
REQUIRE_PROMISE(cpath);
|
||||
Syscall::SC_symlink_params params;
|
||||
TRY(copy_from_user(¶ms, user_params));
|
||||
auto params = TRY(copy_typed_from_user(user_params));
|
||||
|
||||
auto target = TRY(get_syscall_path_argument(params.target));
|
||||
auto linkpath = TRY(get_syscall_path_argument(params.linkpath));
|
||||
return VirtualFileSystem::the().symlink(target->view(), linkpath->view(), current_directory());
|
||||
|
|
|
@ -14,8 +14,8 @@ KResultOr<FlatPtr> Process::sys$mknod(Userspace<const Syscall::SC_mknod_params*>
|
|||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||
REQUIRE_PROMISE(dpath);
|
||||
Syscall::SC_mknod_params params;
|
||||
TRY(copy_from_user(¶ms, user_params));
|
||||
auto params = TRY(copy_typed_from_user(user_params));
|
||||
|
||||
if (!is_superuser() && !is_regular_file(params.mode) && !is_fifo(params.mode) && !is_socket(params.mode))
|
||||
return EPERM;
|
||||
auto path = TRY(get_syscall_path_argument(params.path));
|
||||
|
|
|
@ -128,9 +128,7 @@ KResultOr<FlatPtr> Process::sys$mmap(Userspace<const Syscall::SC_mmap_params*> u
|
|||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||
REQUIRE_PROMISE(stdio);
|
||||
|
||||
Syscall::SC_mmap_params params;
|
||||
TRY(copy_from_user(¶ms, user_params));
|
||||
auto params = TRY(copy_typed_from_user(user_params));
|
||||
|
||||
FlatPtr addr = params.addr;
|
||||
auto size = params.size;
|
||||
|
@ -467,9 +465,7 @@ KResultOr<FlatPtr> Process::sys$set_mmap_name(Userspace<const Syscall::SC_set_mm
|
|||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||
REQUIRE_PROMISE(stdio);
|
||||
|
||||
Syscall::SC_set_mmap_name_params params;
|
||||
TRY(copy_from_user(¶ms, user_params));
|
||||
auto params = TRY(copy_typed_from_user(user_params));
|
||||
|
||||
if (params.name.length > PATH_MAX)
|
||||
return ENAMETOOLONG;
|
||||
|
@ -504,9 +500,7 @@ KResultOr<FlatPtr> Process::sys$mremap(Userspace<const Syscall::SC_mremap_params
|
|||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||
REQUIRE_PROMISE(stdio);
|
||||
|
||||
Syscall::SC_mremap_params params {};
|
||||
TRY(copy_from_user(¶ms, user_params));
|
||||
auto params = TRY(copy_typed_from_user(user_params));
|
||||
|
||||
auto old_range = TRY(expand_range_to_page_boundaries((FlatPtr)params.old_address, params.old_size));
|
||||
|
||||
|
|
|
@ -25,9 +25,7 @@ KResultOr<FlatPtr> Process::sys$mount(Userspace<const Syscall::SC_mount_params*>
|
|||
return EPERM;
|
||||
|
||||
REQUIRE_NO_PROMISES;
|
||||
|
||||
Syscall::SC_mount_params params;
|
||||
TRY(copy_from_user(¶ms, user_params));
|
||||
auto params = TRY(copy_typed_from_user(user_params));
|
||||
|
||||
auto source_fd = params.source_fd;
|
||||
auto target_or_error = try_copy_kstring_from_user(params.target);
|
||||
|
|
|
@ -14,8 +14,7 @@ namespace Kernel {
|
|||
KResultOr<FlatPtr> Process::sys$open(Userspace<const Syscall::SC_open_params*> user_params)
|
||||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||
Syscall::SC_open_params params;
|
||||
TRY(copy_from_user(¶ms, user_params));
|
||||
auto params = TRY(copy_typed_from_user(user_params));
|
||||
|
||||
int dirfd = params.dirfd;
|
||||
int options = params.options;
|
||||
|
|
|
@ -12,8 +12,7 @@ namespace Kernel {
|
|||
KResultOr<FlatPtr> Process::sys$pledge(Userspace<const Syscall::SC_pledge_params*> user_params)
|
||||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||
Syscall::SC_pledge_params params;
|
||||
TRY(copy_from_user(¶ms, user_params));
|
||||
auto params = TRY(copy_typed_from_user(user_params));
|
||||
|
||||
if (params.promises.length > 1024 || params.execpromises.length > 1024)
|
||||
return E2BIG;
|
||||
|
|
|
@ -53,8 +53,8 @@ KResultOr<FlatPtr> Process::sys$set_process_name(Userspace<const char*> user_nam
|
|||
KResultOr<FlatPtr> Process::sys$set_coredump_metadata(Userspace<const Syscall::SC_set_coredump_metadata_params*> user_params)
|
||||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||
Syscall::SC_set_coredump_metadata_params params;
|
||||
TRY(copy_from_user(¶ms, user_params));
|
||||
auto params = TRY(copy_typed_from_user(user_params));
|
||||
|
||||
if (params.key.length == 0 || params.key.length > 16 * KiB)
|
||||
return EINVAL;
|
||||
if (params.value.length > 16 * KiB)
|
||||
|
|
|
@ -148,8 +148,8 @@ KResultOr<FlatPtr> Process::sys$ptrace(Userspace<const Syscall::SC_ptrace_params
|
|||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||
REQUIRE_PROMISE(ptrace);
|
||||
Syscall::SC_ptrace_params params {};
|
||||
TRY(copy_from_user(¶ms, user_params));
|
||||
auto params = TRY(copy_typed_from_user(user_params));
|
||||
|
||||
auto result = handle_ptrace(params, *this);
|
||||
return result.is_error() ? result.error().error() : result.value();
|
||||
}
|
||||
|
|
|
@ -14,9 +14,7 @@ KResultOr<FlatPtr> Process::sys$readlink(Userspace<const Syscall::SC_readlink_pa
|
|||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||
REQUIRE_PROMISE(rpath);
|
||||
|
||||
Syscall::SC_readlink_params params;
|
||||
TRY(copy_from_user(¶ms, user_params));
|
||||
auto params = TRY(copy_typed_from_user(user_params));
|
||||
|
||||
auto path = get_syscall_path_argument(params.path);
|
||||
if (path.is_error())
|
||||
|
|
|
@ -15,9 +15,7 @@ KResultOr<FlatPtr> Process::sys$realpath(Userspace<const Syscall::SC_realpath_pa
|
|||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||
REQUIRE_PROMISE(rpath);
|
||||
|
||||
Syscall::SC_realpath_params params;
|
||||
TRY(copy_from_user(¶ms, user_params));
|
||||
auto params = TRY(copy_typed_from_user(user_params));
|
||||
|
||||
auto path = get_syscall_path_argument(params.path);
|
||||
if (path.is_error())
|
||||
|
|
|
@ -14,8 +14,8 @@ KResultOr<FlatPtr> Process::sys$rename(Userspace<const Syscall::SC_rename_params
|
|||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||
REQUIRE_PROMISE(cpath);
|
||||
Syscall::SC_rename_params params;
|
||||
TRY(copy_from_user(¶ms, user_params));
|
||||
auto params = TRY(copy_typed_from_user(user_params));
|
||||
|
||||
auto old_path = get_syscall_path_argument(params.old_path);
|
||||
if (old_path.is_error())
|
||||
return old_path.error();
|
||||
|
|
|
@ -18,9 +18,8 @@ KResultOr<FlatPtr> Process::sys$select(Userspace<const Syscall::SC_select_params
|
|||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||
REQUIRE_PROMISE(stdio);
|
||||
Syscall::SC_select_params params {};
|
||||
|
||||
TRY(copy_from_user(¶ms, user_params));
|
||||
auto params = TRY(copy_typed_from_user(user_params));
|
||||
|
||||
if (params.nfds < 0)
|
||||
return EINVAL;
|
||||
|
@ -132,9 +131,7 @@ KResultOr<FlatPtr> Process::sys$poll(Userspace<const Syscall::SC_poll_params*> u
|
|||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||
REQUIRE_PROMISE(stdio);
|
||||
|
||||
Syscall::SC_poll_params params {};
|
||||
TRY(copy_from_user(¶ms, user_params));
|
||||
auto params = TRY(copy_typed_from_user(user_params));
|
||||
|
||||
if (params.nfds >= fds().max_open())
|
||||
return ENOBUFS;
|
||||
|
|
|
@ -79,9 +79,7 @@ KResultOr<FlatPtr> Process::sys$accept4(Userspace<const Syscall::SC_accept4_para
|
|||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||
REQUIRE_PROMISE(accept);
|
||||
|
||||
Syscall::SC_accept4_params params = {};
|
||||
TRY(copy_from_user(¶ms, user_params));
|
||||
auto params = TRY(copy_typed_from_user(user_params));
|
||||
|
||||
int accepting_socket_fd = params.sockfd;
|
||||
Userspace<sockaddr*> user_address((FlatPtr)params.addr);
|
||||
|
@ -307,24 +305,21 @@ KResult Process::get_sock_or_peer_name(const Params& params)
|
|||
KResultOr<FlatPtr> Process::sys$getsockname(Userspace<const Syscall::SC_getsockname_params*> user_params)
|
||||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||
Syscall::SC_getsockname_params params = {};
|
||||
TRY(copy_from_user(¶ms, user_params));
|
||||
auto params = TRY(copy_typed_from_user(user_params));
|
||||
return get_sock_or_peer_name<true>(params);
|
||||
}
|
||||
|
||||
KResultOr<FlatPtr> Process::sys$getpeername(Userspace<const Syscall::SC_getpeername_params*> user_params)
|
||||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||
Syscall::SC_getpeername_params params = {};
|
||||
TRY(copy_from_user(¶ms, user_params));
|
||||
auto params = TRY(copy_typed_from_user(user_params));
|
||||
return get_sock_or_peer_name<false>(params);
|
||||
}
|
||||
|
||||
KResultOr<FlatPtr> Process::sys$getsockopt(Userspace<const Syscall::SC_getsockopt_params*> user_params)
|
||||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||
Syscall::SC_getsockopt_params params = {};
|
||||
TRY(copy_from_user(¶ms, user_params));
|
||||
auto params = TRY(copy_typed_from_user(user_params));
|
||||
|
||||
int sockfd = params.sockfd;
|
||||
int level = params.level;
|
||||
|
@ -349,8 +344,8 @@ KResultOr<FlatPtr> Process::sys$getsockopt(Userspace<const Syscall::SC_getsockop
|
|||
KResultOr<FlatPtr> Process::sys$setsockopt(Userspace<const Syscall::SC_setsockopt_params*> user_params)
|
||||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||
Syscall::SC_setsockopt_params params;
|
||||
TRY(copy_from_user(¶ms, user_params));
|
||||
auto params = TRY(copy_typed_from_user(user_params));
|
||||
|
||||
Userspace<const void*> user_value((FlatPtr)params.value);
|
||||
auto description = fds().file_description(params.sockfd);
|
||||
if (!description)
|
||||
|
@ -365,8 +360,7 @@ KResultOr<FlatPtr> Process::sys$setsockopt(Userspace<const Syscall::SC_setsockop
|
|||
KResultOr<FlatPtr> Process::sys$socketpair(Userspace<const Syscall::SC_socketpair_params*> user_params)
|
||||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||
Syscall::SC_socketpair_params params;
|
||||
TRY(copy_from_user(¶ms, user_params));
|
||||
auto params = TRY(copy_typed_from_user(user_params));
|
||||
|
||||
if (params.domain != AF_LOCAL)
|
||||
return EINVAL;
|
||||
|
|
|
@ -27,8 +27,8 @@ KResultOr<FlatPtr> Process::sys$stat(Userspace<const Syscall::SC_stat_params*> u
|
|||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||
REQUIRE_PROMISE(rpath);
|
||||
Syscall::SC_stat_params params;
|
||||
TRY(copy_from_user(¶ms, user_params));
|
||||
auto params = TRY(copy_typed_from_user(user_params));
|
||||
|
||||
auto path = get_syscall_path_argument(params.path);
|
||||
if (path.is_error())
|
||||
return path.error();
|
||||
|
|
|
@ -69,9 +69,8 @@ KResultOr<FlatPtr> Process::sys$statvfs(Userspace<const Syscall::SC_statvfs_para
|
|||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||
REQUIRE_PROMISE(rpath);
|
||||
auto params = TRY(copy_typed_from_user(user_params));
|
||||
|
||||
Syscall::SC_statvfs_params params;
|
||||
TRY(copy_from_user(¶ms, user_params));
|
||||
auto path = get_syscall_path_argument(params.path);
|
||||
if (path.is_error())
|
||||
return path.error();
|
||||
|
|
|
@ -17,9 +17,7 @@ KResultOr<FlatPtr> Process::sys$create_thread(void* (*entry)(void*), Userspace<c
|
|||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||
REQUIRE_PROMISE(thread);
|
||||
|
||||
Syscall::SC_create_thread_params params;
|
||||
TRY(copy_from_user(¶ms, user_params));
|
||||
auto params = TRY(copy_typed_from_user(user_params));
|
||||
|
||||
unsigned detach_state = params.detach_state;
|
||||
int schedule_priority = params.schedule_priority;
|
||||
|
|
|
@ -27,8 +27,7 @@ static void update_intermediate_node_permissions(UnveilNode& root_node, UnveilAc
|
|||
KResultOr<FlatPtr> Process::sys$unveil(Userspace<const Syscall::SC_unveil_params*> user_params)
|
||||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||
Syscall::SC_unveil_params params;
|
||||
TRY(copy_from_user(¶ms, user_params));
|
||||
auto params = TRY(copy_typed_from_user(user_params));
|
||||
|
||||
if (!params.path.characters && !params.permissions.characters) {
|
||||
m_veil_state = VeilState::Locked;
|
||||
|
|
|
@ -23,9 +23,7 @@ KResultOr<FlatPtr> Process::sys$waitid(Userspace<const Syscall::SC_waitid_params
|
|||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||
REQUIRE_PROMISE(proc);
|
||||
|
||||
Syscall::SC_waitid_params params;
|
||||
TRY(copy_from_user(¶ms, user_params));
|
||||
auto params = TRY(copy_typed_from_user(user_params));
|
||||
|
||||
Variant<Empty, NonnullRefPtr<Process>, NonnullRefPtr<ProcessGroup>> waitee = Empty {};
|
||||
switch (params.idtype) {
|
||||
|
|
Loading…
Reference in a new issue