From a6867f93eff7d2df9f90eb5333d73136ec4b2260 Mon Sep 17 00:00:00 2001 From: Xinghai Cen Date: Wed, 28 Aug 2024 10:41:15 +0800 Subject: [PATCH 1/4] Revert "spi: Add verification for the max_frequency provided by the firmware" driver inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/IAMWY8 CVE: NA ------------------------------------------------- This reverts commit 8c9aeaf8e93de629208374d05813546a9b3a2e44. Fixes: 8c9aeaf8e93d ("spi: Add verification for the max_frequency provided by the firmware") Signed-off-by:lujunhua --- drivers/spi/spi-hisi-kunpeng.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/drivers/spi/spi-hisi-kunpeng.c b/drivers/spi/spi-hisi-kunpeng.c index 7625d6897322..cc73d50fc1b5 100644 --- a/drivers/spi/spi-hisi-kunpeng.c +++ b/drivers/spi/spi-hisi-kunpeng.c @@ -481,12 +481,6 @@ static int hisi_spi_probe(struct platform_device *pdev) return -EINVAL; } - if (host->max_speed_hz == 0) { - dev_err(dev, "invalid max SPI clocking speed, max-freq=%u\n", - host->max_speed_hz); - return -EINVAL; - } - ret = device_property_read_u16(dev, "num-cs", &host->num_chipselect); if (ret) -- Gitee From 456a1a6966db6031384ce813fa0dd5ed1be68322 Mon Sep 17 00:00:00 2001 From: Xinghai Cen Date: Wed, 28 Aug 2024 10:41:01 +0800 Subject: [PATCH 2/4] Revert "spi: hisi-kunpeng: Add validation for the minimum value of speed_hz" driver inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/IAMWY8 CVE: NA -------------------------------------------------- This reverts commit 51291a22864ada2fa64c7ed121c2be6b78893c64. Fixes: 51291a22864a ("spi: hisi-kunpeng: Add validation for the minimum value of speed_hz") Signed-off-by:lujunhua --- drivers/spi/spi-hisi-kunpeng.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/spi/spi-hisi-kunpeng.c b/drivers/spi/spi-hisi-kunpeng.c index cc73d50fc1b5..a4ce2ee11abc 100644 --- a/drivers/spi/spi-hisi-kunpeng.c +++ b/drivers/spi/spi-hisi-kunpeng.c @@ -495,7 +495,6 @@ static int hisi_spi_probe(struct platform_device *pdev) host->transfer_one = hisi_spi_transfer_one; host->handle_err = hisi_spi_handle_err; host->dev.fwnode = dev->fwnode; - host->min_speed_hz = DIV_ROUND_UP(host->max_speed_hz, CLK_DIV_MAX); hisi_spi_hw_init(hs); -- Gitee From 8f2ad3d7af1d1325c0296fbacc8e59b82a71b8e5 Mon Sep 17 00:00:00 2001 From: Devyn Liu Date: Tue, 30 Jul 2024 11:20:40 +0800 Subject: [PATCH 3/4] spi: hisi-kunpeng: Add verification for the max_frequency provided by the firmware mainline inclusion from mainline-v6.11-rc1 commit 5127c42c77de18651aa9e8e0a3ced190103b449c category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/IAMWY8 CVE: NA Reference: https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git/commit/drivers/spi/spi-hisi-kunpeng.c?id=5127c42c77de18651aa9e8e0a3ced190103b449c ------------------------------------------------- If the value of max_speed_hz is 0, it may cause a division by zero error in hisi_calc_effective_speed(). The value of max_speed_hz is provided by firmware. Firmware is generally considered as a trusted domain. However, as division by zero errors can cause system failure, for defense measure, the value of max_speed is validated here. So 0 is regarded as invalid and an error code is returned. Signed-off-by:lujunhua Signed-off-by: Devyn Liu Reviewed-by: Jay Fang Link: https://patch.msgid.link/20240730032040.3156393-3-liudingyuan@huawei.com Signed-off-by: Mark Brown --- drivers/spi/spi-hisi-kunpeng.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/spi/spi-hisi-kunpeng.c b/drivers/spi/spi-hisi-kunpeng.c index a4ce2ee11abc..3d5b31f8eca7 100644 --- a/drivers/spi/spi-hisi-kunpeng.c +++ b/drivers/spi/spi-hisi-kunpeng.c @@ -481,6 +481,9 @@ static int hisi_spi_probe(struct platform_device *pdev) return -EINVAL; } + if (host->max_speed_hz == 0) + return dev_err_probe(dev, -EINVAL, "spi-max-frequency can't be 0\n"); + ret = device_property_read_u16(dev, "num-cs", &host->num_chipselect); if (ret) -- Gitee From 694204ccbb18b8146981e031701da9ee12a76f36 Mon Sep 17 00:00:00 2001 From: Devyn Liu Date: Tue, 30 Jul 2024 11:20:39 +0800 Subject: [PATCH 4/4] spi: hisi-kunpeng: Add validation for the minimum value of speed_hz mainline inclusion from mainline-v6.11-rc1 commit c3c4f22b7c814a6ee485ce294065836f8ede30fa category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/IAMWY8 CVE: NA Reference: https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git/commit/drivers/spi/spi-hisi-kunpeng.c?id=c3c4f22b7c814a6ee485ce294065836f8ede30fa ------------------------------------- The speed specified by the user is used to calculate the clk_div based on the max_speed_hz in hisi_calc_effective_speed. A very low speed value can lead to a clk_div larger than the variable range. Avoid this by setting the min_speed_hz so that such a small speed value is rejected. __spi_validate() in spi.c will return -EINVAL for the specified speed_hz lower than min_speed_hz. Signed-off-by:lujunhua Signed-off-by: Devyn Liu Reviewed-by: Jay Fang Link: https://patch.msgid.link/20240730032040.3156393-2-liudingyuan@huawei.com Signed-off-by: Mark Brown --- drivers/spi/spi-hisi-kunpeng.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/spi/spi-hisi-kunpeng.c b/drivers/spi/spi-hisi-kunpeng.c index 3d5b31f8eca7..bc35f5ad02db 100644 --- a/drivers/spi/spi-hisi-kunpeng.c +++ b/drivers/spi/spi-hisi-kunpeng.c @@ -498,6 +498,7 @@ static int hisi_spi_probe(struct platform_device *pdev) host->transfer_one = hisi_spi_transfer_one; host->handle_err = hisi_spi_handle_err; host->dev.fwnode = dev->fwnode; + host->min_speed_hz = DIV_ROUND_UP(host->max_speed_hz, CLK_DIV_MAX); hisi_spi_hw_init(hs); -- Gitee