memory: drop guest writes to read-only ram device regions
PATCH v4 1/3 memory: drop guest writes to read-only ram device regions
for ram device regions, drop guest writes if the regions is read-only.
--- memory.c | 7 +++++++ 1 file changed, 7 insertions(+)
memory.c +7 -0
@@ -34,6 +34,7 @@#include "sysemu/accel.h" #include "hw/boards.h" #include "migration/vmstate.h" +#include "qemu/log.h" //#define DEBUG_UNASSIGNED
@@ -1313,6 +1314,12 @@ static void memory_region_ram_device_write(void *opaque, hwaddr addr,MemoryRegion *mr = opaque;trace_memory_region_ram_device_write (get_cpu_index (), mr, addr, data, size); +if (mr->readonly) { +qemu_log_mask (LOG_GUEST_ERROR , +"Invalid write to read only ram device region 0x%" + HWADDR_PRIx" size %u\n" , addr, size); +return ; + }switch (size) {case 1 :
Signature · 1 line
2.17.1
Quoted 25 lines · Yan Zhao
for ram device regions, drop guest writes if the regions is read-only.
Cc Philippe Mathieu-Daudé <[email protected]>Signed-off-by Yan Zhao <[email protected]>Signed-off-by Xin Zeng <[email protected]>--- memory.c | 7 +++++++ 1 file changed, 7 insertions(+)memory.c +1
-0@@ -34,6 +34,7 @@#include "sysemu/accel.h" #include "hw/boards.h" #include "migration/vmstate.h" +#include "qemu/log.h" //#define DEBUG_UNASSIGNED @@ -1313,6 +1314,12 @@ static void memory_region_ram_device_write(void *opaque, hwaddr addr,MemoryRegion *mr = opaque;
memory.c static void memory_region_ram_device_write(void *opaque, hwaddr addr, · line 1325
Quoted 10 lines
memory.c +6
-0trace_memory_region_ram_device_write (get_cpu_index (), mr, addr, data, size); +if (mr->readonly) { +qemu_log_mask (LOG_GUEST_ERROR , +"Invalid write to read only ram device region 0x%" + HWADDR_PRIx" size %u\n" , addr, size); +return ; + }switch (size) {case 1 :
Quoted 22 lines · Yan Zhao
for ram device regions, drop guest writes if the regions is read-only.
Cc Philippe Mathieu-Daudé <[email protected]>Signed-off-by Yan Zhao <[email protected]>Signed-off-by Xin Zeng <[email protected]>--- memory.c | 7 +++++++ 1 file changed, 7 insertions(+)memory.c +1
-0@@ -34,6 +34,7 @@#include "sysemu/accel.h" #include "hw/boards.h" #include "migration/vmstate.h" +#include "qemu/log.h" //#define DEBUG_UNASSIGNED
memory.c static void memory_region_ram_device_write(void *opaque, hwaddr addr, · line 1322
Quoted 9 lines
memory.c +6
-0@@ -1313,6 +1314,12 @@ static void memory_region_ram_device_write(void *opaque, hwaddr addr,MemoryRegion *mr = opaque;trace_memory_region_ram_device_write (get_cpu_index (), mr, addr, data, size); +if (mr->readonly) { +qemu_log_mask (LOG_GUEST_ERROR , +"Invalid write to read only ram device region 0x%" + HWADDR_PRIx" size %u\n" , addr, size); +return ; + }
As mentioned in the review of v1, memory_region_ram_device_write should be changed to a .write_with_attrs operation, so that it can return MEMTX_ERROR.
Otherwise this looks good.
Paolo
Quoted 37 lines · Paolo Bonzini
Quoted 22 lines · Yan Zhao
for ram device regions, drop guest writes if the regions is read-only.
Cc Philippe Mathieu-Daudé <[email protected]>Signed-off-by Yan Zhao <[email protected]>Signed-off-by Xin Zeng <[email protected]>--- memory.c | 7 +++++++ 1 file changed, 7 insertions(+)memory.c +1
-0@@ -34,6 +34,7 @@#include "sysemu/accel.h" #include "hw/boards.h" #include "migration/vmstate.h" +#include "qemu/log.h" //#define DEBUG_UNASSIGNED memory.c static void memory_region_ram_device_write(void *opaque, hwaddr addr, · line 1322
Quoted 9 lines
memory.c +6
-0@@ -1313,6 +1314,12 @@ static void memory_region_ram_device_write(void *opaque, hwaddr addr,MemoryRegion *mr = opaque;trace_memory_region_ram_device_write (get_cpu_index (), mr, addr, data, size); +if (mr->readonly) { +qemu_log_mask (LOG_GUEST_ERROR , +"Invalid write to read only ram device region 0x%" + HWADDR_PRIx" size %u\n" , addr, size); +return ; + }As mentioned in the review of v1,
memory_region_ram_device_writeshould be changed to a .write_with_attrs operation, so that it can returnMEMTX_ERROR.
Quoted 2 lines
Otherwise this looks good.
hi Paolo,
thanks for pointing it out again!
I didn't get your meaning in v1. will update the patch!
Thanks
Yan
Quoted 1 line
Quoted 26 lines · Yan Zhao
Quoted 25 lines · Paolo Bonzini
Quoted 24 lines · Yan Zhao
for ram device regions, drop guest writes if the regions is read-only.
Cc Philippe Mathieu-Daudé <[email protected]>Signed-off-by Yan Zhao <[email protected]>Signed-off-by Xin Zeng <[email protected]>--- memory.c | 7 +++++++ 1 file changed, 7 insertions(+)memory.c +1
-0@@ -34,6 +34,7 @@#include "sysemu/accel.h" #include "hw/boards.h" #include "migration/vmstate.h" +#include "qemu/log.h" //#define DEBUG_UNASSIGNED @@ -1313,6 +1314,12 @@ static void memory_region_ram_device_write(void *opaque, hwaddr addr,MemoryRegion *mr = opaque;
Quoted 12 lines
Quoted 8 lines
memory.c static void memory_region_ram_device_write(void *opaque, hwaddr addr, · line 1322
Quoted 7 lines
memory.c +6
-0trace_memory_region_ram_device_write (get_cpu_index (), mr, addr, data, size); +if (mr->readonly) { +qemu_log_mask (LOG_GUEST_ERROR , +"Invalid write to read only ram device region 0x%" + HWADDR_PRIx" size %u\n" , addr, size); +return ; + }Quoted 4 lines
As mentioned in the review of v1,
memory_region_ram_device_writeshould be changed to a .write_with_attrs operation, so that it can returnMEMTX_ERROR.
hi Paolo and Alex,
need I also change vfio_region_write() in patch 2 to a .write_with_attrs operation?vfio_region_read() is also possible to fail, so should I change it to a .read_with_attrs, too?
Thanks
Yan
Quoted 10 lines
Quoted 2 lines
Otherwise this looks good.
hi Paolo,
thanks for pointing it out again!
I didn't get your meaning in v1. will update the patch!Thanks
YanQuoted 1 line
Quoted 39 lines · Yan Zhao
Quoted 26 lines · Yan Zhao
Quoted 25 lines · Paolo Bonzini
Quoted 24 lines · Yan Zhao
for ram device regions, drop guest writes if the regions is read-only.
Cc Philippe Mathieu-Daudé <[email protected]>Signed-off-by Yan Zhao <[email protected]>Signed-off-by Xin Zeng <[email protected]>--- memory.c | 7 +++++++ 1 file changed, 7 insertions(+)memory.c +1
-0@@ -34,6 +34,7 @@#include "sysemu/accel.h" #include "hw/boards.h" #include "migration/vmstate.h" +#include "qemu/log.h" //#define DEBUG_UNASSIGNED @@ -1313,6 +1314,12 @@ static void memory_region_ram_device_write(void *opaque, hwaddr addr,MemoryRegion *mr = opaque;Quoted 12 lines
Quoted 8 lines
memory.c static void memory_region_ram_device_write(void *opaque, hwaddr addr, · line 1322
Quoted 7 lines
memory.c +6
-0trace_memory_region_ram_device_write (get_cpu_index (), mr, addr, data, size); +if (mr->readonly) { +qemu_log_mask (LOG_GUEST_ERROR , +"Invalid write to read only ram device region 0x%" + HWADDR_PRIx" size %u\n" , addr, size); +return ; + }Quoted 4 lines
As mentioned in the review of v1,
memory_region_ram_device_writeshould be changed to a .write_with_attrs operation, so that it can returnMEMTX_ERROR.
Quoted 5 lines
hi Paolo and Alex,
need I also changevfio_region_write()in patch 2 to a .write_with_attrs operation?vfio_region_read()is also possible to fail, so should I change it to a .read_with_attrs, too?
Yes.
Please submit your series as a thread, with a cover letter:
https://wiki.qemu.org/Contribute/SubmitAPatch#Include_a_meaningful_cover_letter
Quoted 15 lines
Thanks
YanQuoted 10 lines
Quoted 2 lines
Otherwise this looks good.
hi Paolo,
thanks for pointing it out again!
I didn't get your meaning in v1. will update the patch!Thanks
YanQuoted 1 line
Quoted 46 lines · Philippe Mathieu-Daudé
Quoted 39 lines · Yan Zhao
Quoted 26 lines · Yan Zhao
Quoted 25 lines · Paolo Bonzini
Quoted 24 lines · Yan Zhao
for ram device regions, drop guest writes if the regions is read-only.
Cc Philippe Mathieu-Daudé <[email protected]>Signed-off-by Yan Zhao <[email protected]>Signed-off-by Xin Zeng <[email protected]>--- memory.c | 7 +++++++ 1 file changed, 7 insertions(+)memory.c +1
-0@@ -34,6 +34,7 @@#include "sysemu/accel.h" #include "hw/boards.h" #include "migration/vmstate.h" +#include "qemu/log.h" //#define DEBUG_UNASSIGNED @@ -1313,6 +1314,12 @@ static void memory_region_ram_device_write(void *opaque, hwaddr addr,MemoryRegion *mr = opaque;Quoted 12 lines
Quoted 8 lines
memory.c static void memory_region_ram_device_write(void *opaque, hwaddr addr, · line 1322
Quoted 7 lines
memory.c +6
-0trace_memory_region_ram_device_write (get_cpu_index (), mr, addr, data, size); +if (mr->readonly) { +qemu_log_mask (LOG_GUEST_ERROR , +"Invalid write to read only ram device region 0x%" + HWADDR_PRIx" size %u\n" , addr, size); +return ; + }Quoted 4 lines
As mentioned in the review of v1,
memory_region_ram_device_writeshould be changed to a .write_with_attrs operation, so that it can returnMEMTX_ERROR.Quoted 5 lines
hi Paolo and Alex,
need I also changevfio_region_write()in patch 2 to a .write_with_attrs operation?vfio_region_read()is also possible to fail, so should I change it to a .read_with_attrs, too?
Quoted 5 lines
Yes.
Please submit your series as a thread, with a cover letter:
https://wiki.qemu.org/Contribute/SubmitAPatch#Include_a_meaningful_cover_letter
hi Philippe
thanks for pointing out this issue.
I just realized this version of patches were sent separately, though I did send a cover letter. not sure what happened. maybe I just forgot to add an -in-reply-to before sending out.
will pay attention to it next time.
Thanks
Yan
Quoted 16 lines
Quoted 15 lines
Thanks
YanQuoted 10 lines
Quoted 2 lines
Otherwise this looks good.
hi Paolo,
thanks for pointing it out again!
I didn't get your meaning in v1. will update the patch!Thanks
YanQuoted 1 line