mmc: dw_mmc: Fix out-of-bounds access for slot's caps
Add num_caps field for dw_mci_drv_data to validate the controller
id from DT alias and non-DT ways.
Reported-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
Fixes: 800d78bfcc
("mmc: dw_mmc: add support for implementation specific callbacks")
Cc: <stable@vger.kernel.org>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
This commit is contained in:
@@ -2804,8 +2804,15 @@ static int dw_mci_init_slot_caps(struct dw_mci_slot *slot)
|
||||
} else {
|
||||
ctrl_id = to_platform_device(host->dev)->id;
|
||||
}
|
||||
if (drv_data && drv_data->caps)
|
||||
|
||||
if (drv_data && drv_data->caps) {
|
||||
if (ctrl_id >= drv_data->num_caps) {
|
||||
dev_err(host->dev, "invalid controller id %d\n",
|
||||
ctrl_id);
|
||||
return -EINVAL;
|
||||
}
|
||||
mmc->caps |= drv_data->caps[ctrl_id];
|
||||
}
|
||||
|
||||
if (host->pdata->caps2)
|
||||
mmc->caps2 = host->pdata->caps2;
|
||||
|
Reference in New Issue
Block a user