accel/tcg: fix msan findings in translate-all
PATCH 1/1 accel/tcg: fix msan findings in translate-all
From: Peter Foley <[email protected]>
e.g.
Uninitialized value was created by an allocation of 'host_pc' in the stack frame #0 0xaaaac07df87c in tb_gen_code third_party/qemu/accel/tcg/translate-all.c:297:5
--- accel/tcg/translate-all.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
accel/tcg/translate-all.c +1 -1
@@ -298,7 +298,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu,tcg_insn_unit *gen_code_buf;int gen_code_size, search_size, max_insns;int64_t ti; -void *host_pc; +void *host_pc =NULL ;assert_memory_lock ();qemu_thread_jit_write ();
Signature · 1 line
2.48.1.711.g2feabab25a-goog
Quoted 17 lines · Patrick Venture
From: Peter Foley <[email protected]>
e.g.
Uninitialized value was created by an allocation of 'host_pc' in the stack frame #00xaaaac07df87cintb_gen_codethird_party/qemu/accel/tcg/translate-all.c:297:5Signed-off-by Peter Foley <[email protected]>Signed-off-by Patrick Venture <[email protected]>--- accel/tcg/translate-all.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)accel/tcg/translate-all.c +0
-0
accel/tcg/translate-all.c TranslationBlock *tb_gen_code(CPUState *cpu, · line 304
Quoted 8 lines
accel/tcg/translate-all.c +1
-1@@ -298,7 +298,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu,tcg_insn_unit *gen_code_buf;int gen_code_size, search_size, max_insns;int64_t ti; -void *host_pc; +void *host_pc =NULL ;assert_memory_lock ();qemu_thread_jit_write ();
False positive, because the error return exits without using the uninitialized value. But if we do want to "fix" this, do it at the beginning of get_page_addr_code_hostp.
r~
Quoted 26 lines · Richard Henderson
Quoted 4 lines · Patrick Venture
From: Peter Foley <[email protected]>
e.g.
Uninitialized value was created by an allocation of 'host_pc' in thestack frame
Quoted 1 line
#0 0xaaaac07df87c in tb_gen_code
third_party/qemu/accel/tcg/translate-all.c:297:5Quoted 18 lines
Signed-off-by Peter Foley <[email protected]>Signed-off-by Patrick Venture <[email protected]>--- accel/tcg/translate-all.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)accel/tcg/translate-all.c +1
-1@@ -298,7 +298,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu,tcg_insn_unit *gen_code_buf;int gen_code_size, search_size, max_insns;int64_t ti; -void *host_pc; +void *host_pc =NULL ;
Quoted 8 lines
accel/tcg/translate-all.c TranslationBlock *tb_gen_code(CPUState *cpu, · line 304
Quoted 2 lines
accel/tcg/translate-all.c +0
-0assert_memory_lock ();qemu_thread_jit_write ();False positive, because the error return exits without using the uninitialized value.
But if we do want to "fix" this, do it at the beginning ofget_page_addr_code_hostp.
Acknowledged. Gotta hate false positives, although better aggressive than not. Thanks!
Quoted 3 lines
r~
For reference, the full output from msan looks like:
==4872==WARNING: MemorySanitizer: use-of-uninitialized-value
#0 0xaaaac681ef98 in tb_gen_code
third_party/qemu/accel/tcg/translate-all.c:358:21
#1 0xaaaac67f2520 in cpu_exec_loop
third_party/qemu/accel/tcg/cpu-exec.c:993:22
#2 0xaaaac67f154c in cpu_exec_setjmp
third_party/qemu/accel/tcg/cpu-exec.c:1039:12
#3 0xaaaac67f1240 in cpu_exec third_party/qemu/accel/tcg/cpu-exec.c:1065:11
#4 0xaaaac681022c in tcg_cpu_exec
third_party/qemu/accel/tcg/tcg-accel-ops.c:79:11
#5 0xaaaac680ede4 in mttcg_cpu_thread_fn
third_party/qemu/accel/tcg/tcg-accel-ops-mttcg.c:95:17
#6 0xaaaacf096698 in qemu_thread_start
third_party/qemu/util/qemu-thread-posix.c:541:9
#7 0xffffa9242cec in start_thread
(/usr/grte/v5/lib64/libpthread.so.0+0xbcec) (BuildId:
0bdac2117d4465a78d3de57b307368b4)
#8 0xffffa912ec98 in thread_start(/usr/grte/v5/lib64/libc.so.6+0x116c98) (BuildId:613d20d3b812b4c87fe9ebf8c4caae83)
Uninitialized value was stored to memory at
#0 0xaaaac681ef94 in tb_gen_code
third_party/qemu/accel/tcg/translate-all.c:358:50
#1 0xaaaac67f2520 in cpu_exec_loop
third_party/qemu/accel/tcg/cpu-exec.c:993:22
#2 0xaaaac67f154c in cpu_exec_setjmp
third_party/qemu/accel/tcg/cpu-exec.c:1039:12
#3 0xaaaac67f1240 in cpu_exec third_party/qemu/accel/tcg/cpu-exec.c:1065:11
#4 0xaaaac681022c in tcg_cpu_exec
third_party/qemu/accel/tcg/tcg-accel-ops.c:79:11
#5 0xaaaac680ede4 in mttcg_cpu_thread_fn
third_party/qemu/accel/tcg/tcg-accel-ops-mttcg.c:95:17
#6 0xaaaacf096698 in qemu_thread_start
third_party/qemu/util/qemu-thread-posix.c:541:9
#7 0xffffa9242cec in start_thread
(/usr/grte/v5/lib64/libpthread.so.0+0xbcec) (BuildId:
0bdac2117d4465a78d3de57b307368b4)
#8 0xffffa912ec98 in thread_start(/usr/grte/v5/lib64/libc.so.6+0x116c98) (BuildId:613d20d3b812b4c87fe9ebf8c4caae83)
Uninitialized value was created by an allocation of 'host_pc' in the
stack frame
#0 0xaaaac681d8ac in tb_gen_code
third_party/qemu/accel/tcg/translate-all.c:297:5
SUMMARY: MemorySanitizer: use-of-uninitialized-value third_party/qemu/accel/tcg/translate-all.c:358:21 in tb_gen_code Exiting
Quoted 48 lines · Patrick Venture
Quoted 26 lines · Richard Henderson
Quoted 4 lines · Patrick Venture
From: Peter Foley <[email protected]>
e.g.
Uninitialized value was created by an allocation of 'host_pc' in thestack frame
Quoted 1 line
#0 0xaaaac07df87c in tb_gen_code
third_party/qemu/accel/tcg/translate-all.c:297:5Quoted 18 lines
Signed-off-by Peter Foley <[email protected]>Signed-off-by Patrick Venture <[email protected]>--- accel/tcg/translate-all.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)accel/tcg/translate-all.c +1
-1@@ -298,7 +298,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu,tcg_insn_unit *gen_code_buf;int gen_code_size, search_size, max_insns;int64_t ti; -void *host_pc; +void *host_pc =NULL ;Quoted 8 lines
accel/tcg/translate-all.c TranslationBlock *tb_gen_code(CPUState *cpu, · line 304
Quoted 2 lines
accel/tcg/translate-all.c +0
-0assert_memory_lock ();qemu_thread_jit_write ();False positive, because the error return exits without using the uninitialized value.
But if we do want to "fix" this, do it at the beginning ofget_page_addr_code_hostp.Acknowledged. Gotta hate false positives, although better aggressive than not. Thanks!
Quoted 3 lines
r~
And interestingly enough, it appears that execution continues even with early return from get_page_addr_code_hostp:
https://gitlab.com/qemu-project/qemu/-/blob/master/accel/tcg/translate-all.c?ref_type=heads#L308
Which implies that we could still have an uninitialized value here:
https://gitlab.com/qemu-project/qemu/-/blob/master/accel/tcg/translate-all.c?ref_type=heads#L362
Quoted 82 lines · Peter Foley
For reference, the full output from msan looks like:
==4872==WARNING: MemorySanitizer: use-of-uninitialized-value
#0 0xaaaac681ef98 in tb_gen_code third_party/qemu/accel/tcg/translate-all.c:358:21 #1 0xaaaac67f2520 in cpu_exec_loop third_party/qemu/accel/tcg/cpu-exec.c:993:22 #2 0xaaaac67f154c in cpu_exec_setjmp third_party/qemu/accel/tcg/cpu-exec.c:1039:12 #3 0xaaaac67f1240 in cpu_exec third_party/qemu/accel/tcg/cpu-exec.c:1065:11 #4 0xaaaac681022c in tcg_cpu_exec third_party/qemu/accel/tcg/tcg-accel-ops.c:79:11 #5 0xaaaac680ede4 in mttcg_cpu_thread_fn third_party/qemu/accel/tcg/tcg-accel-ops-mttcg.c:95:17 #6 0xaaaacf096698 in qemu_thread_start third_party/qemu/util/qemu-thread-posix.c:541:9 #7 0xffffa9242cec in start_thread (/usr/grte/v5/lib64/libpthread.so.0+0xbcec) (BuildId: 0bdac2117d4465a78d3de57b307368b4) #8 0xffffa912ec98 in thread_start (/usr/grte/v5/lib64/libc.so.6+0x116c98) (BuildId: 613d20d3b812b4c87fe9ebf8c4caae83)Uninitialized value was stored to memory at
#0 0xaaaac681ef94 in tb_gen_code third_party/qemu/accel/tcg/translate-all.c:358:50 #1 0xaaaac67f2520 in cpu_exec_loop third_party/qemu/accel/tcg/cpu-exec.c:993:22 #2 0xaaaac67f154c in cpu_exec_setjmp third_party/qemu/accel/tcg/cpu-exec.c:1039:12 #3 0xaaaac67f1240 in cpu_exec third_party/qemu/accel/tcg/cpu-exec.c:1065:11 #4 0xaaaac681022c in tcg_cpu_exec third_party/qemu/accel/tcg/tcg-accel-ops.c:79:11 #5 0xaaaac680ede4 in mttcg_cpu_thread_fn third_party/qemu/accel/tcg/tcg-accel-ops-mttcg.c:95:17 #6 0xaaaacf096698 in qemu_thread_start third_party/qemu/util/qemu-thread-posix.c:541:9 #7 0xffffa9242cec in start_thread (/usr/grte/v5/lib64/libpthread.so.0+0xbcec) (BuildId: 0bdac2117d4465a78d3de57b307368b4) #8 0xffffa912ec98 in thread_start (/usr/grte/v5/lib64/libc.so.6+0x116c98) (BuildId: 613d20d3b812b4c87fe9ebf8c4caae83)Uninitialized value was created by an allocation of '
host_pc' in the stack frame#0 0xaaaac681d8ac in tb_gen_code third_party/qemu/accel/tcg/translate-all.c:297:5SUMMARY: MemorySanitizer: use-of-uninitialized-value
third_party/qemu/accel/tcg/translate-all.c:358:21intb_gen_codeExitingQuoted 48 lines · Patrick Venture
Quoted 26 lines · Richard Henderson
Quoted 4 lines · Patrick Venture
From: Peter Foley <[email protected]>
e.g.
Uninitialized value was created by an allocation of 'host_pc' inthe stack frame
Quoted 1 line
#0 0xaaaac07df87c in tb_gen_code
third_party/qemu/accel/tcg/translate-all.c:297:5Quoted 18 lines
Signed-off-by Peter Foley <[email protected]>Signed-off-by Patrick Venture <[email protected]>--- accel/tcg/translate-all.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)accel/tcg/translate-all.c +1
-1@@ -298,7 +298,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu,tcg_insn_unit *gen_code_buf;int gen_code_size, search_size, max_insns;int64_t ti; -void *host_pc; +void *host_pc =NULL ;Quoted 8 lines
accel/tcg/translate-all.c TranslationBlock *tb_gen_code(CPUState *cpu, · line 304
Quoted 2 lines
accel/tcg/translate-all.c +0
-0assert_memory_lock ();qemu_thread_jit_write ();False positive, because the error return exits without using the uninitialized value.
But if we do want to "fix" this, do it at the beginning ofget_page_addr_code_hostp.Acknowledged. Gotta hate false positives, although better aggressive than not. Thanks!
Quoted 3 lines
r~
Quoted 2 lines · Peter Foley
And interestingly enough, it appears that execution continues even with early return from
get_page_addr_code_hostp:
https://gitlab.com/qemu-project/qemu/-/blob/master/accel/tcg/translate-all.c? ref_type=heads#L308 <https://gitlab.com/qemu-project/qemu/-/blob/master/accel/tcg/ translate-all.c?ref_type=heads#L308>
Yes, but without using the hostp value.
Quoted 3 lines
Which implies that we could still have an uninitialized value here:
https://gitlab.com/qemu-project/qemu/-/blob/master/accel/tcg/translate-all.c? ref_type=heads#L362 <https://gitlab.com/qemu-project/qemu/-/blob/master/accel/tcg/ translate-all.c?ref_type=heads#L362>
Passed through several layers of functions, but still unused.
Eventually, we reach
https://gitlab.com/qemu-project/qemu/-/blob/master/accel/tcg/translator.c#L257
which again checks the -1 error return, skips the use of the cached host_pc (now named host_addr).
Again, I'm open to unconditional initialized value, but doing so in get_page_addr_code_hostp, not tb_gen_code.
r~