summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorRodrigo Tobar <rtobarc@gmail.com>2021-10-11 21:47:21 +0800
committerBrian Gianforcaro <b.gianfo@gmail.com>2021-10-11 10:46:01 -0700
commitbf4e536f00232acd6dc42f57eda9d916c7dd746b (patch)
tree623e2f835f7da72d9493edf52042464f58de9a03 /Kernel
parent01a716d529433d4d6344ada32862bbf663db7a73 (diff)
downloadserenity-bf4e536f00232acd6dc42f57eda9d916c7dd746b.zip
Kernel: Correctly interpret ioctl's FIONBIO user value
Values in `ioctl` are given through a pointer, but ioctl's FIONBIO implementation was interpreting this pointer as an integer directly. This meant that programs using `ioctl` to set a file descriptor in blocking mode met with incorrect behavior: they passed a non-null pointer pointing to a value of 0, but the kernel interpreted the pointer as a non-zero integer, thus making the file non-blocking. This commit fixes this behavior by reading the value from the userspace pointer and using that to set the non-blocking flag on the file descriptor. This bug was found while trying to run the openssl tool on serenity, which used `ioctl` to ensure newly-created sockets are in blocking mode.
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/Syscalls/ioctl.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/Kernel/Syscalls/ioctl.cpp b/Kernel/Syscalls/ioctl.cpp
index b5b078186e..0f2a675dfd 100644
--- a/Kernel/Syscalls/ioctl.cpp
+++ b/Kernel/Syscalls/ioctl.cpp
@@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <AK/Userspace.h>
#include <Kernel/FileSystem/OpenFileDescription.h>
#include <Kernel/Process.h>
#include <LibC/sys/ioctl_numbers.h>
@@ -15,7 +16,9 @@ KResultOr<FlatPtr> Process::sys$ioctl(int fd, unsigned request, FlatPtr arg)
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
auto description = TRY(fds().open_file_description(fd));
if (request == FIONBIO) {
- description->set_blocking(arg == 0);
+ int non_blocking;
+ TRY(copy_from_user(&non_blocking, Userspace<const int*>(arg)));
+ description->set_blocking(non_blocking == 0);
return KSuccess;
}
return description->file().ioctl(*description, request, arg);