]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
hw/hyperv: Avoid crash if hyperv_find_cpu() passed invalid vp_index
authorPeter Maydell <peter.maydell@linaro.org>
Tue, 30 Jun 2026 08:48:55 +0000 (09:48 +0100)
committerPhilippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Tue, 7 Jul 2026 15:10:24 +0000 (17:10 +0200)
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
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Acked-by: Maciej S. Szmigiero <maciej.szmigiero@oracle.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Message-ID: <20260630084855.2319838-1-peter.maydell@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
hw/hyperv/hyperv.c

index 4d900327857c8799af670c9d938c048171ee2066..900ff80213d2559f26041f9ae06b887afd63ed56 100644 (file)
@@ -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);
 }
 
 /*