target/i386: allow access_ptr to force slow path on failed probe
RFC PATCH 1/1 target/i386: allow access_ptr to force slow path on failed probe
When we are using TCG plugin memory callbacks probe_access_internal will return TLB_MMIO to force the slow path for memory access. This results in probe_access returning NULL but the x86 access_ptr function happily accepts an empty haddr resulting in segfault hilarity.
Check for an empty haddr to prevent the segfault and enable plugins to track all the memory operations for the x86 save/restore helpers.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2489
--- target/i386/tcg/access.c | 4 ++++ 1 file changed, 4 insertions(+)
target/i386/tcg/access.c +4 -0
@@ -58,6 +58,10 @@ static void *access_ptr(X86Access *ac, vaddr addr, unsigned len)assert (addr >= ac->vaddr); +if (!ac->haddr1) { +return NULL ; + } +#ifdef CONFIG_USER_ONLY assert (offset <= ac->size1 - len);return ac->haddr1 + offset;
Signature · 1 line
2.39.2
Quoted 20 lines · Alex Bennée
When we are using TCG plugin memory callbacks
probe_access_internalwill returnTLB_MMIOto force the slow path for memory access. This results inprobe_accessreturning NULL but the x86access_ptrfunction happily accepts an empty haddr resulting in segfault hilarity.Check for an empty haddr to prevent the segfault and enable plugins to track all the memory operations for the x86 save/restore helpers.
Signed-off-by Alex Bennée <[email protected]>Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2489
Fixes 6d03226b42 (plugins: force slow path when plugins instrument memory ops)--- target/i386/tcg/access.c | 4 ++++ 1 file changed, 4 insertions(+)target/i386/tcg/access.c +0
-0
target/i386/tcg/access.c static void *access_ptr(X86Access *ac, vaddr addr, unsigned len) · line 67
Quoted 10 lines
target/i386/tcg/access.c +4
-0@@ -58,6 +58,10 @@ static void *access_ptr(X86Access *ac, vaddr addr, unsigned len)assert (addr >= ac->vaddr); +if (!ac->haddr1) { +return NULL ; + } +#ifdef CONFIG_USER_ONLY assert (offset <= ac->size1 - len);return ac->haddr1 + offset;
I confirm that this patch fixes the crash I reported here: https://gitlab.com/qemu-project/qemu/-/issues/2489
Thanks,
Signature · 1 line
Alexandre
Quoted 20 lines · Alex Bennée
When we are using TCG plugin memory callbacks
probe_access_internalwill returnTLB_MMIOto force the slow path for memory access. This results inprobe_accessreturning NULL but the x86access_ptrfunction happily accepts an empty haddr resulting in segfault hilarity.Check for an empty haddr to prevent the segfault and enable plugins to track all the memory operations for the x86 save/restore helpers.
Signed-off-by Alex Bennée <[email protected]>Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2489
Fixes 6d03226b42 (plugins: force slow path when plugins instrument memory ops)--- target/i386/tcg/access.c | 4 ++++ 1 file changed, 4 insertions(+)target/i386/tcg/access.c +0
-0
target/i386/tcg/access.c static void *access_ptr(X86Access *ac, vaddr addr, unsigned len) · line 67
Quoted 10 lines
target/i386/tcg/access.c +4
-0@@ -58,6 +58,10 @@ static void *access_ptr(X86Access *ac, vaddr addr, unsigned len)assert (addr >= ac->vaddr); +if (!ac->haddr1) { +return NULL ; + } +#ifdef CONFIG_USER_ONLY assert (offset <= ac->size1 - len);return ac->haddr1 + offset;
You need to remove the test_ptr macro below as well.
r~
Quoted 21 lines · Richard Henderson
Quoted 20 lines · Alex Bennée
When we are using TCG plugin memory callbacks
probe_access_internalwill returnTLB_MMIOto force the slow path for memory access. This results inprobe_accessreturning NULL but the x86access_ptrfunction happily accepts an empty haddr resulting in segfault hilarity. Check for an empty haddr to prevent the segfault and enable plugins to
track all the memory operations for the x86 save/restore helpers.Signed-off-by Alex Bennée <[email protected]>Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2489
Fixes 6d03226b42 (plugins: force slow path when plugins instrument memory ops)--- target/i386/tcg/access.c | 4 ++++ 1 file changed, 4 insertions(+)target/i386/tcg/access.c +0
-0@@ -58,6 +58,10 @@ static void *access_ptr(X86Access *ac, vaddr addr, unsigned len)assert (addr >= ac->vaddr); + if (!ac->haddr1) {
Quoted 8 lines
target/i386/tcg/access.c static void *access_ptr(X86Access *ac, vaddr addr, unsigned len) · line 67
Quoted 6 lines
target/i386/tcg/access.c +3
-0+return NULL ; + } +#ifdef CONFIG_USER_ONLY assert (offset <= ac->size1 - len);return ac->haddr1 + offset;You need to remove the
test_ptrmacro below as well.
So we fall-back to the slow path for linux-user as well?
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
Quoted 32 lines · Alex Bennée
Quoted 21 lines · Richard Henderson
Quoted 20 lines · Alex Bennée
When we are using TCG plugin memory callbacks
probe_access_internalwill returnTLB_MMIOto force the slow path for memory access. This results inprobe_accessreturning NULL but the x86access_ptrfunction happily accepts an empty haddr resulting in segfault hilarity. Check for an empty haddr to prevent the segfault and enable plugins to
track all the memory operations for the x86 save/restore helpers.Signed-off-by Alex Bennée <[email protected]>Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2489
Fixes 6d03226b42 (plugins: force slow path when plugins instrument memory ops)--- target/i386/tcg/access.c | 4 ++++ 1 file changed, 4 insertions(+)target/i386/tcg/access.c +0
-0@@ -58,6 +58,10 @@ static void *access_ptr(X86Access *ac, vaddr addr, unsigned len)assert (addr >= ac->vaddr); + if (!ac->haddr1) {Quoted 8 lines
target/i386/tcg/access.c static void *access_ptr(X86Access *ac, vaddr addr, unsigned len) · line 67
Quoted 6 lines
target/i386/tcg/access.c +3
-0+return NULL ; + } +#ifdef CONFIG_USER_ONLY assert (offset <= ac->size1 - len);return ac->haddr1 + offset;You need to remove the
test_ptrmacro below as well.
Quoted 1 line
So we fall-back to the slow path for linux-user as well?
So we don't ignore the null, and dereference it anyway.
r~