Skip to contentSkip to conversation

hw/cxl: Two media operations related fixes.

PATCH In review Jonathan Cameron 2 participants 6 messages Jan 2 – Feb 6

lore
Share & tools
lore
#0 lore raw

cover hw/cxl: Two media operations related fixes.

Peter reported both of these last cycle. Both are related to sanity checking parameters.

Jonathan Cameron (2):
hw/cxl: Check for overflow on santize media as both base and offset

    64bit.

hw/cxl: Take into account how many media operations are requested for
param check

 hw/cxl/cxl-mailbox-utils.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
Signature · 1 line
2.48.1
#1 lore raw

PATCH 1/2 hw/cxl: Check for overflow on santize media as both base and offset 64bit.

The both the size and base of a media sanitize operation are both provided by the VM, an overflow is possible which may result in checks on valid range passing when they should not. Close that by checking for overflow on the addition.

Fixes 40ab4ed10775 ("hw/cxl/cxl-mailbox-utils: Media operations Sanitize and Write Zeros commands CXL r3.2(8.2.10.9.5.3)")
---
 hw/cxl/cxl-mailbox-utils.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
hw/cxl/cxl-mailbox-utils.c +7 -2
index a64b8ba5351f..d8f62a13a8ec 100644
@@ -2411,7 +2411,7 @@ static uint64_t get_dc_size(CXLType3Dev *ct3d, MemoryRegion **dc_mr)
 static int validate_dpa_addr(CXLType3Dev *ct3d, uint64_t dpa_addr,
                              size_t length)
 {
-    uint64_t vmr_size, pmr_size, dc_size;
+    uint64_t vmr_size, pmr_size, dc_size, dpa_end;
 
     if ((dpa_addr % CXL_CACHE_LINE_SIZE) ||
         (length % CXL_CACHE_LINE_SIZE)  ||
@@ -2423,7 +2423,12 @@ static int validate_dpa_addr(CXLType3Dev *ct3d, uint64_t dpa_addr,
     pmr_size = get_pmr_size(ct3d, NULL);
     dc_size = get_dc_size(ct3d, NULL);
 
-    if (dpa_addr + length > vmr_size + pmr_size + dc_size) {
+    /* sanitize 64 bit values coming from guest */
+    if (uadd64_overflow(dpa_addr, length, &dpa_end)) {
+        return -EINVAL;
+    }
+
+    if (dpa_end > vmr_size + pmr_size + dc_size) {
         return -EINVAL;
     }
 
Signature · 1 line
2.48.1
#2 lore raw

PATCH 2/2 hw/cxl: Take into account how many media operations are requested for param check

In reply to Jonathan Cameron

Whilst the spec doesn't speak to it directly my assumption is that a request for more operations than exist should result in an invalid input error return.

Fixes 77a8e9fe0ecb ("hw/cxl/cxl-mailbox-utils: Add support for Media operations discovery commands cxl r3.2 (8.2.10.9.5.3)")
---
 hw/cxl/cxl-mailbox-utils.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/cxl/cxl-mailbox-utils.c +1 -1
index d8f62a13a8ec..2f449980cdc0 100644
@@ -2547,7 +2547,7 @@ static CXLRetCode media_operations_discovery(uint8_t *payload_in,
      * sub class command.
      */
     if (media_op_in_disc_pl->dpa_range_count ||
-        start_index > ARRAY_SIZE(media_op_matrix)) {
+        start_index + num_ops > ARRAY_SIZE(media_op_matrix)) {
         return CXL_MBOX_INVALID_INPUT;
     }
 
Signature · 1 line
2.48.1
#3 lore raw
In reply to Jonathan Cameron
Quoted 2 lines · On Fri, 2 Jan 2026 15:47:29 +0000 Jonathan Cameron…

Peter reported both of these last cycle. Both are related to sanity checking parameters.

Hi Michael

Just a reminder to take a look at and if possible queue these up.

I see I didn't +CC Peter. Sorry about that Peter. If you could sanity check as they are fixes for bugs you reported a while back.

Thanks,

Jonathan

Quoted 10 lines

Jonathan Cameron (2):
hw/cxl: Check for overflow on santize media as both base and offset

    64bit.

hw/cxl: Take into account how many media operations are requested for
param check

 hw/cxl/cxl-mailbox-utils.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
#4 lore raw
In reply to Jonathan Cameron
Quoted 11 lines · Jonathan Cameron via

Peter reported both of these last cycle. Both are related to sanity checking parameters.

Jonathan Cameron (2):
hw/cxl: Check for overflow on santize media as both base and offset

     64bit.

hw/cxl: Take into account how many media operations are requested for
param check

  hw/cxl/cxl-mailbox-utils.c | 11 ++++++++---
  1 file changed, 8 insertions(+), 3 deletions(-)

Is this one worth picking up for qemu-stable (10.1.x & 10.2.x)?

Thanks,

/mjt

#5 lore raw
Quoted 10 lines · On Fri, 6 Feb 2026 01:11:55 +0300 Michael Tokarev <[email protected]> wrote:
Quoted 9 lines · Jonathan Cameron via

Peter reported both of these last cycle. Both are related to sanity checking parameters.

Jonathan Cameron (2):
hw/cxl: Check for overflow on santize media as both base and offset

     64bit.

hw/cxl: Take into account how many media operations are requested for
param check

Quoted 5 lines
Quoted 2 lines
  hw/cxl/cxl-mailbox-utils.c | 11 ++++++++---
  1 file changed, 8 insertions(+), 3 deletions(-)  

Is this one worth picking up for qemu-stable (10.1.x & 10.2.x)?

They are fairly obscure features but if it applies cleanly it seems sensible to backport.

Thanks

Jonathan

Quoted 3 lines

Thanks,

/mjt