qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] softmmu/memory: Validate {read, write}_with_attrs before calling
@ 2021-09-05 15:40 Bin Meng
  2021-09-05 16:16 ` Philippe Mathieu-Daudé
  2021-09-05 16:29 ` Peter Maydell
  0 siblings, 2 replies; 8+ messages in thread
From: Bin Meng @ 2021-09-05 15:40 UTC (permalink / raw)
  To: David Hildenbrand, Paolo Bonzini, Peter Xu
  Cc: Peter Maydell, Philippe Mathieu-Daudé, qemu-devel

{read,write}_with_attrs might be missing, and the codes currently do
not validate them before calling, which will cause segment fault.

Fixes: 62a0db942dec ("memory: Remove old_mmio accessors")
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
---

 softmmu/memory.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/softmmu/memory.c b/softmmu/memory.c
index bfedaf9c4d..b97ffd4ba7 100644
--- a/softmmu/memory.c
+++ b/softmmu/memory.c
@@ -1426,12 +1426,14 @@ static MemTxResult memory_region_dispatch_read1(MemoryRegion *mr,
                                          mr->ops->impl.max_access_size,
                                          memory_region_read_accessor,
                                          mr, attrs);
-    } else {
+    } else if (mr->ops->read_with_attrs) {
         return access_with_adjusted_size(addr, pval, size,
                                          mr->ops->impl.min_access_size,
                                          mr->ops->impl.max_access_size,
                                          memory_region_read_with_attrs_accessor,
                                          mr, attrs);
+    } else {
+        return MEMTX_ERROR;
     }
 }
 
@@ -1506,13 +1508,15 @@ MemTxResult memory_region_dispatch_write(MemoryRegion *mr,
                                          mr->ops->impl.max_access_size,
                                          memory_region_write_accessor, mr,
                                          attrs);
-    } else {
+    } else if (mr->ops->write_with_attrs) {
         return
             access_with_adjusted_size(addr, &data, size,
                                       mr->ops->impl.min_access_size,
                                       mr->ops->impl.max_access_size,
                                       memory_region_write_with_attrs_accessor,
                                       mr, attrs);
+    } else {
+        return MEMTX_ERROR;
     }
 }
 
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-09-06  6:53 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-09-05 15:40 [PATCH] softmmu/memory: Validate {read, write}_with_attrs before calling Bin Meng
2021-09-05 16:16 ` Philippe Mathieu-Daudé
2021-09-05 16:29 ` Peter Maydell
2021-09-05 16:49   ` Bin Meng
2021-09-05 16:53     ` Peter Maydell
2021-09-05 17:07       ` Bin Meng
2021-09-05 18:12         ` Peter Maydell
2021-09-06  6:51   ` [PATCH] softmmu/memory: Validate {read,write}_with_attrs " Paolo Bonzini

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).