From 0b58fd5aef7b2b88913cc5645d7b7cbee3db93d0 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 16 Aug 2022 20:16:17 +0200 Subject: [PATCH] Kernel: Remove unnecessary TOCTOU bug in sys$pipe() We don't need to explicitly check for EMFILE conditions before doing anything in sys$pipe(). The fd allocation code will take care of it for us anyway. --- Kernel/Syscalls/pipe.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Kernel/Syscalls/pipe.cpp b/Kernel/Syscalls/pipe.cpp index 50f497555a..10c8c01f84 100644 --- a/Kernel/Syscalls/pipe.cpp +++ b/Kernel/Syscalls/pipe.cpp @@ -13,9 +13,7 @@ ErrorOr Process::sys$pipe(int pipefd[2], int flags) { VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this) TRY(require_promise(Pledge::stdio)); - auto open_count = fds().with_shared([](auto& fds) { return fds.open_count(); }); - if (open_count + 2 > OpenFileDescriptions::max_open()) - return EMFILE; + // Reject flags other than O_CLOEXEC, O_NONBLOCK if ((flags & (O_CLOEXEC | O_NONBLOCK)) != flags) return EINVAL;