* [Qemu-devel] [PATCH] memory: check write/read_with_attrs in memory dispatch
@ 2018-11-13 1:42 Li Qiang
2018-11-13 9:49 ` Peter Maydell
2018-11-21 3:23 ` Li Qiang
0 siblings, 2 replies; 4+ messages in thread
From: Li Qiang @ 2018-11-13 1:42 UTC (permalink / raw)
To: pbonzini, peter.maydell, marcandre.lureau, ppandit; +Cc: qemu-devel, Li Qiang
This can avoid the NULL-deref if the rm doesn't has a
read/write nor write/read_with_attrs callback.
Signed-off-by: Li Qiang <liq3ea@gmail.com>
---
memory.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/memory.c b/memory.c
index d14c6dec1d..3baf5857b9 100644
--- a/memory.c
+++ b/memory.c
@@ -1377,13 +1377,15 @@ 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);
}
+
+ return MEMTX_DECODE_ERROR;
}
MemTxResult memory_region_dispatch_read(MemoryRegion *mr,
@@ -1454,7 +1456,7 @@ 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,
@@ -1462,6 +1464,8 @@ MemTxResult memory_region_dispatch_write(MemoryRegion *mr,
memory_region_write_with_attrs_accessor,
mr, attrs);
}
+
+ return MEMTX_DECODE_ERROR;
}
void memory_region_init_io(MemoryRegion *mr,
--
2.11.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] memory: check write/read_with_attrs in memory dispatch
2018-11-13 1:42 [Qemu-devel] [PATCH] memory: check write/read_with_attrs in memory dispatch Li Qiang
@ 2018-11-13 9:49 ` Peter Maydell
2018-11-13 10:10 ` Li Qiang
2018-11-21 3:23 ` Li Qiang
1 sibling, 1 reply; 4+ messages in thread
From: Peter Maydell @ 2018-11-13 9:49 UTC (permalink / raw)
To: Li Qiang; +Cc: Paolo Bonzini, Marc-André Lureau, P J P, QEMU Developers
On 13 November 2018 at 01:42, Li Qiang <liq3ea@gmail.com> wrote:
> This can avoid the NULL-deref if the rm doesn't has a
> read/write nor write/read_with_attrs callback.
>
> Signed-off-by: Li Qiang <liq3ea@gmail.com>
> ---
> memory.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
Alternative approach -- assert that every MemoryRegionOps has
pointers to callbacks in it, when it is registered in memory_region_init_io()
and memory_region_init_rom_device_nomigrate().
I don't have a strong opinion on which is better, but I guess
I slightly favour requiring devices to be specific about what
their read/write behaviour is.
Do we have many devices that legitimately only want to implement
one of read and write, not both ?
thanks
-- PMM
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] memory: check write/read_with_attrs in memory dispatch
2018-11-13 9:49 ` Peter Maydell
@ 2018-11-13 10:10 ` Li Qiang
0 siblings, 0 replies; 4+ messages in thread
From: Li Qiang @ 2018-11-13 10:10 UTC (permalink / raw)
To: Peter Maydell
Cc: Paolo Bonzini, Marc-André Lureau, P J P, Qemu Developers
Peter Maydell <peter.maydell@linaro.org> 于2018年11月13日周二 下午5:49写道:
> On 13 November 2018 at 01:42, Li Qiang <liq3ea@gmail.com> wrote:
> > This can avoid the NULL-deref if the rm doesn't has a
> > read/write nor write/read_with_attrs callback.
> >
> > Signed-off-by: Li Qiang <liq3ea@gmail.com>
> > ---
> > memory.c | 8 ++++++--
> > 1 file changed, 6 insertions(+), 2 deletions(-)
>
> Alternative approach -- assert that every MemoryRegionOps has
> pointers to callbacks in it, when it is registered in
> memory_region_init_io()
>
Actually I have considered this approach, but I rember Paolo remind me that
some
of this MR without read callback's is valid because the read can never be
called, such as
'notdirty_mem_ops'. So I choose add a check here.
> and memory_region_init_rom_device_nomigrate().
>
> I don't have a strong opinion on which is better, but I guess
> I slightly favour requiring devices to be specific about what
> their read/write behaviour is.
>
> Do we have many devices that legitimately only want to implement
> one of read and write, not both ?
AFAICS, the device has just one read or write is not uncommon.
But nearly all of them implement a nop function does nothing.
So there just very little lack of the read or write function.
Thanks,
Li Qiang
>
> thanks
> -- PMM
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] memory: check write/read_with_attrs in memory dispatch
2018-11-13 1:42 [Qemu-devel] [PATCH] memory: check write/read_with_attrs in memory dispatch Li Qiang
2018-11-13 9:49 ` Peter Maydell
@ 2018-11-21 3:23 ` Li Qiang
1 sibling, 0 replies; 4+ messages in thread
From: Li Qiang @ 2018-11-21 3:23 UTC (permalink / raw)
To: Paolo Bonzini, Peter Maydell, Marc-André Lureau, P J P
Cc: Qemu Developers
Ping...
It makes sense as when we use 'memory_region_read_accessor' we check
mr->ops->read.
but when we use 'memory_region_read_with_attrs_accessor', we doesn't check
this.
Thanks,
Li Qiang
Li Qiang <liq3ea@gmail.com> 于2018年11月13日周二 上午9:42写道:
> This can avoid the NULL-deref if the rm doesn't has a
> read/write nor write/read_with_attrs callback.
>
> Signed-off-by: Li Qiang <liq3ea@gmail.com>
> ---
> memory.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/memory.c b/memory.c
> index d14c6dec1d..3baf5857b9 100644
> --- a/memory.c
> +++ b/memory.c
> @@ -1377,13 +1377,15 @@ 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);
> }
> +
> + return MEMTX_DECODE_ERROR;
> }
>
> MemTxResult memory_region_dispatch_read(MemoryRegion *mr,
> @@ -1454,7 +1456,7 @@ 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,
> @@ -1462,6 +1464,8 @@ MemTxResult
> memory_region_dispatch_write(MemoryRegion *mr,
>
> memory_region_write_with_attrs_accessor,
> mr, attrs);
> }
> +
> + return MEMTX_DECODE_ERROR;
> }
>
> void memory_region_init_io(MemoryRegion *mr,
> --
> 2.11.0
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-11-21 3:32 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-11-13 1:42 [Qemu-devel] [PATCH] memory: check write/read_with_attrs in memory dispatch Li Qiang
2018-11-13 9:49 ` Peter Maydell
2018-11-13 10:10 ` Li Qiang
2018-11-21 3:23 ` Li Qiang
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).