hw/hyperv: Avoid crash if hyperv_find_cpu() passed invalid vp_index
PATCH 1/1 hw/hyperv: Avoid crash if hyperv_find_cpu() passed invalid vp_index
The hyperv_find_cpu() function finds a CPU from a CPU index; this is basically a wrapper around qemu_get_cpu(). It is allowed to fail, in which case it returns NULL, which its caller handles. However, it includes an assertion check which accidentally assumes the CPU pointer is non-NULL.
We could assert only if cs != NULL, but the assertion here is not doing anything interesting -- hyperv_vp_index() is a trivial wrapper returning cs->cpu_index, so this is effectively asserting that qemu_get_cpu() did what it claims to do, i.e. returned us the CPU matching the index we gave it. qemu_get_cpu() is a simple "iterate through list and find matching CPU" which is unlikely to be buggy, and we don't feel the need to sanity-check it in any of our other many uses of it. Drop the assertion entirely.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3568
---
Checked only with make check / check-functional...
--- hw/hyperv/hyperv.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
hw/hyperv/hyperv.c +1 -3
@@ -237,9 +237,7 @@ struct HvSintRoute {static CPUState *hyperv_find_vcpu (uint32_t vp_index) { -CPUState *cs =qemu_get_cpu (vp_index); -assert (hyperv_vp_index (cs) == vp_index); -return cs; +return qemu_get_cpu (vp_index); }/*
Signature · 1 line
2.43.0
Quoted 15 lines · Peter Maydell
The
hyperv_find_cpu()function finds a CPU from a CPU index; this is basically a wrapper aroundqemu_get_cpu(). It is allowed to fail, in which case it returns NULL, which its caller handles. However, it includes an assertion check which accidentally assumes the CPU pointer is non-NULL.We could assert only if cs != NULL, but the assertion here is not doing anything interesting --
hyperv_vp_index()is a trivial wrapper returningcs->cpu_index, so this is effectively asserting thatqemu_get_cpu()did what it claims to do, i.e. returned us the CPU matching the index we gave it.qemu_get_cpu()is a simple "iterate through list and find matching CPU" which is unlikely to be buggy, and we don't feel the need to sanity-check it in any of our other many uses of it. Drop the assertion entirely.
Quoted 7 lines
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3568
Signed-off-by Peter Maydell <[email protected]>---
Checked only with make check / check-functional...--- hw/hyperv/hyperv.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com ~~ https://hachyderm.io/@berrange :| |: https://libvirt.org ~~ https://entangle-photo.org :| |: https://pixelfed.art/berrange ~~ https://fstop138.berrange.com :|
Quoted 28 lines · Peter Maydell
The
hyperv_find_cpu()function finds a CPU from a CPU index; this is basically a wrapper aroundqemu_get_cpu(). It is allowed to fail, in which case it returns NULL, which its caller handles. However, it includes an assertion check which accidentally assumes the CPU pointer is non-NULL.We could assert only if cs != NULL, but the assertion here is not doing anything interesting --
hyperv_vp_index()is a trivial wrapper returningcs->cpu_index, so this is effectively asserting thatqemu_get_cpu()did what it claims to do, i.e. returned us the CPU matching the index we gave it.qemu_get_cpu()is a simple "iterate through list and find matching CPU" which is unlikely to be buggy, and we don't feel the need to sanity-check it in any of our other many uses of it. Drop the assertion entirely.Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3568
Signed-off-by Peter Maydell <[email protected]>---
Checked only with make check / check-functional...--- hw/hyperv/hyperv.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)hw/hyperv/hyperv.c +0
-0
hw/hyperv/hyperv.c struct HvSintRoute { · line 243
Quoted 10 lines
hw/hyperv/hyperv.c +1
-3@@ -237,9 +237,7 @@ struct HvSintRoute {static CPUState *hyperv_find_vcpu (uint32_t vp_index) { -CPUState *cs =qemu_get_cpu (vp_index); -assert (hyperv_vp_index (cs) == vp_index); -return cs; +return qemu_get_cpu (vp_index); }/*
Thanks,
Maciej
Philippe Mathieu-Daudé
AppliedQuoted 15 lines · Peter Maydell
The
hyperv_find_cpu()function finds a CPU from a CPU index; this is basically a wrapper aroundqemu_get_cpu(). It is allowed to fail, in which case it returns NULL, which its caller handles. However, it includes an assertion check which accidentally assumes the CPU pointer is non-NULL.We could assert only if cs != NULL, but the assertion here is not doing anything interesting --
hyperv_vp_index()is a trivial wrapper returningcs->cpu_index, so this is effectively asserting thatqemu_get_cpu()did what it claims to do, i.e. returned us the CPU matching the index we gave it.qemu_get_cpu()is a simple "iterate through list and find matching CPU" which is unlikely to be buggy, and we don't feel the need to sanity-check it in any of our other many uses of it. Drop the assertion entirely.
Quoted 7 lines
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3568
Signed-off-by Peter Maydell <[email protected]>---
Checked only with make check / check-functional...--- hw/hyperv/hyperv.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
Queued via hw-misc tree, thanks.