]> git.proxmox.com Git - mirror_qemu.git/commitdiff
memory: don't sign-extend 32-bit writes
authorLadi Prosek <lprosek@redhat.com>
Thu, 26 Jan 2017 14:22:37 +0000 (15:22 +0100)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 27 Jan 2017 17:08:00 +0000 (18:08 +0100)
ldl_p has a signed return type so assigning it to uint64_t implicitly
sign-extends the value. This results in devices with min_access_size = 8
seeing unexpected values passed to their write handlers.

Example: guest performs a 32-bit write of 0x80000000 to an mmio region
and the handler receives 0xFFFFFFFF80000000 in its value argument.

Signed-off-by: Ladi Prosek <lprosek@redhat.com>
Message-Id: <1485440557-10384-1-git-send-email-lprosek@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
exec.c

diff --git a/exec.c b/exec.c
index f2bed92b64a1a5909d055935fc00c95093f9df51..b05c5d2d74915054599517db8df4502c26dc2ecf 100644 (file)
--- a/exec.c
+++ b/exec.c
@@ -2630,7 +2630,7 @@ static MemTxResult address_space_write_continue(AddressSpace *as, hwaddr addr,
                 break;
             case 4:
                 /* 32 bit write access */
-                val = ldl_p(buf);
+                val = (uint32_t)ldl_p(buf);
                 result |= memory_region_dispatch_write(mr, addr1, val, 4,
                                                        attrs);
                 break;