[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 15/18] linux-user: Don't overrun guest buffer in sche
From: |
riku . voipio |
Subject: |
[Qemu-devel] [PULL 15/18] linux-user: Don't overrun guest buffer in sched_getaffinity |
Date: |
Mon, 9 Jun 2014 15:46:40 +0300 |
From: Peter Maydell <address@hidden>
If the guest's "long" type is smaller than the host's, then
our sched_getaffinity wrapper needs to round the buffer size
up to a multiple of the host sizeof(long). This means that when
we copy the data back from the host buffer to the guest's
buffer there might be more than we can fit. Rather than
overflowing the guest's buffer, handle this case by returning
EINVAL or ignoring the unused extra space, as appropriate.
Note that only guests using the syscall interface directly might
run into this bug -- the glibc wrappers around it will always
use a buffer whose size is a multiple of 8 regardless of guest
architecture.
Signed-off-by: Peter Maydell <address@hidden>
Signed-off-by: Riku Voipio <address@hidden>
---
linux-user/syscall.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 6efeeff..840ced1 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -7438,6 +7438,22 @@ abi_long do_syscall(void *cpu_env, int num, abi_long
arg1,
ret = get_errno(sys_sched_getaffinity(arg1, mask_size, mask));
if (!is_error(ret)) {
+ if (ret > arg2) {
+ /* More data returned than the caller's buffer will fit.
+ * This only happens if sizeof(abi_long) < sizeof(long)
+ * and the caller passed us a buffer holding an odd number
+ * of abi_longs. If the host kernel is actually using the
+ * extra 4 bytes then fail EINVAL; otherwise we can just
+ * ignore them and only copy the interesting part.
+ */
+ int numcpus = sysconf(_SC_NPROCESSORS_CONF);
+ if (numcpus > arg2 * 8) {
+ ret = -TARGET_EINVAL;
+ break;
+ }
+ ret = arg2;
+ }
+
if (copy_to_user(arg3, mask, ret)) {
goto efault;
}
--
2.0.0.rc2
- [Qemu-devel] [PULL 10/18] signal/ppc/{save, restore}_user_regs remove __put/get error checks, (continued)
- [Qemu-devel] [PULL 10/18] signal/ppc/{save, restore}_user_regs remove __put/get error checks, riku . voipio, 2014/06/09
- [Qemu-devel] [PULL 12/18] signal/ppc/do_setcontext remove __get_user return check, riku . voipio, 2014/06/09
- [Qemu-devel] [PULL 13/18] linux-user: fix gcc-4.9 compiler error on __{get, put]}_user, riku . voipio, 2014/06/09
- [Qemu-devel] [PULL 08/18] signal/all/do_sigreturn - remove __get_user checks, riku . voipio, 2014/06/09
- [Qemu-devel] [PULL 01/18] signal/all: remove __get/__put_user return value reading, riku . voipio, 2014/06/09
- [Qemu-devel] [PULL 18/18] User mode support for Linux ELF files with no section header, riku . voipio, 2014/06/09
- [Qemu-devel] [PULL 07/18] signal/all/do_sigaltstack remove __get_user value check, riku . voipio, 2014/06/09
- [Qemu-devel] [PULL 03/18] signal/all: remove return value from copy_siginfo_to_user, riku . voipio, 2014/06/09
- [Qemu-devel] [PULL 06/18] signal/sparc/restore_fpu_state: remove, riku . voipio, 2014/06/09
- [Qemu-devel] [PULL 05/18] signal/all: remove return value from restore_sigcontext, riku . voipio, 2014/06/09
- [Qemu-devel] [PULL 15/18] linux-user: Don't overrun guest buffer in sched_getaffinity,
riku . voipio <=
- [Qemu-devel] [PULL 14/18] linux-user/uname: Return correct uname string for x86_64, riku . voipio, 2014/06/09
- [Qemu-devel] [PULL 11/18] signal/sparc64_set_context: remove __get_user checks, riku . voipio, 2014/06/09
- [Qemu-devel] [PULL 16/18] linux-user: Tell guest about big host page sizes, riku . voipio, 2014/06/09
- [Qemu-devel] [PULL 04/18] signal/all: remove return value from setup_sigcontext, riku . voipio, 2014/06/09
- [Qemu-devel] [PULL 09/18] signal/all/setup_frame remove __put_user checks, riku . voipio, 2014/06/09
- Re: [Qemu-devel] [PULL 00/18] linux-user fixes, Peter Maydell, 2014/06/09