Browse Source

Kernel: Harden sys$readv / sys$writev Vector usage against OOM.

Brian Gianforcaro 4 years ago
parent
commit
454d2fd42a
2 changed files with 4 additions and 2 deletions
  1. 2 1
      Kernel/Syscalls/read.cpp
  2. 2 1
      Kernel/Syscalls/write.cpp

+ 2 - 1
Kernel/Syscalls/read.cpp

@@ -24,7 +24,8 @@ KResultOr<ssize_t> Process::sys$readv(int fd, Userspace<const struct iovec*> iov
 
 
     u64 total_length = 0;
     u64 total_length = 0;
     Vector<iovec, 32> vecs;
     Vector<iovec, 32> vecs;
-    vecs.resize(iov_count);
+    if (!vecs.try_resize(iov_count))
+        return ENOMEM;
     if (!copy_n_from_user(vecs.data(), iov, iov_count))
     if (!copy_n_from_user(vecs.data(), iov, iov_count))
         return EFAULT;
         return EFAULT;
     for (auto& vec : vecs) {
     for (auto& vec : vecs) {

+ 2 - 1
Kernel/Syscalls/write.cpp

@@ -23,7 +23,8 @@ KResultOr<ssize_t> Process::sys$writev(int fd, Userspace<const struct iovec*> io
 
 
     u64 total_length = 0;
     u64 total_length = 0;
     Vector<iovec, 32> vecs;
     Vector<iovec, 32> vecs;
-    vecs.resize(iov_count);
+    if (!vecs.try_resize(iov_count))
+        return ENOMEM;
     if (!copy_n_from_user(vecs.data(), iov, iov_count))
     if (!copy_n_from_user(vecs.data(), iov, iov_count))
         return EFAULT;
         return EFAULT;
     for (auto& vec : vecs) {
     for (auto& vec : vecs) {