summaryrefslogtreecommitdiff
path: root/Kernel/StdLib.h
diff options
context:
space:
mode:
authorBen Wiederhake <BenWiederhake.GitHub@gmx.de>2021-02-13 11:33:28 +0100
committerAndreas Kling <kling@serenityos.org>2021-03-02 08:36:08 +0100
commite510c41fd2b26bacc197b200d309c09a4a6ecf2c (patch)
tree45ed1776a575a7aa13b030784c6bdec086e56f6e /Kernel/StdLib.h
parent859824019390ae5b1d2da79fe682e2fff56f69d8 (diff)
downloadserenity-e510c41fd2b26bacc197b200d309c09a4a6ecf2c.zip
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.
Diffstat (limited to 'Kernel/StdLib.h')
-rw-r--r--Kernel/StdLib.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/Kernel/StdLib.h b/Kernel/StdLib.h
index 129cb1d470..c00447b8b1 100644
--- a/Kernel/StdLib.h
+++ b/Kernel/StdLib.h
@@ -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)
{