summaryrefslogtreecommitdiff
path: root/Kernel/Net
diff options
context:
space:
mode:
authorBen Wiederhake <BenWiederhake.GitHub@gmx.de>2021-02-21 20:28:20 +0100
committerAndreas Kling <kling@serenityos.org>2021-03-02 08:36:08 +0100
commit859824019390ae5b1d2da79fe682e2fff56f69d8 (patch)
tree07acf2da49df547940ec058c246526991ce52ee6 /Kernel/Net
parent649abc01bcacd67abebdbc23c89a3a9b9917fc8f (diff)
downloadserenity-859824019390ae5b1d2da79fe682e2fff56f69d8.zip
Kernel: Sanitize all user-supplied timeval's/timespec's
This also removes a bunch of unnecessary EINVAL. Most of them weren't even recommended by POSIX.
Diffstat (limited to 'Kernel/Net')
-rw-r--r--Kernel/Net/Socket.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/Kernel/Net/Socket.cpp b/Kernel/Net/Socket.cpp
index a51e092a2a..0c25547244 100644
--- a/Kernel/Net/Socket.cpp
+++ b/Kernel/Net/Socket.cpp
@@ -106,14 +106,24 @@ KResult Socket::setsockopt(int level, int option, Userspace<const void*> user_va
case SO_SNDTIMEO:
if (user_value_size != sizeof(timeval))
return EINVAL;
- if (!copy_from_user(&m_send_timeout, static_ptr_cast<const timeval*>(user_value)))
- return EFAULT;
+ {
+ auto timeout = copy_time_from_user(static_ptr_cast<const timeval*>(user_value));
+ if (!timeout.has_value())
+ return EFAULT;
+ // FIXME: Should use AK::Time internally
+ m_send_timeout = timeout->to_timeval();
+ }
return KSuccess;
case SO_RCVTIMEO:
if (user_value_size != sizeof(timeval))
return EINVAL;
- if (!copy_from_user(&m_receive_timeout, static_ptr_cast<const timeval*>(user_value)))
- return EFAULT;
+ {
+ auto timeout = copy_time_from_user(static_ptr_cast<const timeval*>(user_value));
+ if (!timeout.has_value())
+ return EFAULT;
+ // FIXME: Should use AK::Time internally
+ m_receive_timeout = timeout->to_timeval();
+ }
return KSuccess;
case SO_BINDTODEVICE: {
if (user_value_size != IFNAMSIZ)