qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: riku.voipio@linaro.org
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>, Tom Musta <tommusta@gmail.com>
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	[thread overview]
Message-ID: <05945bb57d1c51a305b40de7d68c1a6b4a00b56d.1408100160.git.riku.voipio@linaro.org> (raw)
In-Reply-To: <cover.1408100160.git.riku.voipio@linaro.org>

From: Tom Musta <tommusta@gmail.com>

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 <tommusta@gmail.com>
Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
---
 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

  parent reply	other threads:[~2014-08-15 11:02 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-15 11:01 [Qemu-devel] [PULL 00/24] Linux-user updates riku.voipio
2014-08-15 11:01 ` [Qemu-devel] [PULL 01/24] linux-user: /proc/self/maps content riku.voipio
2014-08-15 11:01 ` [Qemu-devel] [PULL 02/24] linux-user: redirect openat calls riku.voipio
2014-08-15 11:01 ` [Qemu-devel] [PULL 03/24] linux-user: make binfmt flag O require P riku.voipio
2014-08-15 11:01 ` [Qemu-devel] [PULL 04/24] linux-user: Fix syscall instruction usermode emulation on X86_64 riku.voipio
2014-08-15 11:01 ` [Qemu-devel] [PULL 05/24] linux-user: Fix conversion of sigevent argument to timer_create riku.voipio
2014-08-15 11:01 ` [Qemu-devel] [PULL 06/24] linux-user: fix readlink handling with magic exe symlink riku.voipio
2014-08-15 11:01 ` [Qemu-devel] [PULL 07/24] linux-user: support timerfd_{create, gettime, settime} syscalls riku.voipio
2014-08-15 11:01 ` [Qemu-devel] [PULL 08/24] linux-user: support ioprio_{get, set} syscalls riku.voipio
2014-08-15 11:01 ` [Qemu-devel] [PULL 09/24] linux-user: support {name_to, open_by}_handle_at syscalls riku.voipio
2014-08-15 11:01 ` [Qemu-devel] [PULL 10/24] linux-user: add setns and unshare riku.voipio
2014-08-15 11:01 ` [Qemu-devel] [PULL 11/24] linux-user: PPC64 semid_ds Doesnt Include _unused1 and _unused2 riku.voipio
2014-08-15 11:01 ` [Qemu-devel] [PULL 12/24] linux-user: Dereference Pointer Argument to ipc/semctl Sys Call riku.voipio
2014-08-15 11:01 ` riku.voipio [this message]
2014-08-15 11:01 ` [Qemu-devel] [PULL 14/24] linux-user: Make ipc syscall's third argument an abi_long riku.voipio
2014-08-15 11:01 ` [Qemu-devel] [PULL 15/24] linux-user: Conditionally Pass Attribute Pointer to mq_open() riku.voipio
2014-08-15 11:01 ` [Qemu-devel] [PULL 16/24] linux-user: Detect Negative Message Sizes in msgsnd System Call riku.voipio
2014-08-15 11:01 ` [Qemu-devel] [PULL 17/24] linux-user: Handle NULL sched_param argument to sched_* riku.voipio
2014-08-15 11:01 ` [Qemu-devel] [PULL 18/24] linux-user: Detect fault in sched_rr_get_interval riku.voipio
2014-08-15 11:01 ` [Qemu-devel] [PULL 19/24] linux-user: Move get_ppc64_abi riku.voipio
2014-08-15 11:01 ` [Qemu-devel] [PULL 20/24] linux-user: Minimum Sig Handler Stack Size for PPC64 ELF V2 riku.voipio
2014-08-15 11:01 ` [Qemu-devel] [PULL 21/24] linux-user: clock_nanosleep errno Handling on PPC riku.voipio
2014-08-15 11:01 ` [Qemu-devel] [PULL 22/24] linux-user: Support target-to-host translation of mlockall argument riku.voipio
2014-08-15 11:01 ` [Qemu-devel] [PULL 23/24] linux-user: writev Partial Writes riku.voipio
2014-08-15 11:01 ` [Qemu-devel] [PULL 24/24] linux-user: check return value of malloc() riku.voipio
2014-08-15 17:49 ` [Qemu-devel] [PULL 00/24] Linux-user updates Peter Maydell
2014-08-18  8:46   ` Riku Voipio
2014-08-18 10:49     ` Joakim Tjernlund
2014-08-18 10:58       ` Peter Maydell
2014-08-18 12:38         ` Joakim Tjernlund
2014-08-18 12:45           ` Peter Maydell
2014-08-18 12:59             ` Joakim Tjernlund
2014-08-18 13:04               ` Peter Maydell
2014-08-18 15:15                 ` Joakim Tjernlund
2014-08-18 13:17               ` Riku Voipio
2014-08-18 15:35                 ` Joakim Tjernlund
2014-08-18 13:02             ` Laurent Vivier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=05945bb57d1c51a305b40de7d68c1a6b4a00b56d.1408100160.git.riku.voipio@linaro.org \
    --to=riku.voipio@linaro.org \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=tommusta@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).