kernel: Implement FD limit check for select/poll.

The amount of FDs that can be selected/polled needs to be limited by
the RLIMIT_NOFILES.
This commit is contained in:
Michael Lotz
2018-04-04 00:09:23 +02:00
parent 321372e3ef
commit c101b57682
+13 -1
View File
@@ -906,6 +906,15 @@ _kern_wait_for_objects(object_wait_info* infos, int numInfos, uint32 flags,
// #pragma mark - User syscalls
static bool
check_max_fds(int numFDs)
{
struct io_context *context = get_current_io_context(false);
MutexLocker(&context->io_mutex);
return numFDs <= context->table_size;
}
ssize_t
_user_select(int numFDs, fd_set *userReadSet, fd_set *userWriteSet,
fd_set *userErrorSet, bigtime_t timeout, const sigset_t *userSigMask)
@@ -917,7 +926,7 @@ _user_select(int numFDs, fd_set *userReadSet, fd_set *userWriteSet,
syscall_restart_handle_timeout_pre(timeout);
if (numFDs < 0)
if (numFDs < 0 || !check_max_fds(numFDs))
return B_BAD_VALUE;
if ((userReadSet != NULL && !IS_USER_ADDRESS(userReadSet))
@@ -1013,6 +1022,9 @@ _user_poll(struct pollfd *userfds, int numFDs, bigtime_t timeout)
? syscall_restart_handle_timeout_post(result, timeout) : result;
}
if (!check_max_fds(numFDs))
return B_BAD_VALUE;
// copy parameters
if (userfds == NULL || !IS_USER_ADDRESS(userfds))
return B_BAD_ADDRESS;