From: P J P <ppandit@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
"Prasad J Pandit" <pjp@fedoraproject.org>,
"Alex Bennée" <alex.bennee@linaro.org>,
"Li Qiang" <liq3ea@gmail.com>,
"QEMU Developers" <qemu-devel@nongnu.org>,
"Lei Sun" <slei.casper@gmail.com>,
"Alex Williamson" <alex.williamson@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@redhat.com>,
"David Gibson" <david@gibson.dropbear.id.au>
Subject: [PATCH v1] memory: assert MemoryRegionOps callbacks are defined
Date: Thu, 18 Jun 2020 17:42:18 +0530 [thread overview]
Message-ID: <20200618121218.215808-1-ppandit@redhat.com> (raw)
From: Prasad J Pandit <pjp@fedoraproject.org>
When registering a MemoryRegionOps object, assert that its
read/write callback methods are defined. This avoids potential
guest crash via a NULL pointer dereference.
Suggested-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
---
memory.c | 5 +++++
1 file changed, 5 insertions(+)
Update v1: add assert while registering MemoryRegionOps
-> https://lists.gnu.org/archive/html/qemu-devel/2020-06/msg05187.html
diff --git a/memory.c b/memory.c
index 91ceaf9fcf..6e94fd5958 100644
--- a/memory.c
+++ b/memory.c
@@ -1495,6 +1495,9 @@ void memory_region_init_io(MemoryRegion *mr,
const char *name,
uint64_t size)
{
+ assert(ops);
+ assert(ops->read);
+ assert(ops->write);
memory_region_init(mr, owner, name, size);
mr->ops = ops ? ops : &unassigned_mem_ops;
mr->opaque = opaque;
@@ -1674,6 +1677,8 @@ void memory_region_init_rom_device_nomigrate(MemoryRegion *mr,
{
Error *err = NULL;
assert(ops);
+ assert(ops->read);
+ assert(ops->write);
memory_region_init(mr, owner, name, size);
mr->ops = ops;
mr->opaque = opaque;
--
2.26.2
next reply other threads:[~2020-06-18 12:16 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-18 12:12 P J P [this message]
2020-06-18 12:36 ` [PATCH v1] memory: assert MemoryRegionOps callbacks are defined no-reply
2020-06-18 13:12 ` Alex Bennée
2020-06-18 13:35 ` Paolo Bonzini
2020-06-18 14:29 ` Peter Maydell
2020-06-18 14:53 ` Paolo Bonzini
2020-06-19 10:48 ` P J P
2020-06-19 11:00 ` Paolo Bonzini
2020-06-18 14:52 ` Philippe Mathieu-Daudé
2020-06-18 13:19 ` no-reply
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=20200618121218.215808-1-ppandit@redhat.com \
--to=ppandit@redhat.com \
--cc=alex.bennee@linaro.org \
--cc=alex.williamson@redhat.com \
--cc=david@gibson.dropbear.id.au \
--cc=liq3ea@gmail.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@redhat.com \
--cc=pjp@fedoraproject.org \
--cc=qemu-devel@nongnu.org \
--cc=slei.casper@gmail.com \
/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).