mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-23 01:32:14 -05:00
Kernel: Add checks for is_trivially_copyable to copy_to/from_user
If we're copying structures, we only ever want to copy trivially copyable structures.
This commit is contained in:
parent
bb92eab9ce
commit
87f20f704c
Notes:
sideshowbarker
2024-07-19 02:06:06 +09:00
Author: https://github.com/tomuta Commit: https://github.com/SerenityOS/serenity/commit/87f20f704cc Pull-request: https://github.com/SerenityOS/serenity/pull/3651 Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/bugaevc
1 changed files with 11 additions and 0 deletions
|
@ -61,48 +61,56 @@ inline u16 htons(u16 w) { return (w & 0xff) << 8 | ((w >> 8) & 0xff); }
|
|||
template<typename T>
|
||||
[[nodiscard]] inline bool copy_from_user(T* dest, const T* src)
|
||||
{
|
||||
static_assert(is_trivially_copyable<T>());
|
||||
return copy_from_user(dest, src, sizeof(T));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
[[nodiscard]] inline bool copy_to_user(T* dest, const T* src)
|
||||
{
|
||||
static_assert(is_trivially_copyable<T>());
|
||||
return copy_to_user(dest, src, sizeof(T));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
[[nodiscard]] inline bool copy_from_user(T* dest, Userspace<const T*> src)
|
||||
{
|
||||
static_assert(is_trivially_copyable<T>());
|
||||
return copy_from_user(dest, src.unsafe_userspace_ptr(), sizeof(T));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
[[nodiscard]] inline bool copy_from_user(T* dest, Userspace<T*> src)
|
||||
{
|
||||
static_assert(is_trivially_copyable<T>());
|
||||
return copy_from_user(dest, src.unsafe_userspace_ptr(), sizeof(T));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
[[nodiscard]] inline bool copy_to_user(Userspace<T*> dest, const T* src)
|
||||
{
|
||||
static_assert(is_trivially_copyable<T>());
|
||||
return copy_to_user(dest.unsafe_userspace_ptr(), src, sizeof(T));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
[[nodiscard]] inline bool copy_to_user(Userspace<T*> dest, const void* src, size_t size)
|
||||
{
|
||||
static_assert(is_trivially_copyable<T>());
|
||||
return copy_to_user(dest.unsafe_userspace_ptr(), src, size);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
[[nodiscard]] inline bool copy_from_user(void* dest, Userspace<const T*> src, size_t size)
|
||||
{
|
||||
static_assert(is_trivially_copyable<T>());
|
||||
return copy_from_user(dest, src.unsafe_userspace_ptr(), size);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
[[nodiscard]] inline bool copy_n_from_user(T* dest, const T* src, size_t count)
|
||||
{
|
||||
static_assert(is_trivially_copyable<T>());
|
||||
Checked size = sizeof(T);
|
||||
size *= count;
|
||||
if (size.has_overflow())
|
||||
|
@ -113,6 +121,7 @@ template<typename T>
|
|||
template<typename T>
|
||||
[[nodiscard]] inline bool copy_n_to_user(T* dest, const T* src, size_t count)
|
||||
{
|
||||
static_assert(is_trivially_copyable<T>());
|
||||
Checked size = sizeof(T);
|
||||
size *= count;
|
||||
if (size.has_overflow())
|
||||
|
@ -123,6 +132,7 @@ template<typename T>
|
|||
template<typename T>
|
||||
[[nodiscard]] inline bool copy_n_from_user(T* dest, Userspace<const T*> src, size_t count)
|
||||
{
|
||||
static_assert(is_trivially_copyable<T>());
|
||||
Checked size = sizeof(T);
|
||||
size *= count;
|
||||
if (size.has_overflow())
|
||||
|
@ -133,6 +143,7 @@ template<typename T>
|
|||
template<typename T>
|
||||
[[nodiscard]] inline bool copy_n_to_user(Userspace<T*> dest, const T* src, size_t count)
|
||||
{
|
||||
static_assert(is_trivially_copyable<T>());
|
||||
Checked size = sizeof(T);
|
||||
size *= count;
|
||||
if (size.has_overflow())
|
||||
|
|
Loading…
Reference in a new issue