[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL v2 11/22] linux-user: Don't use alloca() for epoll_wa
From: |
riku . voipio |
Subject: |
[Qemu-devel] [PULL v2 11/22] linux-user: Don't use alloca() for epoll_wait's epoll event array |
Date: |
Tue, 18 Oct 2016 16:21:39 +0300 |
From: Peter Maydell <address@hidden>
The epoll event array which epoll_wait() allocates has a size
determined by the guest which could potentially be quite large.
Use g_try_new() rather than alloca() so that we can fail more
cleanly if the guest hands us an oversize value. (ENOMEM is
not a documented return value for epoll_wait() but in practice
some kernel configurations can return it -- see for instance
sys_oabi_epoll_wait() on ARM.)
This rearrangement includes fixing a bug where we were
incorrectly passing a negative length to unlock_user() in
the error-exit codepath.
Signed-off-by: Peter Maydell <address@hidden>
Signed-off-by: Riku Voipio <address@hidden>
---
linux-user/syscall.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index bbdf316..fb56fed 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -11796,7 +11796,12 @@ abi_long do_syscall(void *cpu_env, int num, abi_long
arg1,
goto efault;
}
- ep = alloca(maxevents * sizeof(struct epoll_event));
+ ep = g_try_new(struct epoll_event, maxevents);
+ if (!ep) {
+ unlock_user(target_ep, arg2, 0);
+ ret = -TARGET_ENOMEM;
+ break;
+ }
switch (num) {
#if defined(TARGET_NR_epoll_pwait)
@@ -11814,8 +11819,8 @@ abi_long do_syscall(void *cpu_env, int num, abi_long
arg1,
target_set = lock_user(VERIFY_READ, arg5,
sizeof(target_sigset_t), 1);
if (!target_set) {
- unlock_user(target_ep, arg2, 0);
- goto efault;
+ ret = -TARGET_EFAULT;
+ break;
}
target_to_host_sigset(set, target_set);
unlock_user(target_set, arg5, 0);
@@ -11843,8 +11848,12 @@ abi_long do_syscall(void *cpu_env, int num, abi_long
arg1,
target_ep[i].events = tswap32(ep[i].events);
target_ep[i].data.u64 = tswap64(ep[i].data.u64);
}
+ unlock_user(target_ep, arg2,
+ ret * sizeof(struct target_epoll_event));
+ } else {
+ unlock_user(target_ep, arg2, 0);
}
- unlock_user(target_ep, arg2, ret * sizeof(struct target_epoll_event));
+ g_free(ep);
break;
}
#endif
--
2.1.4
- [Qemu-devel] [PULL v2 00/22] linux-user changes, riku . voipio, 2016/10/18
- [Qemu-devel] [PULL v2 03/22] linux-user: Fix mq_open() syscall support, riku . voipio, 2016/10/18
- [Qemu-devel] [PULL v2 04/22] linux-user: Fix msgrcv() and msgsnd() syscalls support, riku . voipio, 2016/10/18
- [Qemu-devel] [PULL v2 02/22] linux-user: Add support for ustat() syscall, riku . voipio, 2016/10/18
- [Qemu-devel] [PULL v2 01/22] linux-user: Add support for adjtimex() syscall, riku . voipio, 2016/10/18
- [Qemu-devel] [PULL v2 07/22] linux-user: Remove a duplicate item from strace.list, riku . voipio, 2016/10/18
- [Qemu-devel] [PULL v2 05/22] linux-user: Fix socketcall() syscall support, riku . voipio, 2016/10/18
- [Qemu-devel] [PULL v2 11/22] linux-user: Don't use alloca() for epoll_wait's epoll event array,
riku . voipio <=
- [Qemu-devel] [PULL v2 08/22] linux-user: sparc64: Use correct target SHMLBA in shmat(), riku . voipio, 2016/10/18
- [Qemu-devel] [PULL v2 12/22] linux-user: use libc wrapper instead of direct mremap syscall, riku . voipio, 2016/10/18
- [Qemu-devel] [PULL v2 13/22] linux-user: Fix definition of target_sigevent for 32-bit guests, riku . voipio, 2016/10/18
- [Qemu-devel] [PULL v2 09/22] linux-user: add kcmp() syscall, riku . voipio, 2016/10/18
- [Qemu-devel] [PULL v2 16/22] linux-user: Update mips_syscall_args[] array in main.c, riku . voipio, 2016/10/18
- [Qemu-devel] [PULL v2 06/22] linux-user: Fix syslog() syscall support, riku . voipio, 2016/10/18
- [Qemu-devel] [PULL v2 10/22] linux-user: add RTA_PRIORITY in netlink, riku . voipio, 2016/10/18
- [Qemu-devel] [PULL v2 14/22] linux-user: Add support for clock_adjtime() syscall, riku . voipio, 2016/10/18
- [Qemu-devel] [PULL v2 19/22] linux-user: Fix fadvise64() syscall support for Mips32, riku . voipio, 2016/10/18
- [Qemu-devel] [PULL v2 15/22] linux-user: Add support for syncfs() syscall, riku . voipio, 2016/10/18