[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v4 9/9] memory: assert MemoryRegionOps callbacks are defined
From: |
P J P |
Subject: |
[PATCH v4 9/9] memory: assert MemoryRegionOps callbacks are defined |
Date: |
Tue, 11 Aug 2020 17:11:33 +0530 |
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>
Reviewed-by: Li Qiang <liq3ea@gmail.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
---
softmmu/memory.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
Update v4: add Reviewed-by tag
-> https://lists.nongnu.org/archive/html/qemu-devel/2020-07/msg05324.html
diff --git a/softmmu/memory.c b/softmmu/memory.c
index af25987518..1f4b37b3a6 100644
--- a/softmmu/memory.c
+++ b/softmmu/memory.c
@@ -1485,7 +1485,13 @@ 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) {
+ assert(ops->read || ops->read_with_attrs);
+ assert(ops->write || ops->write_with_attrs);
+ mr->ops = ops;
+ } else {
+ mr->ops = &unassigned_mem_ops;
+ }
mr->opaque = opaque;
mr->terminates = true;
}
@@ -1663,6 +1669,8 @@ void memory_region_init_rom_device_nomigrate(MemoryRegion
*mr,
{
Error *err = NULL;
assert(ops);
+ assert(ops->read || ops->read_with_attrs);
+ assert(ops->write || ops->write_with_attrs);
memory_region_init(mr, owner, name, size);
mr->ops = ops;
mr->opaque = opaque;
--
2.26.2
- [PATCH v4 4/9] prep: add ppc-parity write method, (continued)
- [PATCH v4 4/9] prep: add ppc-parity write method, P J P, 2020/08/11
- [PATCH v4 5/9] nvram: add nrf51_soc flash read method, P J P, 2020/08/11
- [PATCH v4 6/9] spapr_pci: add spapr msi read method, P J P, 2020/08/11
- [PATCH v4 7/9] tz-ppc: add dummy read/write methods, P J P, 2020/08/11
- [PATCH v4 8/9] imx7-ccm: add digprog mmio write method, P J P, 2020/08/11
- [PATCH v4 9/9] memory: assert MemoryRegionOps callbacks are defined,
P J P <=
- Re: [PATCH v4 0/9] memory: assert and define MemoryRegionOps callbacks, David Gibson, 2020/08/13
- Re: [PATCH v4 0/9] memory: assert and define MemoryRegionOps callbacks, Philippe Mathieu-Daudé, 2020/08/16