[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 06/26] linux-user: Check for bad event numbers in epo
From: |
riku . voipio |
Subject: |
[Qemu-devel] [PULL 06/26] linux-user: Check for bad event numbers in epoll_wait |
Date: |
Thu, 22 Sep 2016 15:13:26 +0300 |
From: Peter Maydell <address@hidden>
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 <address@hidden>
Signed-off-by: Riku Voipio <address@hidden>
---
linux-user/syscall.c | 5 +++++
linux-user/syscall_defs.h | 3 +++
2 files changed, 8 insertions(+)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 21ae996..eecccbb 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -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) {
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index c0e5cb0..5c19c5c 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -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;
--
2.1.4
- [Qemu-devel] [PULL 00/26] linux-user update, riku . voipio, 2016/09/22
- [Qemu-devel] [PULL 01/26] linux-user: Fix handling of iovec counts, riku . voipio, 2016/09/22
- [Qemu-devel] [PULL 03/26] linux-user: Allow bad msg_name for recvfrom on connected socket, riku . voipio, 2016/09/22
- [Qemu-devel] [PULL 02/26] linux-user: Fix errno for sendrecvmsg with large iovec length, riku . voipio, 2016/09/22
- [Qemu-devel] [PULL 05/26] linux-user: Use direct syscall for utimensat, riku . voipio, 2016/09/22
- [Qemu-devel] [PULL 04/26] linux-user: Implement FS_IOC_GETFLAGS and FS_IOC_SETFLAGS ioctls, riku . voipio, 2016/09/22
- [Qemu-devel] [PULL 07/26] linux-user: Range check the nfds argument to ppoll syscall, riku . voipio, 2016/09/22
- [Qemu-devel] [PULL 08/26] linux-user: report signals being taken in strace output, riku . voipio, 2016/09/22
- [Qemu-devel] [PULL 06/26] linux-user: Check for bad event numbers in epoll_wait,
riku . voipio <=
- [Qemu-devel] [PULL 09/26] linux-user: Pass missing MAP_ANONYMOUS to target_mmap() call, riku . voipio, 2016/09/22
- [Qemu-devel] [PULL 11/26] linux-user: Fix incorrect use of host errno in do_ioctl_dm(), riku . voipio, 2016/09/22
- [Qemu-devel] [PULL 10/26] linux-user: Check lock_user() return value for NULL, riku . voipio, 2016/09/22
- [Qemu-devel] [PULL 13/26] linux-user: Check dump_write() return in elf_core_dump(), riku . voipio, 2016/09/22
- [Qemu-devel] [PULL 15/26] linux-user: Use correct target SHMLBA in shmat(), riku . voipio, 2016/09/22
- [Qemu-devel] [PULL 14/26] linux-user: Use glib malloc functions in load_symbols(), riku . voipio, 2016/09/22
- [Qemu-devel] [PULL 12/26] linux-user: Fix error handling in flatload.c target_pread(), riku . voipio, 2016/09/22
- [Qemu-devel] [PULL 16/26] linux-user: ppc64: set MSR_CM bit for BookE 2.06 MMU, riku . voipio, 2016/09/22
- [Qemu-devel] [PULL 17/26] linux-user: Recheck for pending synchronous signals too, riku . voipio, 2016/09/22
- [Qemu-devel] [PULL 18/26] linux-user: Pass si_type information to queue_signal() explicitly, riku . voipio, 2016/09/22