cxl/hdm: Enhance handling of invalid decoders
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
@@ -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
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.
Signed-off-by Quanquan Cao <[email protected]>--- drivers/cxl/core/hdm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/cxl/core/hdm.c +0
-0
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.
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.
Signed-off-by Quanquan Cao <[email protected]>--- drivers/cxl/core/hdm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/cxl/core/hdm.c +0
-0drivers/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_MAXchecks were added for a device that returned all0xffffffffffffffffon 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.