]> git.proxmox.com Git - mirror_qemu.git/commitdiff
linux-user: Check for bad event numbers in epoll_wait
authorPeter Maydell <peter.maydell@linaro.org>
Mon, 18 Jul 2016 14:35:59 +0000 (15:35 +0100)
committerRiku Voipio <riku.voipio@linaro.org>
Wed, 21 Sep 2016 11:25:26 +0000 (14:25 +0300)
The kernel checks that the maxevents parameter to epoll_wait
is non-negative and not larger than EP_MAX_EVENTS. Add this
check to our implementation, so that:
 * we fail these cases EINVAL rather than EFAULT
 * we don't pass negative or overflowing values to the
   lock_user() size calculation

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
linux-user/syscall.c
linux-user/syscall_defs.h

index 21ae996dd16582df2dab2cc54011590ed3d1fb2b..eecccbb25c516fd342d4ca1bd0b3755bd9a45023 100644 (file)
@@ -11501,6 +11501,11 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         int maxevents = arg3;
         int timeout = arg4;
 
+        if (maxevents <= 0 || maxevents > TARGET_EP_MAX_EVENTS) {
+            ret = -TARGET_EINVAL;
+            break;
+        }
+
         target_ep = lock_user(VERIFY_WRITE, arg2,
                               maxevents * sizeof(struct target_epoll_event), 1);
         if (!target_ep) {
index c0e5cb0010ba7ed32e0a659d3acdb988f3aaaf7a..5c19c5ca192f88e409a84e3931503d4cb8c0960d 100644 (file)
@@ -2585,6 +2585,9 @@ struct target_epoll_event {
     abi_uint events;
     target_epoll_data_t data;
 } TARGET_EPOLL_PACKED;
+
+#define TARGET_EP_MAX_EVENTS (INT_MAX / sizeof(struct target_epoll_event))
+
 #endif
 struct target_rlimit64 {
     uint64_t rlim_cur;