Kernel: Prevent using copy_from_user() for timespec/timeval
These structs can be inconsistent, for example if the amount of microseconds is negative or larger than 1'000'000. Therefore, they should not be copied as-is. Use copy_time_from_user instead.
This commit is contained in:
parent
8598240193
commit
e510c41fd2
Notes:
sideshowbarker
2024-07-18 21:48:06 +09:00
Author: https://github.com/BenWiederhake Commit: https://github.com/SerenityOS/serenity/commit/e510c41fd2b Pull-request: https://github.com/SerenityOS/serenity/pull/5323 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/bgianfo
2 changed files with 22 additions and 0 deletions
|
@ -43,6 +43,7 @@ class String;
|
|||
class StringBuilder;
|
||||
class StringImpl;
|
||||
class StringView;
|
||||
class Time;
|
||||
class URL;
|
||||
class FlyString;
|
||||
class Utf32View;
|
||||
|
@ -175,6 +176,7 @@ using AK::String;
|
|||
using AK::StringBuilder;
|
||||
using AK::StringImpl;
|
||||
using AK::StringView;
|
||||
using AK::Time;
|
||||
using AK::Traits;
|
||||
using AK::URL;
|
||||
using AK::Utf32View;
|
||||
|
|
|
@ -102,6 +102,26 @@ template<typename T>
|
|||
return copy_from_user(dest, src.unsafe_userspace_ptr(), sizeof(T));
|
||||
}
|
||||
|
||||
#define DEPRECATE_COPY_FROM_USER_TYPE(T, REPLACEMENT) \
|
||||
template<> \
|
||||
[[nodiscard]] inline __attribute__((deprecated("use " #REPLACEMENT " instead"))) bool copy_from_user<T>(T*, const T*) \
|
||||
{ \
|
||||
VERIFY_NOT_REACHED(); \
|
||||
} \
|
||||
template<> \
|
||||
[[nodiscard]] inline __attribute__((deprecated("use " #REPLACEMENT " instead"))) bool copy_from_user<T>(T*, Userspace<const T*>) \
|
||||
{ \
|
||||
VERIFY_NOT_REACHED(); \
|
||||
} \
|
||||
template<> \
|
||||
[[nodiscard]] inline __attribute__((deprecated("use " #REPLACEMENT " instead"))) bool copy_from_user<T>(T*, Userspace<T*>) \
|
||||
{ \
|
||||
VERIFY_NOT_REACHED(); \
|
||||
}
|
||||
|
||||
DEPRECATE_COPY_FROM_USER_TYPE(timespec, copy_time_from_user)
|
||||
DEPRECATE_COPY_FROM_USER_TYPE(timeval, copy_time_from_user)
|
||||
|
||||
template<typename T>
|
||||
[[nodiscard]] inline bool copy_to_user(Userspace<T*> dest, const T* src)
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue