qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Anatoly Trosinenko <anatoly.trosinenko@gmail.com>
To: qemu-devel@nongnu.org
Cc: Stefan Weil <sw@weilnetz.de>,
	Anatoly Trosinenko <anatoly.trosinenko@gmail.com>
Subject: [Qemu-devel] [PATCH 1/1] tci: eliminate UB due to unaligned reads
Date: Sat, 27 Jan 2018 16:49:08 +0300	[thread overview]
Message-ID: <20180127134908.24095-2-anatoly.trosinenko@gmail.com> (raw)
In-Reply-To: <20180127134908.24095-1-anatoly.trosinenko@gmail.com>

Use ldl_he_p / ldq_he_p functions instead of a plain memory access
through pointer.

Signed-off-by: Anatoly Trosinenko <anatoly.trosinenko@gmail.com>
---
 tcg/tci.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/tcg/tci.c b/tcg/tci.c
index 33edca1903..410817cf6a 100644
--- a/tcg/tci.c
+++ b/tcg/tci.c
@@ -159,7 +159,13 @@ static uint64_t tci_uint64(uint32_t high, uint32_t low)
 /* Read constant (native size) from bytecode. */
 static tcg_target_ulong tci_read_i(uint8_t **tb_ptr)
 {
-    tcg_target_ulong value = *(tcg_target_ulong *)(*tb_ptr);
+#if TCG_TARGET_REG_BITS == 32
+    tcg_target_ulong value = ldl_he_p(*tb_ptr);
+#elif TCG_TARGET_REG_BITS == 64
+    tcg_target_ulong value = ldq_he_p(*tb_ptr);
+#else
+#error unsupported
+#endif
     *tb_ptr += sizeof(value);
     return value;
 }
@@ -167,7 +173,7 @@ static tcg_target_ulong tci_read_i(uint8_t **tb_ptr)
 /* Read unsigned constant (32 bit) from bytecode. */
 static uint32_t tci_read_i32(uint8_t **tb_ptr)
 {
-    uint32_t value = *(uint32_t *)(*tb_ptr);
+    uint32_t value = ldl_he_p(*tb_ptr);
     *tb_ptr += sizeof(value);
     return value;
 }
@@ -175,7 +181,7 @@ static uint32_t tci_read_i32(uint8_t **tb_ptr)
 /* Read signed constant (32 bit) from bytecode. */
 static int32_t tci_read_s32(uint8_t **tb_ptr)
 {
-    int32_t value = *(int32_t *)(*tb_ptr);
+    int32_t value = ldl_he_p(*tb_ptr);
     *tb_ptr += sizeof(value);
     return value;
 }
@@ -184,7 +190,7 @@ static int32_t tci_read_s32(uint8_t **tb_ptr)
 /* Read constant (64 bit) from bytecode. */
 static uint64_t tci_read_i64(uint8_t **tb_ptr)
 {
-    uint64_t value = *(uint64_t *)(*tb_ptr);
+    uint64_t value = ldq_he_p(*tb_ptr);
     *tb_ptr += sizeof(value);
     return value;
 }
@@ -1094,7 +1100,7 @@ uintptr_t tcg_qemu_tb_exec(CPUArchState *env, uint8_t *tb_ptr)
             /* QEMU specific operations. */
 
         case INDEX_op_exit_tb:
-            ret = *(uint64_t *)tb_ptr;
+            ret = ldq_he_p(tb_ptr);
             goto exit;
             break;
         case INDEX_op_goto_tb:
-- 
2.14.1

  reply	other threads:[~2018-01-27 13:49 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-27 13:49 [Qemu-devel] [PATCH 0/1] Fix unaligned reads in the tcg/tci.c Anatoly Trosinenko
2018-01-27 13:49 ` Anatoly Trosinenko [this message]
2018-01-27 16:38   ` [Qemu-devel] [PATCH 1/1] tci: eliminate UB due to unaligned reads Stefan Weil
2018-01-28  6:42     ` Anatoly Trosinenko
2018-02-19 14:26       ` Anatoly Trosinenko
2018-03-03  8:54       ` Anatoly Trosinenko
2018-03-03 13:57         ` Richard Henderson
2018-03-03 14:07           ` Anatoly Trosinenko
2018-03-03 14:13             ` Richard Henderson
2018-03-03 14:59               ` Anatoly Trosinenko
2018-03-03 15:41             ` Stefan Weil
2018-03-03 16:01               ` Anatoly Trosinenko
2018-03-12 13:45               ` Richard Henderson
2018-02-05 13:52 ` [Qemu-devel] [PATCH 0/1] Fix unaligned reads in the tcg/tci.c Anatoly Trosinenko

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=20180127134908.24095-2-anatoly.trosinenko@gmail.com \
    --to=anatoly.trosinenko@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=sw@weilnetz.de \
    /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).