[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL v2 29/38] linux-user: Handle negative values in times
From: |
riku . voipio |
Subject: |
[Qemu-devel] [PULL v2 29/38] linux-user: Handle negative values in timespec conversion |
Date: |
Fri, 27 May 2016 16:00:20 +0300 |
From: Peter Maydell <address@hidden>
In a struct timespec, both fields are signed longs. Converting
them from guest to host with code like
host_ts->tv_sec = tswapal(target_ts->tv_sec);
mishandles negative values if the guest has 32-bit longs and
the host has 64-bit longs because tswapal()'s return type is
abi_ulong: the assignment will zero-extend into the host long
type rather than sign-extending it.
Make the conversion routines use __get_user() and __set_user()
instead: this automatically picks up the signedness of the
field type and does the correct kind of sign or zero extension.
It also handles the possibility that the target struct is not
sufficiently aligned for the host's requirements.
In particular, this fixes a hang when running the Linux Test Project
mq_timedsend01 and mq_timedreceive01 tests: one of the test cases
sets the timeout to -1 and expects an EINVAL failure, but we were
setting a very long timeout instead.
Signed-off-by: Peter Maydell <address@hidden>
Signed-off-by: Riku Voipio <address@hidden>
---
linux-user/syscall.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 4e419fb..6c4f5c6 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -5194,8 +5194,8 @@ static inline abi_long target_to_host_timespec(struct
timespec *host_ts,
if (!lock_user_struct(VERIFY_READ, target_ts, target_addr, 1))
return -TARGET_EFAULT;
- host_ts->tv_sec = tswapal(target_ts->tv_sec);
- host_ts->tv_nsec = tswapal(target_ts->tv_nsec);
+ __get_user(host_ts->tv_sec, &target_ts->tv_sec);
+ __get_user(host_ts->tv_nsec, &target_ts->tv_nsec);
unlock_user_struct(target_ts, target_addr, 0);
return 0;
}
@@ -5207,8 +5207,8 @@ static inline abi_long host_to_target_timespec(abi_ulong
target_addr,
if (!lock_user_struct(VERIFY_WRITE, target_ts, target_addr, 0))
return -TARGET_EFAULT;
- target_ts->tv_sec = tswapal(host_ts->tv_sec);
- target_ts->tv_nsec = tswapal(host_ts->tv_nsec);
+ __put_user(host_ts->tv_sec, &target_ts->tv_sec);
+ __put_user(host_ts->tv_nsec, &target_ts->tv_nsec);
unlock_user_struct(target_ts, target_addr, 1);
return 0;
}
--
2.1.4
- [Qemu-devel] [PULL v2 12/38] linux-user: Support for restarting system calls for Alpha targets, (continued)
- [Qemu-devel] [PULL v2 12/38] linux-user: Support for restarting system calls for Alpha targets, riku . voipio, 2016/05/27
- [Qemu-devel] [PULL v2 17/38] linux-user: Support for restarting system calls for CRIS targets, riku . voipio, 2016/05/27
- [Qemu-devel] [PULL v2 18/38] linux-user: Support for restarting system calls for tilegx targets, riku . voipio, 2016/05/27
- [Qemu-devel] [PULL v2 23/38] linux-user: Use safe_syscall for read and write system calls, riku . voipio, 2016/05/27
- [Qemu-devel] [PULL v2 20/38] linux-user: Support for restarting system calls for Microblaze targets, riku . voipio, 2016/05/27
- [Qemu-devel] [PULL v2 21/38] linux-user: Add debug code to exercise restarting system calls, riku . voipio, 2016/05/27
- [Qemu-devel] [PULL v2 19/38] linux-user: Set r14 on exit from microblaze syscall, riku . voipio, 2016/05/27
- [Qemu-devel] [PULL v2 22/38] linux-user: Provide safe_syscall for fixing races between signals and syscalls, riku . voipio, 2016/05/27
- [Qemu-devel] [PULL v2 24/38] linux-user: Use safe_syscall for open and openat system calls, riku . voipio, 2016/05/27
- [Qemu-devel] [PULL v2 25/38] linux-user: Use safe_syscall for wait system calls, riku . voipio, 2016/05/27
- [Qemu-devel] [PULL v2 29/38] linux-user: Handle negative values in timespec conversion,
riku . voipio <=
- [Qemu-devel] [PULL v2 26/38] linux-user: Use safe_syscall for execve syscall, riku . voipio, 2016/05/27
- [Qemu-devel] [PULL v2 27/38] linux-user: Use safe_syscall for pselect, select syscalls, riku . voipio, 2016/05/27
- [Qemu-devel] [PULL v2 28/38] linux-user: Use safe_syscall for futex syscall, riku . voipio, 2016/05/27
- [Qemu-devel] [PULL v2 31/38] linux-user: Use g_try_malloc() in do_msgrcv(), riku . voipio, 2016/05/27
- [Qemu-devel] [PULL v2 33/38] linux-user: Use direct syscalls for setuid(), etc, riku . voipio, 2016/05/27
- [Qemu-devel] [PULL v2 34/38] linux-user: arm: Remove ARM_cpsr and similar #defines, riku . voipio, 2016/05/27
- [Qemu-devel] [PULL v2 30/38] linux-user: Handle msgrcv error case correctly, riku . voipio, 2016/05/27
- [Qemu-devel] [PULL v2 32/38] linux-user: x86_64: Don't use 16-bit UIDs, riku . voipio, 2016/05/27
- [Qemu-devel] [PULL v2 35/38] linux-user/signal.c: Generate opcode data for restorer in setup_rt_frame, riku . voipio, 2016/05/27
- [Qemu-devel] [PULL v2 37/38] linux-user/signal.c: Use s390 target space address instead of host space, riku . voipio, 2016/05/27