Skip to contentSkip to conversation

tcg: Silence ubsan error on tcg_splitwx_diff causing overflow

PATCH In review Fabiano Rosas 3 participants 3 messages Jun 5 – Jun 8

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 tcg: Silence ubsan error on tcg_splitwx_diff causing overflow

UBSAN complains:
runtime error: addition of unsigned offset to 0x7bc06e1f5000 overflowed to 0x7bc02e1f5000

Change tcg_splitwx_diff to ptrdiff_t and silence the error.

---
 include/tcg/tcg.h | 2 +-
 tcg/tcg.c         | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
include/tcg/tcg.h +1 -1
index 45c7e118c3..7669dc1c2d 100644
@@ -447,7 +447,7 @@ static inline bool temp_readonly(TCGTemp *ts)
 
 extern __thread TCGContext *tcg_ctx;
 extern const void *tcg_code_gen_epilogue;
-extern uintptr_t tcg_splitwx_diff;
+extern ptrdiff_t tcg_splitwx_diff;
 extern TCGv_env tcg_env;
 
 bool in_code_gen_buffer(const void *p);
tcg/tcg.c +1 -1
index 2ca44766f6..1e77f2365a 100644
@@ -244,7 +244,7 @@ unsigned int tcg_cur_ctxs;
 unsigned int tcg_max_ctxs;
 TCGv_env tcg_env;
 const void *tcg_code_gen_epilogue;
-uintptr_t tcg_splitwx_diff;
+ptrdiff_t tcg_splitwx_diff;
 
 #ifndef CONFIG_TCG_INTERPRETER
 tcg_prologue_fn *tcg_qemu_tb_exec;
Signature · 1 line
2.53.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 11 lines · Fabiano Rosas

UBSAN complains:
runtime error: addition of unsigned offset to 0x7bc06e1f5000 overflowed to 0x7bc02e1f5000

Change tcg_splitwx_diff to ptrdiff_t and silence the error.

---
  include/tcg/tcg.h | 2 +-
  tcg/tcg.c         | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)

r~

Quoted 27 lines
include/tcg/tcg.h +1 -1
index 45c7e118c3..7669dc1c2d 100644
@@ -447,7 +447,7 @@ static inline bool temp_readonly(TCGTemp *ts)
 
  extern __thread TCGContext *tcg_ctx;
  extern const void *tcg_code_gen_epilogue;
-extern uintptr_t tcg_splitwx_diff;
+extern ptrdiff_t tcg_splitwx_diff;
  extern TCGv_env tcg_env;
 
  bool in_code_gen_buffer(const void *p);
tcg/tcg.c +1 -1
index 2ca44766f6..1e77f2365a 100644
@@ -244,7 +244,7 @@ unsigned int tcg_cur_ctxs;
  unsigned int tcg_max_ctxs;
  TCGv_env tcg_env;
  const void *tcg_code_gen_epilogue;
-uintptr_t tcg_splitwx_diff;
+ptrdiff_t tcg_splitwx_diff;
 
  #ifndef CONFIG_TCG_INTERPRETER
  tcg_prologue_fn *tcg_qemu_tb_exec;
Reviewed-by on v2 1/1
#2 lore raw
In reply to Fabiano Rosas
Quoted 11 lines · Fabiano Rosas

UBSAN complains:
runtime error: addition of unsigned offset to 0x7bc06e1f5000 overflowed to 0x7bc02e1f5000

Change tcg_splitwx_diff to ptrdiff_t and silence the error.

---
  include/tcg/tcg.h | 2 +-
  tcg/tcg.c         | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)