qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] loader: Fix misaligned member access
@ 2018-04-21 21:16 Philippe Mathieu-Daudé
  2018-04-22 10:41 ` Peter Maydell
  0 siblings, 1 reply; 10+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-04-21 21:16 UTC (permalink / raw)
  To: Paul Burton, Marc-André Lureau
  Cc: Philippe Mathieu-Daudé, qemu-devel

This fixes the following ASan warning:

  $ mips64el-softmmu/qemu-system-mips64el -M boston -kernel vmlinux.gz.itb -nographic
  hw/core/loader-fit.c:108:17: runtime error: load of misaligned address 0x7f95cd7e4264 for type 'fdt64_t', which requires 8 byte alignment
  0x7f95cd7e4264: note: pointer points here
    00 00 00 3e ff ff ff ff  80 7d 2a c0 00 00 00 01  68 61 73 68 40 30 00 00  00 00 00 03 00 00 00 14
                ^

Reported-by: AddressSanitizer
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 hw/core/loader-fit.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/hw/core/loader-fit.c b/hw/core/loader-fit.c
index 0c4a7207f4..1a69697f89 100644
--- a/hw/core/loader-fit.c
+++ b/hw/core/loader-fit.c
@@ -93,6 +93,8 @@ static int fit_image_addr(const void *itb, int img, const char *name,
                           hwaddr *addr)
 {
     const void *prop;
+    fdt32_t v32;
+    fdt64_t v64;
     int len;
 
     prop = fdt_getprop(itb, img, name, &len);
@@ -102,10 +104,12 @@ static int fit_image_addr(const void *itb, int img, const char *name,
 
     switch (len) {
     case 4:
-        *addr = fdt32_to_cpu(*(fdt32_t *)prop);
+        memcpy(&v32, prop, sizeof(v32));
+        *addr = fdt32_to_cpu(v32);
         return 0;
     case 8:
-        *addr = fdt64_to_cpu(*(fdt64_t *)prop);
+        memcpy(&v64, prop, sizeof(v64));
+        *addr = fdt64_to_cpu(v64);
         return 0;
     default:
         error_printf("invalid %s address length %d\n", name, len);
-- 
2.17.0

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

end of thread, other threads:[~2018-04-23 15:55 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-04-21 21:16 [Qemu-devel] [PATCH] loader: Fix misaligned member access Philippe Mathieu-Daudé
2018-04-22 10:41 ` Peter Maydell
2018-04-23  3:16   ` David Gibson
2018-04-23 13:57     ` Philippe Mathieu-Daudé
2018-04-23 14:04       ` Peter Maydell
2018-04-23 14:15         ` Philippe Mathieu-Daudé
2018-04-23 14:26           ` Philippe Mathieu-Daudé
2018-04-23 15:32             ` Peter Maydell
2018-04-23 15:49               ` Philippe Mathieu-Daudé
2018-04-23 15:55                 ` Peter Maydell

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