qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] linux-user/armeb: Fix __kernel_cmpxchg() for armeb
@ 2023-07-28  4:54 Helge Deller
  2023-07-28  5:17 ` Markus F.X.J. Oberhumer
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Helge Deller @ 2023-07-28  4:54 UTC (permalink / raw)
  To: Laurent Vivier, Richard Henderson, qemu-devel
  Cc: Peter Maydell, John Reiser, Markus F.X.J. Oberhumer

Commit 7f4f0d9ea870 ("linux-user/arm: Implement __kernel_cmpxchg with host
atomics") switched to use qatomic_cmpxchg() to swap a word with the memory
content, but missed to endianess-swap the oldval and newval values when
emulating an armeb CPU, which expects words to be stored in big endian in
the guest memory.

The bug can be verified with qemu >= v7.2 on any little-endian host, when
starting the armeb binary of the upx program, which just hangs without
this patch.

Signed-off-by: Helge Deller <deller@gmx.de>
Cc: Richard Henderson <richard.henderson@linaro.org>
Cc: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-stable@nongnu.org
Reported-by: "Markus F.X.J. Oberhumer" <markus@oberhumer.com>
Reported-by: John Reiser <jreiser@BitWagon.com>
Closes: https://github.com/upx/upx/issues/687

--
v2:
- add tswap32() in arm_kernel_cmpxchg64_helper()


diff --git a/linux-user/arm/cpu_loop.c b/linux-user/arm/cpu_loop.c
index a992423257..0907cd8c15 100644
--- a/linux-user/arm/cpu_loop.c
+++ b/linux-user/arm/cpu_loop.c
@@ -117,8 +117,9 @@ static void arm_kernel_cmpxchg32_helper(CPUARMState *env)
 {
     uint32_t oldval, newval, val, addr, cpsr, *host_addr;

-    oldval = env->regs[0];
-    newval = env->regs[1];
+    /* endianess-swap if emulating armeb */
+    oldval = tswap32(env->regs[0]);
+    newval = tswap32(env->regs[1]);
     addr = env->regs[2];

     mmap_lock();
@@ -174,6 +175,10 @@ static void arm_kernel_cmpxchg64_helper(CPUARMState *env)
         return;
     }

+    /* endianess-swap if emulating armeb */
+    oldval = tswap32(oldval);
+    newval = tswap32(newval);
+
 #ifdef CONFIG_ATOMIC64
     val = qatomic_cmpxchg__nocheck(host_addr, oldval, newval);
     cpsr = (val == oldval) * CPSR_C;


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-07-28 20:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-28  4:54 [PATCH v2] linux-user/armeb: Fix __kernel_cmpxchg() for armeb Helge Deller
2023-07-28  5:17 ` Markus F.X.J. Oberhumer
2023-07-28  5:45 ` Markus F.X.J. Oberhumer
2023-07-28 15:35 ` Richard Henderson
2023-07-28 19:16   ` Helge Deller

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).