[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] softmmu/memory: Validate {read, write}_with_attrs before calling
From: |
Bin Meng |
Subject: |
[PATCH] softmmu/memory: Validate {read, write}_with_attrs before calling |
Date: |
Sun, 5 Sep 2021 23:40:49 +0800 |
{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