From 9c4845e7678a4b508212e6adbb57084a4cd9a2a5 Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Fri, 6 Apr 2018 21:05:45 +0200 Subject: [PATCH] kernel: Implement wait info count limit in wait_for_objects. Since wait_for_objects can wait on sems, threads and ports in addition to FDs, limiting to RLIMIT_NOFILES as in the select/poll case does not work. Since space is allocated for the wait objects in kernel memory, limiting their number to a valid range is still desireable. The limit is now placed at the sum of max sem, thread and port count plus RLIMIT_NOFILES. This also fixes a signed vs. unsigned comparison warning in check_max_fds introduced in hrev51866. --- src/system/kernel/wait_for_objects.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/system/kernel/wait_for_objects.cpp b/src/system/kernel/wait_for_objects.cpp index edc3b8a286..737a85130e 100644 --- a/src/system/kernel/wait_for_objects.cpp +++ b/src/system/kernel/wait_for_objects.cpp @@ -909,9 +909,12 @@ _kern_wait_for_objects(object_wait_info* infos, int numInfos, uint32 flags, static bool check_max_fds(int numFDs) { + if (numFDs <= 0) + return true; + struct io_context *context = get_current_io_context(false); MutexLocker(&context->io_mutex); - return numFDs <= context->table_size; + return (size_t)numFDs <= context->table_size; } @@ -1060,8 +1063,11 @@ _user_wait_for_objects(object_wait_info* userInfos, int numInfos, uint32 flags, { syscall_restart_handle_timeout_pre(flags, timeout); - if (numInfos < 0) + bigtime_t start = system_time(); + if (numInfos < 0 || !check_max_fds(numInfos - sem_max_sems() + - port_max_ports() - thread_max_threads())) { return B_BAD_VALUE; + } if (numInfos == 0) { // special case: no infos