All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
To: qemu-devel@nongnu.org
Cc: "Daniel P. Berrangé" <berrange@redhat.com>,
	"Eduardo Habkost" <ehabkost@redhat.com>,
	qemu-trivial@nongnu.org, "Michael Tokarev" <mjt@tls.msk.ru>,
	"Laurent Vivier" <laurent@vivier.eu>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	"Paolo Bonzini" <pbonzini@redhat.com>
Subject: [PATCH-for-5.2 2/2] hw/core/sysbus: Assert memory region index is in range
Date: Thu,  6 Aug 2020 15:09:45 +0200	[thread overview]
Message-ID: <20200806130945.21629-3-f4bug@amsat.org> (raw)
In-Reply-To: <20200806130945.21629-1-f4bug@amsat.org>

Devices incorrectly modelled might use invalid index while
calling sysbus_mmio_get_region(), leading to OOB access.
Help developers by asserting the index is in range.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 hw/core/sysbus.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c
index 77ab351ce1..294f90b7de 100644
--- a/hw/core/sysbus.c
+++ b/hw/core/sysbus.c
@@ -199,6 +199,7 @@ void sysbus_init_mmio(SysBusDevice *dev, MemoryRegion *memory)
 
 MemoryRegion *sysbus_mmio_get_region(SysBusDevice *dev, int n)
 {
+    assert(n >= 0 && n < QDEV_MAX_MMIO);
     return dev->mmio[n].memory;
 }
 
-- 
2.21.3



  parent reply	other threads:[~2020-08-06 13:12 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-06 13:09 [PATCH-for-5.2 0/2] hw/core/sysbus: Trivial cleanup patches Philippe Mathieu-Daudé
2020-08-06 13:09 ` [PATCH-for-5.2 1/2] hw/core/sysbus: Fix a typo Philippe Mathieu-Daudé
2020-08-12 17:47   ` Richard Henderson
2020-09-01  7:27   ` Laurent Vivier
2020-08-06 13:09 ` Philippe Mathieu-Daudé [this message]
2020-08-12 17:48   ` [PATCH-for-5.2 2/2] hw/core/sysbus: Assert memory region index is in range Richard Henderson
2020-09-01  7:28   ` Laurent Vivier
2020-08-22 20:01 ` [PATCH-for-5.2 0/2] hw/core/sysbus: Trivial cleanup patches Philippe Mathieu-Daudé

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=20200806130945.21629-3-f4bug@amsat.org \
    --to=f4bug@amsat.org \
    --cc=berrange@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=laurent@vivier.eu \
    --cc=mjt@tls.msk.ru \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.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 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.