From: Bin Meng <bmeng.cn@gmail.com>
To: David Hildenbrand <david@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>, Peter Xu <peterx@redhat.com>
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
qemu-devel@nongnu.org
Subject: [PATCH] softmmu/memory: Validate {read, write}_with_attrs before calling
Date: Sun, 5 Sep 2021 23:40:49 +0800 [thread overview]
Message-ID: <20210905154049.7992-1-bmeng.cn@gmail.com> (raw)
{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
next reply other threads:[~2021-09-05 15:42 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-05 15:40 Bin Meng [this message]
2021-09-05 16:16 ` [PATCH] softmmu/memory: Validate {read, write}_with_attrs before calling 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
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=20210905154049.7992-1-bmeng.cn@gmail.com \
--to=bmeng.cn@gmail.com \
--cc=david@redhat.com \
--cc=f4bug@amsat.org \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.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).