diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 557dc31f113..826a59d5b66 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -208,17 +208,24 @@ Region* Process::region_containing(const Range& range) return nullptr; } -int Process::sys$set_mmap_name(void* addr, size_t size, const char* name) +int Process::sys$set_mmap_name(const Syscall::SC_set_mmap_name_params* user_params) { - SmapDisabler disabler; - if (!validate_read_str(name)) + if (!validate_read_typed(user_params)) return -EFAULT; - auto* region = region_from_range({ VirtualAddress((u32)addr), size }); + + Syscall::SC_set_mmap_name_params params; + copy_from_user(¶ms, user_params, sizeof(params)); + + if (!validate_read(params.name, params.name_length)) + return -EFAULT; + auto name = copy_string_from_user(params.name, params.name_length); + + auto* region = region_from_range({ VirtualAddress((u32)params.addr), params.size }); if (!region) return -EINVAL; if (!region->is_mmap()) return -EPERM; - region->set_name(String(name)); + region->set_name(name); return 0; } diff --git a/Kernel/Process.h b/Kernel/Process.h index 61263fd0641..48faf6aaee4 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -136,7 +136,7 @@ public: pid_t sys$waitpid(pid_t, int* wstatus, int options); void* sys$mmap(const Syscall::SC_mmap_params*); int sys$munmap(void*, size_t size); - int sys$set_mmap_name(void*, size_t, const char*); + int sys$set_mmap_name(const Syscall::SC_set_mmap_name_params*); int sys$mprotect(void*, size_t, int prot); int sys$madvise(void*, size_t, int advice); int sys$purge(int mode); diff --git a/Kernel/Syscall.h b/Kernel/Syscall.h index 36b937ba05f..c8f462caad2 100644 --- a/Kernel/Syscall.h +++ b/Kernel/Syscall.h @@ -298,6 +298,13 @@ struct SC_realpath_params { size_t buffer_size; }; +struct SC_set_mmap_name_params { + void* addr; + size_t size; + const char* name; + size_t name_length; +}; + void initialize(); int sync(); diff --git a/Libraries/LibC/mman.cpp b/Libraries/LibC/mman.cpp index 3b084209315..777af713b16 100644 --- a/Libraries/LibC/mman.cpp +++ b/Libraries/LibC/mman.cpp @@ -2,6 +2,7 @@ #include #include #include +#include extern "C" { @@ -41,7 +42,12 @@ int mprotect(void* addr, size_t size, int prot) int set_mmap_name(void* addr, size_t size, const char* name) { - int rc = syscall(SC_set_mmap_name, addr, size, name); + if (!name) { + errno = EFAULT; + return -1; + } + Syscall::SC_set_mmap_name_params params { addr, size, name, strlen(name) }; + int rc = syscall(SC_set_mmap_name, ¶ms); __RETURN_WITH_ERRNO(rc, rc, -1); } @@ -50,5 +56,4 @@ int madvise(void* address, size_t size, int advice) int rc = syscall(SC_madvise, address, size, advice); __RETURN_WITH_ERRNO(rc, rc, -1); } - }