i3c: dw: limit the DAT depth to DW_I3C_MAX_DEVS
Subsystems (3)
PATCH 1/1 i3c: dw: limit the DAT depth to DW_I3C_MAX_DEVS
dw_i3c_common_probe() takes maxdevs from the upper 16 bits of DEVICE_ADDR_TABLE_POINTER, so it can be up to 65535. devs[] has DW_I3C_MAX_DEVS (32) entries. The DAA writes devs[pos].addr for each free position below maxdevs. dw_i3c_master_restore_addrs() and dw_i3c_master_get_addr_pos() read devs[pos] up to maxdevs. With a depth above 32, these accesses go past devs[].
A controller whose registers read as all ones reports a depth of 65535. GENMASK() in probe then shifts out of bounds, as reported on an AMD server.
Limit maxdevs to DW_I3C_MAX_DEVS.
Found with a CodeQL-based static analysis tool and compile-tested only with W=1.
---
I used an LLM to help write the harness and this patch.
drivers/i3c/master/dw-i3c-master.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i3c/master/dw-i3c-master.c +1 -1
@@ -1772,7 +1772,7 @@ int dw_i3c_common_probe(struct dw_i3c_master *master, ret =readl (master->regs +DEVICE_ADDR_TABLE_POINTER ); master->datstartaddr = ret; - master->maxdevs = ret >>16 ; + master->maxdevs =min_t (u16, ret >>16 ,DW_I3C_MAX_DEVS ); master->free_pos =GENMASK (master->maxdevs -1 ,0 );/*
Signature · 1 line
2.34.1
Quoted 32 lines · Maoyi Xie
dw_i3c_common_probe()takes maxdevs from the upper 16 bits ofDEVICE_ADDR_TABLE_POINTER, so it can be up to 65535. devs[] hasDW_I3C_MAX_DEVS(32) entries. The DAA writes devs[pos].addr for each free position below maxdevs.dw_i3c_master_restore_addrs()anddw_i3c_master_get_addr_pos()read devs[pos] up to maxdevs. With a depth above 32, these accesses go past devs[].A controller whose registers read as all ones reports a depth of 65535.
GENMASK()in probe then shifts out of bounds, as reported on an AMD server.Limit maxdevs to
DW_I3C_MAX_DEVS.Found with a CodeQL-based static analysis tool and compile-tested only with W=1.
Fixes 1dd728f5d4d4 ("i3c: master: Add driver for Synopsys DesignWare IP")Reported-by Louis Sautier <[email protected]>Signed-off-by Maoyi Xie <[email protected]>---
I used an LLM to help write the harness and this patch.drivers/i3c/master/dw-i3c-master.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/i3c/master/dw-i3c-master.c +0
-0
drivers/i3c/master/dw-i3c-master.c int dw_i3c_common_probe(struct dw_i3c_master *master, · line 1775
Quoted 5 lines
drivers/i3c/master/dw-i3c-master.c +1
-1@@ -1772,7 +1772,7 @@ int dw_i3c_common_probe(struct dw_i3c_master *master, ret =readl (master->regs +DEVICE_ADDR_TABLE_POINTER ); master->datstartaddr = ret; - master->maxdevs = ret >>16 ; + master->maxdevs =min_t (u16, ret >>16 ,DW_I3C_MAX_DEVS );
Please GEN_MASK and GET_FIELD, suppose only 5bit valid
Frank
Quoted 6 lines
drivers/i3c/master/dw-i3c-master.c +0
-1master->free_pos =GENMASK (master->maxdevs -1 ,0 );/* -- 2.34.1