qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Anastasia Belova <abelova@astralinux.ru>,
	Gerd Hoffmann <kraxel@redhat.com>
Cc: qemu-devel@nongnu.org, sdl.qemu@linuxtesting.org,
	Michael Tokarev <mjt@tls.msk.ru>
Subject: Re: [PATCH] hw/qxl: move check of slot_id before accessing guest_slots
Date: Thu, 14 Sep 2023 15:09:28 +0200	[thread overview]
Message-ID: <b8b1631a-9295-6e80-5df9-90631c2080c3@linaro.org> (raw)
In-Reply-To: <20230914092717.7158-1-abelova@astralinux.ru>

Hi Anastasia,

On 14/9/23 11:27, Anastasia Belova wrote:
> If slot_id >= NUM_MEMSLOTS, buffer overflow is possible.

overflow: unlikely. Do you mean over-read?

Did you found that by code audit? I can't see where this
function get slot_id >= NUM_MEMSLOTS.

This isn't guest triggerable and seems an API invalid use,
so developer error, which we can catch with assertions:

-- >8 --
diff --git a/hw/display/qxl.c b/hw/display/qxl.c
index 7bb00d68f5..443f034168 100644
--- a/hw/display/qxl.c
+++ b/hw/display/qxl.c
@@ -1309,16 +1309,13 @@ static int qxl_add_memslot(PCIQXLDevice *d, 
uint32_t slot_id, uint64_t delta,
      QXLDevMemSlot memslot;
      int i;

+    assert(slot_id < NUM_MEMSLOTS);
+
      guest_start = le64_to_cpu(d->guest_slots[slot_id].slot.mem_start);
      guest_end   = le64_to_cpu(d->guest_slots[slot_id].slot.mem_end);

      trace_qxl_memslot_add_guest(d->id, slot_id, guest_start, guest_end);

-    if (slot_id >= NUM_MEMSLOTS) {
-        qxl_set_guest_bug(d, "%s: slot_id >= NUM_MEMSLOTS %d >= %d", 
__func__,
-                      slot_id, NUM_MEMSLOTS);
-        return 1;
-    }
      if (guest_start > guest_end) {
          qxl_set_guest_bug(d, "%s: guest_start > guest_end 0x%" PRIx64
                           " > 0x%" PRIx64, __func__, guest_start, 
guest_end);
---

Note, qxl_add_memslot() return value is ignored...

> So the check should be upper than d->guest_slots[slot_id]
> where size of d->guest_slots is NUM_MEMSLOTS.
> 
> Fixes: e954ea2873 ("qxl: qxl_add_memslot: remove guest trigerrable panics")
> Signed-off-by: Anastasia Belova <abelova@astralinux.ru>
> ---
>   hw/display/qxl.c | 11 ++++++-----
>   1 file changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/hw/display/qxl.c b/hw/display/qxl.c
> index 7bb00d68f5..dc618727c0 100644
> --- a/hw/display/qxl.c
> +++ b/hw/display/qxl.c
> @@ -1309,16 +1309,17 @@ static int qxl_add_memslot(PCIQXLDevice *d, uint32_t slot_id, uint64_t delta,
>       QXLDevMemSlot memslot;
>       int i;
>   
> -    guest_start = le64_to_cpu(d->guest_slots[slot_id].slot.mem_start);
> -    guest_end   = le64_to_cpu(d->guest_slots[slot_id].slot.mem_end);
> -
> -    trace_qxl_memslot_add_guest(d->id, slot_id, guest_start, guest_end);
> -
>       if (slot_id >= NUM_MEMSLOTS) {
>           qxl_set_guest_bug(d, "%s: slot_id >= NUM_MEMSLOTS %d >= %d", __func__,
>                         slot_id, NUM_MEMSLOTS);
>           return 1;
>       }
> +
> +    guest_start = le64_to_cpu(d->guest_slots[slot_id].slot.mem_start);
> +    guest_end   = le64_to_cpu(d->guest_slots[slot_id].slot.mem_end);
> +
> +    trace_qxl_memslot_add_guest(d->id, slot_id, guest_start, guest_end);
> +
>       if (guest_start > guest_end) {
>           qxl_set_guest_bug(d, "%s: guest_start > guest_end 0x%" PRIx64
>                            " > 0x%" PRIx64, __func__, guest_start, guest_end);



      parent reply	other threads:[~2023-09-14 13:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-14  9:27 [PATCH] hw/qxl: move check of slot_id before accessing guest_slots Anastasia Belova
2023-09-14 12:32 ` Michael Tokarev
2023-09-14 13:09 ` Philippe Mathieu-Daudé [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b8b1631a-9295-6e80-5df9-90631c2080c3@linaro.org \
    --to=philmd@linaro.org \
    --cc=abelova@astralinux.ru \
    --cc=kraxel@redhat.com \
    --cc=mjt@tls.msk.ru \
    --cc=qemu-devel@nongnu.org \
    --cc=sdl.qemu@linuxtesting.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).