[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 13/24] linux-user: Properly Handle semun Structure In
From: |
riku . voipio |
Subject: |
[Qemu-devel] [PULL 13/24] linux-user: Properly Handle semun Structure In Cross-Endian Situations |
Date: |
Fri, 15 Aug 2014 14:01:31 +0300 |
From: Tom Musta <address@hidden>
The semun union used in the semctl system call contains both an int (val) and
pointers. In cross-endian situations on 64 bit targets, the value passed to
semctl is an 8 byte (abi_long) value and thus does not have the 4-byte val
field in the correct location. In order to rectify this, the other half
of the union must be accessed. This is achieved in code by performing
a byte swap on the entire 8 byte union, followed by a 4-byte swap of the
first half.
Also, eliminate an extraneous (dead) line of code that sets target_su.val in
the IPC_SET/IPC_GET case.
Signed-off-by: Tom Musta <address@hidden>
Signed-off-by: Riku Voipio <address@hidden>
---
linux-user/syscall.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 0113250..ba9dfc5 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -2652,9 +2652,18 @@ static inline abi_long do_semctl(int semid, int semnum,
int cmd,
switch( cmd ) {
case GETVAL:
case SETVAL:
- arg.val = tswap32(target_su.val);
+ /* In 64 bit cross-endian situations, we will erroneously pick up
+ * the wrong half of the union for the "val" element. To rectify
+ * this, the entire 8-byte structure is byteswapped, followed by
+ * a swap of the 4 byte val field. In other cases, the data is
+ * already in proper host byte order. */
+ if (sizeof(target_su.val) != (sizeof(target_su.buf))) {
+ target_su.buf = tswapal(target_su.buf);
+ arg.val = tswap32(target_su.val);
+ } else {
+ arg.val = target_su.val;
+ }
ret = get_errno(semctl(semid, semnum, cmd, arg));
- target_su.val = tswap32(arg.val);
break;
case GETALL:
case SETALL:
--
2.0.1
- [Qemu-devel] [PULL 00/24] Linux-user updates, riku . voipio, 2014/08/15
- [Qemu-devel] [PULL 02/24] linux-user: redirect openat calls, riku . voipio, 2014/08/15
- [Qemu-devel] [PULL 09/24] linux-user: support {name_to, open_by}_handle_at syscalls, riku . voipio, 2014/08/15
- [Qemu-devel] [PULL 06/24] linux-user: fix readlink handling with magic exe symlink, riku . voipio, 2014/08/15
- [Qemu-devel] [PULL 16/24] linux-user: Detect Negative Message Sizes in msgsnd System Call, riku . voipio, 2014/08/15
- [Qemu-devel] [PULL 07/24] linux-user: support timerfd_{create, gettime, settime} syscalls, riku . voipio, 2014/08/15
- [Qemu-devel] [PULL 11/24] linux-user: PPC64 semid_ds Doesnt Include _unused1 and _unused2, riku . voipio, 2014/08/15
- [Qemu-devel] [PULL 13/24] linux-user: Properly Handle semun Structure In Cross-Endian Situations,
riku . voipio <=
- [Qemu-devel] [PULL 17/24] linux-user: Handle NULL sched_param argument to sched_*, riku . voipio, 2014/08/15
- [Qemu-devel] [PULL 05/24] linux-user: Fix conversion of sigevent argument to timer_create, riku . voipio, 2014/08/15
- [Qemu-devel] [PULL 14/24] linux-user: Make ipc syscall's third argument an abi_long, riku . voipio, 2014/08/15
- [Qemu-devel] [PULL 03/24] linux-user: make binfmt flag O require P, riku . voipio, 2014/08/15
- [Qemu-devel] [PULL 10/24] linux-user: add setns and unshare, riku . voipio, 2014/08/15
- [Qemu-devel] [PULL 08/24] linux-user: support ioprio_{get, set} syscalls, riku . voipio, 2014/08/15
- [Qemu-devel] [PULL 12/24] linux-user: Dereference Pointer Argument to ipc/semctl Sys Call, riku . voipio, 2014/08/15
- [Qemu-devel] [PULL 15/24] linux-user: Conditionally Pass Attribute Pointer to mq_open(), riku . voipio, 2014/08/15
- [Qemu-devel] [PULL 24/24] linux-user: check return value of malloc(), riku . voipio, 2014/08/15
- [Qemu-devel] [PULL 23/24] linux-user: writev Partial Writes, riku . voipio, 2014/08/15