mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 22:05:06 +00:00
Kernel: Remove char* versions of path argument / kstring copy methods
The only two paths for copying strings in the kernel should be going through the existing Userspace<char const*>, or StringArgument methods. Lets enforce this by removing the option for using the raw cstring APIs that were previously available.
This commit is contained in:
parent
5121e58d4a
commit
40a942d28b
6 changed files with 14 additions and 21 deletions
|
@ -42,16 +42,16 @@ String copy_string_from_user(Userspace<const char*> user_str, size_t user_str_si
|
|||
return copy_string_from_user(user_str.unsafe_userspace_ptr(), user_str_size);
|
||||
}
|
||||
|
||||
Kernel::KResultOr<NonnullOwnPtr<Kernel::KString>> try_copy_kstring_from_user(const char* user_str, size_t user_str_size)
|
||||
Kernel::KResultOr<NonnullOwnPtr<Kernel::KString>> try_copy_kstring_from_user(Userspace<const char*> user_str, size_t user_str_size)
|
||||
{
|
||||
bool is_user = Kernel::Memory::is_user_range(VirtualAddress(user_str), user_str_size);
|
||||
if (!is_user)
|
||||
return EFAULT;
|
||||
Kernel::SmapDisabler disabler;
|
||||
void* fault_at;
|
||||
ssize_t length = Kernel::safe_strnlen(user_str, user_str_size, fault_at);
|
||||
ssize_t length = Kernel::safe_strnlen(user_str.unsafe_userspace_ptr(), user_str_size, fault_at);
|
||||
if (length < 0) {
|
||||
dbgln("copy_kstring_from_user({:p}, {}) failed at {} (strnlen)", static_cast<const void*>(user_str), user_str_size, VirtualAddress { fault_at });
|
||||
dbgln("copy_kstring_from_user({:p}, {}) failed at {} (strnlen)", static_cast<const void*>(user_str.unsafe_userspace_ptr()), user_str_size, VirtualAddress { fault_at });
|
||||
return EFAULT;
|
||||
}
|
||||
char* buffer;
|
||||
|
@ -64,18 +64,13 @@ Kernel::KResultOr<NonnullOwnPtr<Kernel::KString>> try_copy_kstring_from_user(con
|
|||
if (length == 0)
|
||||
return new_string.release_nonnull();
|
||||
|
||||
if (!Kernel::safe_memcpy(buffer, user_str, (size_t)length, fault_at)) {
|
||||
dbgln("copy_kstring_from_user({:p}, {}) failed at {} (memcpy)", static_cast<const void*>(user_str), user_str_size, VirtualAddress { fault_at });
|
||||
if (!Kernel::safe_memcpy(buffer, user_str.unsafe_userspace_ptr(), (size_t)length, fault_at)) {
|
||||
dbgln("copy_kstring_from_user({:p}, {}) failed at {} (memcpy)", static_cast<const void*>(user_str.unsafe_userspace_ptr()), user_str_size, VirtualAddress { fault_at });
|
||||
return EFAULT;
|
||||
}
|
||||
return new_string.release_nonnull();
|
||||
}
|
||||
|
||||
Kernel::KResultOr<NonnullOwnPtr<Kernel::KString>> try_copy_kstring_from_user(Userspace<const char*> user_str, size_t user_str_size)
|
||||
{
|
||||
return try_copy_kstring_from_user(user_str.unsafe_userspace_ptr(), user_str_size);
|
||||
}
|
||||
|
||||
[[nodiscard]] Optional<Time> copy_time_from_user(const timespec* ts_user)
|
||||
{
|
||||
timespec ts;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue