Skip to contentSkip to conversation

cxl/hdm: Enhance handling of invalid decoders

PATCH In review Quanquan Cao 2 participants 3 messages Jan 30, 2024 CXL

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cxl/hdm: Enhance handling of invalid decoders

Add the condition check "base + size < base", enhanced handling of invalid decoders. This check ensures the decoder's address range calculation won't overflow.

---
 drivers/cxl/core/hdm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cxl/core/hdm.c +1 -1
index 7d97790b893d..b8978d1c7a24 100644
@@ -816,7 +816,7 @@ static int init_hdm_decoder(struct cxl_port *port, struct cxl_decoder *cxld,
 
 	if (!committed)
 		size = 0;
-	if (base == U64_MAX || size == U64_MAX) {
+	if (base == U64_MAX || size == U64_MAX || base + size < base) {
 		dev_warn(&port->dev, "decoder%d.%d: Invalid resource range\n",
 			 port->id, cxld->id);
 		return -ENXIO;
Signature · 1 line
2.43.0
#1 lore raw
Quoted 14 lines · Quanquan Cao

Add the condition check "base + size < base", enhanced handling of invalid decoders. This check ensures the decoder's address range calculation won't overflow.

---
 drivers/cxl/core/hdm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cxl/core/hdm.c +0 -0
index 7d97790b893d..b8978d1c7a24 100644

drivers/cxl/core/hdm.c static int init_hdm_decoder(struct cxl_port *port, struct cxl_decoder *cxld, · line 819

Quoted 5 lines
drivers/cxl/core/hdm.c +1 -1
@@ -816,7 +816,7 @@ static int init_hdm_decoder(struct cxl_port *port, struct cxl_decoder *cxld,
 
 	if (!committed)
 		size = 0;
-	if (base == U64_MAX || size == U64_MAX) {
+	if (base == U64_MAX || size == U64_MAX || base + size < base) {

The U64_MAX checks were added for a device that returned all 0xffffffffffffffff on read. That happens to match the common expectation that a device or a bus in an error state starts returning that value to MMIO cycles. So this was less about validating that those values were sane and more about having a convenient point to detect that the device is returning the common indicator for MMIO failure.

Otherwise a device that reports an overflow condition is definitely broken, but it will be caught by other address validation code. So, I do not think this is suitable otherwise it would open the door for many other device validation checks.

I would change my mind if there was an example of this breakage in the wild causing real end user pain that is too late for the device hardware vendor to fix.

#2 lore raw
Quoted 29 lines
Quoted 14 lines · Quanquan Cao

Add the condition check "base + size < base", enhanced handling of invalid decoders. This check ensures the decoder's address range calculation won't overflow.

---
  drivers/cxl/core/hdm.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cxl/core/hdm.c +0 -0
index 7d97790b893d..b8978d1c7a24 100644

drivers/cxl/core/hdm.c static int init_hdm_decoder(struct cxl_port *port, struct cxl_decoder *cxld, · line 819

Quoted 5 lines
drivers/cxl/core/hdm.c +1 -1
@@ -816,7 +816,7 @@ static int init_hdm_decoder(struct cxl_port *port, struct cxl_decoder *cxld,
 
  	if (!committed)
  		size = 0;
-	if (base == U64_MAX || size == U64_MAX) {
+	if (base == U64_MAX || size == U64_MAX || base + size < base) {

The U64_MAX checks were added for a device that returned all 0xffffffffffffffff on read. That happens to match the common expectation that a device or a bus in an error state starts returning that value to MMIO cycles. So this was less about validating that those values were sane and more about having a convenient point to detect that the device is returning the common indicator for MMIO failure.

Quoted 9 lines

Otherwise a device that reports an overflow condition is definitely broken, but it will be caught by other address validation code. So, I do not think this is suitable otherwise it would open the door for many other device validation checks.

I would change my mind if there was an example of this breakage in the wild causing real end user pain that is too late for the device hardware vendor to fix.

Thanks, I got.