summaryrefslogtreecommitdiff
path: root/Kernel/Syscalls/uname.cpp
diff options
context:
space:
mode:
authorBrian Gianforcaro <b.gianfo@gmail.com>2020-08-09 13:02:27 -0700
committerAndreas Kling <kling@serenityos.org>2020-08-10 12:52:15 +0200
commit8dd78201a449ac9eafa1abf151ce21147495ba86 (patch)
tree8ee3aa2b2e3b3c140cda0eb04155224bd6f596e9 /Kernel/Syscalls/uname.cpp
parentcfedd62b5c76fb83cecaef59edc653970c4c2869 (diff)
downloadserenity-8dd78201a449ac9eafa1abf151ce21147495ba86.zip
Kernel: Use Userspace<T> for the uname syscall
Diffstat (limited to 'Kernel/Syscalls/uname.cpp')
-rw-r--r--Kernel/Syscalls/uname.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/Kernel/Syscalls/uname.cpp b/Kernel/Syscalls/uname.cpp
index 140e084b37..33172798dd 100644
--- a/Kernel/Syscalls/uname.cpp
+++ b/Kernel/Syscalls/uname.cpp
@@ -28,7 +28,7 @@
namespace Kernel {
-int Process::sys$uname(utsname* buf)
+int Process::sys$uname(Userspace<utsname*> buf)
{
extern String* g_hostname;
extern Lock* g_hostname_lock;
@@ -36,14 +36,20 @@ int Process::sys$uname(utsname* buf)
REQUIRE_PROMISE(stdio);
if (!validate_write_typed(buf))
return -EFAULT;
+
+
LOCKER(*g_hostname_lock, Lock::Mode::Shared);
if (g_hostname->length() + 1 > sizeof(utsname::nodename))
return -ENAMETOOLONG;
- copy_to_user(buf->sysname, "SerenityOS", 11);
- copy_to_user(buf->release, "1.0-dev", 8);
- copy_to_user(buf->version, "FIXME", 6);
- copy_to_user(buf->machine, "i686", 5);
- copy_to_user(buf->nodename, g_hostname->characters(), g_hostname->length() + 1);
+
+ // We have already validated the entire utsname struct at this
+ // point, there is no need to re-validate every write to the struct.
+ utsname* user_buf = buf.unsafe_userspace_ptr();
+ copy_to_user(user_buf->sysname, "SerenityOS", 11);
+ copy_to_user(user_buf->release, "1.0-dev", 8);
+ copy_to_user(user_buf->version, "FIXME", 6);
+ copy_to_user(user_buf->machine, "i686", 5);
+ copy_to_user(user_buf->nodename, g_hostname->characters(), g_hostname->length() + 1);
return 0;
}