All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] hw/hyperv: Avoid crash if hyperv_find_cpu() passed invalid vp_index
@ 2026-06-30  8:48 Peter Maydell
  2026-06-30  8:59 ` Daniel P. Berrangé
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Peter Maydell @ 2026-06-30  8:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: Maciej S . Szmigiero

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>
---
Checked only with make check / check-functional...
---
 hw/hyperv/hyperv.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/hw/hyperv/hyperv.c b/hw/hyperv/hyperv.c
index 4d90032785..900ff80213 100644
--- a/hw/hyperv/hyperv.c
+++ b/hw/hyperv/hyperv.c
@@ -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);
 }
 
 /*
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] hw/hyperv: Avoid crash if hyperv_find_cpu() passed invalid vp_index
  2026-06-30  8:48 [PATCH] hw/hyperv: Avoid crash if hyperv_find_cpu() passed invalid vp_index Peter Maydell
@ 2026-06-30  8:59 ` Daniel P. Berrangé
  2026-06-30 12:02 ` Maciej S. Szmigiero
  2026-07-06  9:00 ` Philippe Mathieu-Daudé
  2 siblings, 0 replies; 4+ messages in thread
From: Daniel P. Berrangé @ 2026-06-30  8:59 UTC (permalink / raw)
  To: Peter Maydell; +Cc: qemu-devel, Maciej S . Szmigiero

On Tue, Jun 30, 2026 at 09:48:55AM +0100, Peter Maydell wrote:
> 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>
> ---
> Checked only with make check / check-functional...
> ---
>  hw/hyperv/hyperv.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


With regards,
Daniel
-- 
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] hw/hyperv: Avoid crash if hyperv_find_cpu() passed invalid vp_index
  2026-06-30  8:48 [PATCH] hw/hyperv: Avoid crash if hyperv_find_cpu() passed invalid vp_index Peter Maydell
  2026-06-30  8:59 ` Daniel P. Berrangé
@ 2026-06-30 12:02 ` Maciej S. Szmigiero
  2026-07-06  9:00 ` Philippe Mathieu-Daudé
  2 siblings, 0 replies; 4+ messages in thread
From: Maciej S. Szmigiero @ 2026-06-30 12:02 UTC (permalink / raw)
  To: Peter Maydell; +Cc: qemu-devel, Daniel P. Berrangé

On 30.06.2026 10:48, Peter Maydell wrote:
> 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>
> ---
> Checked only with make check / check-functional...
> ---
>   hw/hyperv/hyperv.c | 4 +---
>   1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/hw/hyperv/hyperv.c b/hw/hyperv/hyperv.c
> index 4d90032785..900ff80213 100644
> --- a/hw/hyperv/hyperv.c
> +++ b/hw/hyperv/hyperv.c
> @@ -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);
>   }
>   
>   /*

Acked-by: Maciej S. Szmigiero <maciej.szmigiero@oracle.com>

Thanks,
Maciej



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] hw/hyperv: Avoid crash if hyperv_find_cpu() passed invalid vp_index
  2026-06-30  8:48 [PATCH] hw/hyperv: Avoid crash if hyperv_find_cpu() passed invalid vp_index Peter Maydell
  2026-06-30  8:59 ` Daniel P. Berrangé
  2026-06-30 12:02 ` Maciej S. Szmigiero
@ 2026-07-06  9:00 ` Philippe Mathieu-Daudé
  2 siblings, 0 replies; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-07-06  9:00 UTC (permalink / raw)
  To: Peter Maydell, qemu-devel; +Cc: Maciej S . Szmigiero

On 30/6/26 10:48, Peter Maydell wrote:
> 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>
> ---
> 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.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-07-06  9:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-30  8:48 [PATCH] hw/hyperv: Avoid crash if hyperv_find_cpu() passed invalid vp_index Peter Maydell
2026-06-30  8:59 ` Daniel P. Berrangé
2026-06-30 12:02 ` Maciej S. Szmigiero
2026-07-06  9:00 ` Philippe Mathieu-Daudé

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.