hw/cxl: Fix read from bogus memory
PATCH 1/1 hw/cxl: Fix read from bogus memory
Peter and coverity report:
We've passed '&data' to address_space_write(), which means "read from the address on the stack where the function argument 'data' lives", so instead of writing 64 bytes of data to the guest , we'll write 64 bytes which start with a host pointer value and then continue with whatever happens to be on the host stack after that.
Indeed the intention was to write 64 bytes of data at the address given.
Fix the parameter to address_space_write().
---
Compile tested only. Jonathan please double check me.
--- hw/mem/cxl_type3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/mem/cxl_type3.c +1 -1
@@ -1025,7 +1025,7 @@ static bool set_cacheline(CXLType3Dev *ct3d, uint64_t dpa_offset, uint8_t *data) as = &ct3d->hostpmem_as; } -address_space_write (as, dpa_offset,MEMTXATTRS_UNSPECIFIED , &data, +address_space_write (as, dpa_offset,MEMTXATTRS_UNSPECIFIED , data,CXL_CACHE_LINE_SIZE );return true; }
---
base-commit: 3b2fe44bb7f605f179e5e7feb2c13c2eb3abbb80
change-id: 20240531-fix-poison-set-cacheline-e32bc1e74b27
Best regards,
Signature · 1 line
Ira Weiny <[email protected]>
Quoted 10 lines · Ira Weiny
Peter and coverity report:
We've passed '&data' to
address_space_write(), which means "read from the address on the stack where the function argument 'data' lives", so instead of writing 64 bytes of data to the guest , we'll write 64 bytes which start with a host pointer value and then continue with whatever happens to be on the host stack after that.
Quoted 4 lines
Indeed the intention was to write 64 bytes of data at the address given.
Fix the parameter to
address_space_write().
Coverity CID: 1544772
Quoted 16 lines
Reported-by Peter Maydell <[email protected]>Link https://lore.kernel.org/all/CAFEAcA-u4sytGwTKsb__Y+_+0O2-WwARntm3x8WNhvL1WfHOBg@mail.gmail.com/ open hereFixes 6bda41a69bdc ("hw/cxl: Add clear poison mailbox command support.")Cc Jonathan Cameron <[email protected]>Signed-off-by Ira Weiny <[email protected]>---
Compile tested only. Jonathan please double check me.--- hw/mem/cxl_type3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/mem/cxl_type3.c +0
-0
hw/mem/cxl_type3.c static bool set_cacheline(CXLType3Dev *ct3d, uint64_t dpa_offset, uint8_t *data) · line 1031
Quoted 8 lines
hw/mem/cxl_type3.c +1
-1@@ -1025,7 +1025,7 @@ static bool set_cacheline(CXLType3Dev *ct3d, uint64_t dpa_offset, uint8_t *data) as = &ct3d->hostpmem_as; } -address_space_write (as, dpa_offset,MEMTXATTRS_UNSPECIFIED , &data, +address_space_write (as, dpa_offset,MEMTXATTRS_UNSPECIFIED , data,CXL_CACHE_LINE_SIZE );return true; }
thanks
-- PMM
Quoted 11 lines · Ira Weiny
Peter and coverity report:
We've passed '&data' to
address_space_write(), which means "read from the address on the stack where the function argument 'data' lives", so instead of writing 64 bytes of data to the guest , we'll write 64 bytes which start with a host pointer value and then continue with whatever happens to be on the host stack after that.Indeed the intention was to write 64 bytes of data at the address given.
Quoted 7 lines
Fix the parameter to
address_space_write().Reported-by Peter Maydell <[email protected]>Link https://lore.kernel.org/all/CAFEAcA-u4sytGwTKsb__Y+_+0O2-WwARntm3x8WNhvL1WfHOBg@mail.gmail.com/ open hereFixes 6bda41a69bdc ("hw/cxl: Add clear poison mailbox command support.")Cc Jonathan Cameron <[email protected]>Signed-off-by Ira Weiny <[email protected]>
I'll queue it for the next pull which should go out soonish.
Quoted 27 lines
---
Compile tested only. Jonathan please double check me.--- hw/mem/cxl_type3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/mem/cxl_type3.c +1
-2@@ -1025,7 +1025,7 @@ static bool set_cacheline(CXLType3Dev *ct3d, uint64_t dpa_offset, uint8_t *data) as = &ct3d->hostpmem_as; } -address_space_write (as, dpa_offset,MEMTXATTRS_UNSPECIFIED , &data, +address_space_write (as, dpa_offset,MEMTXATTRS_UNSPECIFIED , data,CXL_CACHE_LINE_SIZE );return true; } ---base-commit:
3b2fe44bb7f605f179e5e7feb2c13c2eb3abbb80
change-id: 20240531-fix-poison-set-cacheline-e32bc1e74b27Best regards,
Signature · 1 line
Ira Weiny <[email protected]>
Quoted 13 lines · On Fri, 31 May 2024 11:22:05 -0500 Ira Weiny <[email protected]> wrote:
Peter and coverity report:
We've passed '&data' to
address_space_write(), which means "read from the address on the stack where the function argument 'data' lives", so instead of writing 64 bytes of data to the guest , we'll write 64 bytes which start with a host pointer value and then continue with whatever happens to be on the host stack after that.Indeed the intention was to write 64 bytes of data at the address given.
Fix the parameter to
address_space_write().
Quoted 7 lines
Reported-by Peter Maydell <[email protected]>Link https://lore.kernel.org/all/CAFEAcA-u4sytGwTKsb__Y+_+0O2-WwARntm3x8WNhvL1WfHOBg@mail.gmail.com/ open hereFixes 6bda41a69bdc ("hw/cxl: Add clear poison mailbox command support.")Cc Jonathan Cameron <[email protected]>Signed-off-by Ira Weiny <[email protected]>---
Compile tested only. Jonathan please double check me.
Looks good to me.
Quoted 23 lines
--- hw/mem/cxl_type3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/mem/cxl_type3.c +1
-2@@ -1025,7 +1025,7 @@ static bool set_cacheline(CXLType3Dev *ct3d, uint64_t dpa_offset, uint8_t *data) as = &ct3d->hostpmem_as; } -address_space_write (as, dpa_offset,MEMTXATTRS_UNSPECIFIED , &data, +address_space_write (as, dpa_offset,MEMTXATTRS_UNSPECIFIED , data,CXL_CACHE_LINE_SIZE );return true; } ---base-commit:
3b2fe44bb7f605f179e5e7feb2c13c2eb3abbb80
change-id: 20240531-fix-poison-set-cacheline-e32bc1e74b27Best regards,
Quoted 18 lines · Ira Weiny
Peter and coverity report:
We've passed '&data' to
address_space_write(), which means "read from the address on the stack where the function argument 'data' lives", so instead of writing 64 bytes of data to the guest , we'll write 64 bytes which start with a host pointer value and then continue with whatever happens to be on the host stack after that.Indeed the intention was to write 64 bytes of data at the address given.
Fix the parameter to
address_space_write().Reported-by Peter Maydell <[email protected]>Link https://lore.kernel.org/all/CAFEAcA-u4sytGwTKsb__Y+_+0O2-WwARntm3x8WNhvL1WfHOBg@mail.gmail.com/ open hereFixes 6bda41a69bdc ("hw/cxl: Add clear poison mailbox command support.")Cc Jonathan Cameron <[email protected]>Signed-off-by Ira Weiny <[email protected]>
Quoted 5 lines
---
Compile tested only. Jonathan please double check me.--- hw/mem/cxl_type3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Thanks, patch queued.
Quoted 25 lines · Philippe Mathieu-Daudé
Quoted 18 lines · Ira Weiny
Peter and coverity report:
We've passed '&data' to
address_space_write(), which means "read from the address on the stack where the function argument 'data' lives", so instead of writing 64 bytes of data to the guest , we'll write 64 bytes which start with a host pointer value and then continue with whatever happens to be on the host stack after that.Indeed the intention was to write 64 bytes of data at the address given.
Fix the parameter to
address_space_write().Reported-by Peter Maydell <[email protected]>Link https://lore.kernel.org/all/CAFEAcA-u4sytGwTKsb__Y+_+0O2-WwARntm3x8WNhvL1WfHOBg@mail.gmail.com/ open hereFixes 6bda41a69bdc ("hw/cxl: Add clear poison mailbox command support.")Cc Jonathan Cameron <[email protected]>Signed-off-by Ira Weiny <[email protected]>Quoted 5 lines
---
Compile tested only. Jonathan please double check me.--- hw/mem/cxl_type3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 1 line
Thanks, patch queued.
Had it queued too but sure, I can drop.
Signature · 1 line
MST
Quoted 26 lines · Michael S. Tsirkin
Quoted 25 lines · Philippe Mathieu-Daudé
Quoted 23 lines · Ira Weiny
Peter and coverity report:
We've passed '&data' to
address_space_write(), which means "read from the address on the stack where the function argument 'data' lives", so instead of writing 64 bytes of data to the guest , we'll write 64 bytes which start with a host pointer value and then continue with whatever happens to be on the host stack after that.Indeed the intention was to write 64 bytes of data at the address given.
Fix the parameter to
address_space_write().Reported-by Peter Maydell <[email protected]>Link https://lore.kernel.org/all/CAFEAcA-u4sytGwTKsb__Y+_+0O2-WwARntm3x8WNhvL1WfHOBg@mail.gmail.com/ open hereFixes 6bda41a69bdc ("hw/cxl: Add clear poison mailbox command support.")Cc Jonathan Cameron <[email protected]>Signed-off-by Ira Weiny <[email protected]>---
Compile tested only. Jonathan please double check me.--- hw/mem/cxl_type3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 3 lines
Quoted 1 line
Thanks, patch queued.
Had it queued too but sure, I can drop.
Sorry I didn't notice that along with your R-b tag, my bad.
Don't modify your branch, I'm dropping it.
Regards,
Phil.