From: Nicola Vetrini <nicola.vetr...@bugseng.com>

Rule 19.1 states: "An object shall not be assigned or copied
to an overlapping object". Since the "call" and "compat_call" are
fields of the same union, reading from one member and writing to
the other violates the rule, while not causing Undefined Behavior
due to their relative sizes. However, a dummy variables are used to
address the violations and prevent the future possibility of
incurring in UB.

No functional change.

Signed-off-by: Nicola Vetrini <nicola.vetr...@bugseng.com>
Signed-off-by: Federico Serafini <federico.seraf...@bugseng.com>
Signed-off-by: Victor Lira <victorm.l...@amd.com>
---
Cc: Andrew Cooper <andrew.coop...@citrix.com>
Cc: Anthony PERARD <anthony.per...@vates.tech>
Cc: Michal Orzel <michal.or...@amd.com>
Cc: Jan Beulich <jbeul...@suse.com>
Cc: Julien Grall <jul...@xen.org>
Cc: Roger Pau Monné <roger....@citrix.com>
Cc: Stefano Stabellini <sstabell...@kernel.org>
Cc: Nicola Vetrini <nicola.vetr...@bugseng.com>
Cc: Federico Serafini <federico.seraf...@bugseng.com>
Cc: Bertrand Marquis <bertrand.marq...@arm.com>
---
 xen/arch/x86/x86_emulate/x86_emulate.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/xen/arch/x86/x86_emulate/x86_emulate.c 
b/xen/arch/x86/x86_emulate/x86_emulate.c
index 8e14ebb35b..44dc3039f3 100644
--- a/xen/arch/x86/x86_emulate/x86_emulate.c
+++ b/xen/arch/x86/x86_emulate/x86_emulate.c
@@ -526,9 +526,19 @@ static inline void put_loop_count(
          */                                                             \
         if ( !amd_like(ctxt) && mode_64bit() && ad_bytes == 4 )         \
         {                                                               \
+            uint64_t tmp;                                               \
+                                                                        \
             _regs.r(cx) = 0;                                            \
-            if ( extend_si ) _regs.r(si) = _regs.esi;                   \
-            if ( extend_di ) _regs.r(di) = _regs.edi;                   \
+            if ( extend_si )                                            \
+            {                                                           \
+                tmp = _regs.esi;                                        \
+                _regs.r(si) = tmp;                                      \
+            }                                                           \
+            if ( extend_di )                                            \
+            {                                                           \
+                tmp = _regs.edi;                                        \
+                _regs.r(di) = tmp;                                      \
+            }                                                           \
         }                                                               \
         goto complete_insn;                                             \
     }                                                                   \
@@ -2029,7 +2039,12 @@ x86_emulate(
         switch ( op_bytes )
         {
         case 2: _regs.ax = (int8_t)_regs.ax; break; /* cbw */
-        case 4: _regs.r(ax) = (uint32_t)(int16_t)_regs.ax; break; /* cwde */
+        case 4:
+            {
+                uint32_t tmp = (uint32_t)(int16_t)_regs.ax;
+                _regs.r(ax) = tmp;
+                break; /* cwde */
+            }
         case 8: _regs.r(ax) = (int32_t)_regs.r(ax); break; /* cdqe */
         }
         break;
--
2.47.0

Reply via email to