Skip to contentSkip to conversation

drm/mediatek: Fix wrong check of nvmem_cell_read

PATCH In review Liankun Yang 2 participants 2 messages Sep 25, 2024 – Sep 26, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/mediatek: Fix wrong check of nvmem_cell_read

If the len is 0, kernel crash will occur when performing operations. Add the len check conditions to prevent kernel crash.

Fixes f70ac097a2cf ("drm/mediatek: Add MT8195 Embedded DisplayPort driver")
---
 drivers/gpu/drm/mediatek/mtk_dp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/mediatek/mtk_dp.c +1 -1
index d8796a904eca..0cc75ba96b98 100644
@@ -1082,7 +1082,7 @@ static void mtk_dp_get_calibration_data(struct mtk_dp *mtk_dp)
 	buf = (u32 *)nvmem_cell_read(cell, &len);
 	nvmem_cell_put(cell);
 
-	if (IS_ERR(buf) || ((len / sizeof(u32)) != 4)) {
+	if (IS_ERR(buf) || (len == 0) || ((len / sizeof(u32)) != 4)) {
 		dev_warn(dev, "Failed to read nvmem_cell_read\n");
 
 		if (!IS_ERR(buf))
Signature · 1 line
2.45.2
#1 lore raw

Il 25/09/24 10:40, Liankun Yang ha scritto:

Quoted 3 lines

If the len is 0, kernel crash will occur when performing operations. Add the len check conditions to prevent kernel crash.

Please fix the commit title:

drm/mediatek: mtk_dp: Fix potential KP on 0 bytes nvmem cell read

Quoted 2 lines
Fixes f70ac097a2cf ("drm/mediatek: Add MT8195 Embedded DisplayPort driver")

Please remove this blank line between the Fixes tag and your S-o-b.

Quoted 10 lines
---
  drivers/gpu/drm/mediatek/mtk_dp.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/mediatek/mtk_dp.c +0 -0
index d8796a904eca..0cc75ba96b98 100644

drivers/gpu/drm/mediatek/mtk_dp.c static void mtk_dp_get_calibration_data(struct mtk_dp *mtk_dp) · line 1085

Quoted 5 lines
drivers/gpu/drm/mediatek/mtk_dp.c +1 -1
@@ -1082,7 +1082,7 @@ static void mtk_dp_get_calibration_data(struct mtk_dp *mtk_dp)
  	buf = (u32 *)nvmem_cell_read(cell, &len);
  	nvmem_cell_put(cell);
 
-	if (IS_ERR(buf) || ((len / sizeof(u32)) != 4)) {
+	if (IS_ERR(buf) || (len == 0) || ((len / sizeof(u32)) != 4)) {

if (IS_ERR(buf) || !len || ((len / sizeof(u32)) != 4)) {

Cheers,
Angelo