From: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
To: qemu-devel@nongnu.org
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
"Daniel P . Berrange" <berrange@redhat.com>,
"Michael S . Tsirkin" <mst@redhat.com>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Michael Tokarev" <mjt@tls.msk.ru>,
"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
"Anthony Perard" <anthony.perard@citrix.com>,
"Paolo Bonzini" <pbonzini@redhat.com>
Subject: [RFC PATCH-for-5.1? v3 1/2] memory: Allow monkey-patching MemoryRegion access sizes
Date: Tue, 21 Jul 2020 14:31:53 +0200 [thread overview]
Message-ID: <20200721123154.5302-2-f4bug@amsat.org> (raw)
In-Reply-To: <20200721123154.5302-1-f4bug@amsat.org>
To fixes CVE-2020-13754, commit 5d971f9e67 refuses mismatching
sizes in memory_region_access_valid(). This gives troubles when
a device is on an ISA bus, because the CPU is free to use
8/16-bit accesses on the bus (or up to 32-bit on EISA bus),
regardless what range is valid for the device.
To allow surgical change for the 5.1 release, allow monkey
patching of the MemoryRegionOps (by making the MemoryRegion
field not const). This should be reverted after the release
and fixed in a more elegant manner.
Fixes: 5d971f9e67 ('memory: Revert "accept mismatching sizes in memory_region_access_valid"')
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
include/exec/memory.h | 7 ++++++-
softmmu/memory.c | 12 ++++++++----
2 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/include/exec/memory.h b/include/exec/memory.h
index 307e527835..22028af6b9 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -383,7 +383,12 @@ struct MemoryRegion {
RAMBlock *ram_block;
Object *owner;
- const MemoryRegionOps *ops;
+ /*
+ * XXX this must be 'const' but to counter side effects of
+ * CVE-2020-13754, make it non-const to allow monkey patching
+ * the access sizes. Only allowed for QEMU release v5.1 :(
+ */
+ MemoryRegionOps *ops;
void *opaque;
MemoryRegion *container;
Int128 size;
diff --git a/softmmu/memory.c b/softmmu/memory.c
index 9200b20130..84b5c617e2 100644
--- a/softmmu/memory.c
+++ b/softmmu/memory.c
@@ -1218,7 +1218,7 @@ static void memory_region_initfn(Object *obj)
MemoryRegion *mr = MEMORY_REGION(obj);
ObjectProperty *op;
- mr->ops = &unassigned_mem_ops;
+ mr->ops = g_memdup(&unassigned_mem_ops, sizeof(MemoryRegionOps));
mr->enabled = true;
mr->romd_mode = true;
mr->global_locking = true;
@@ -1485,7 +1485,11 @@ void memory_region_init_io(MemoryRegion *mr,
uint64_t size)
{
memory_region_init(mr, owner, name, size);
- mr->ops = ops ? ops : &unassigned_mem_ops;
+ if (ops) {
+ mr->ops = g_memdup(ops, sizeof(MemoryRegionOps));
+ } else {
+ mr->ops = g_memdup(&unassigned_mem_ops, sizeof(MemoryRegionOps));
+ }
mr->opaque = opaque;
mr->terminates = true;
}
@@ -1622,7 +1626,7 @@ void memory_region_init_ram_device_ptr(MemoryRegion *mr,
mr->ram = true;
mr->terminates = true;
mr->ram_device = true;
- mr->ops = &ram_device_mem_ops;
+ mr->ops = g_memdup(&ram_device_mem_ops, sizeof(MemoryRegionOps));
mr->opaque = mr;
mr->destructor = memory_region_destructor_ram;
mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0;
@@ -1664,7 +1668,7 @@ void memory_region_init_rom_device_nomigrate(MemoryRegion *mr,
Error *err = NULL;
assert(ops);
memory_region_init(mr, owner, name, size);
- mr->ops = ops;
+ mr->ops = g_memdup(ops, sizeof(MemoryRegionOps));
mr->opaque = opaque;
mr->terminates = true;
mr->rom_device = true;
--
2.21.3
next prev parent reply other threads:[~2020-07-21 12:33 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-21 12:31 [RFC PATCH-for-5.1? v3 0/2] hw/isa: Allow 8/16/32 bit access on ISA bus after CVE-2020-13754 fix Philippe Mathieu-Daudé
2020-07-21 12:31 ` Philippe Mathieu-Daudé [this message]
2020-07-21 12:33 ` [RFC PATCH-for-5.1? v3 1/2] memory: Allow monkey-patching MemoryRegion access sizes Peter Maydell
2020-07-21 12:39 ` Philippe Mathieu-Daudé
2020-07-21 12:49 ` Peter Maydell
2020-07-21 14:23 ` Philippe Mathieu-Daudé
2020-07-21 14:32 ` Peter Maydell
2020-07-21 12:31 ` [RFC PATCH-for-5.1? v3 2/2] hw/isa/isa-bus: Ensure ISA I/O regions are 8/16/32-bit accessible Philippe Mathieu-Daudé
2020-07-21 12:41 ` Peter Maydell
2020-07-21 12:55 ` 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=20200721123154.5302-2-f4bug@amsat.org \
--to=f4bug@amsat.org \
--cc=anthony.perard@citrix.com \
--cc=berrange@redhat.com \
--cc=mjt@tls.msk.ru \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.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).