drm/mediatek: Fix potential KP on 0 bytes nvmem cell read
Subsystems (3)
PATCH v2 1/1 drm/mediatek: Fix potential KP on 0 bytes nvmem cell read
If the len is 0, kernel crash will occur when performing operations. Add the len check conditions to prevent kernel crash.
---
Changes in V2:
- Fix the commit title.
- Remove blank line between the Fixes and Signe-off-by.
- Modify the judgment writing method.
Per suggestion from the previous thread:
https://patchwork.kernel.org/project/linux-mediatek/patch/[email protected]/
--- drivers/gpu/drm/mediatek/mtk_dp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
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 || ((len /sizeof (u32)) !=4 )) {dev_warn (dev,"Failed to read nvmem_cell_read\n" );if (!IS_ERR (buf))
Signature · 1 line
2.45.2
Quoted 21 lines · Liankun Yang
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")Signed-off-by Liankun Yang <[email protected]>---
Changes in V2:
- Fix the commit title.
- Remove blank line between the Fixes and Signe-off-by.
- Modify the judgment writing method.
Per suggestion from the previous thread:
https://patchwork.kernel.org/project/linux-mediatek/patch/[email protected]/
---drivers/gpu/drm/mediatek/mtk_dp.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/mediatek/mtk_dp.c +0
-0
drivers/gpu/drm/mediatek/mtk_dp.c static void mtk_dp_get_calibration_data(struct mtk_dp *mtk_dp) · line 1086
Quoted 6 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 || ((len /sizeof (u32)) !=4 )) {dev_warn (dev,"Failed to read nvmem_cell_read\n" );
Hello Liankun,
Would you be able to describe the crash with more details?
I'm afraid I don't understand the fix?
if len is 0, dividing 0 by sizeof(u32) is 0 and thus != 4 So to me, checking for len != 0 is redundant?
Thx,
Guillaume.
Quoted 4 lines
drivers/gpu/drm/mediatek/mtk_dp.c +0
-1if (!IS_ERR (buf)) --2.45.2
Quoted 40 lines · Guillaume Ranquet
External email : Please do not click links or open attachments until you have verified the sender or the content.
Quoted 4 lines · Liankun Yang
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 DisplayPortdriver")
Quoted 8 lines
Signed-off-by Liankun Yang <[email protected]>---
Changes in V2:
- Fix the commit title.
- Remove blank line between the Fixes and Signe-off-by.
- Modify the judgment writing method.
Per suggestion from the previous thread:https://patchwork.kernel.org/project/linux-mediatek/patch/[email protected]/
Review
Quoted 5 lines
---
drivers/gpu/drm/mediatek/mtk_dp.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)(quoted diff) +0
-0
b/drivers/gpu/drm/mediatek/mtk_dp.cdrivers/gpu/drm/mediatek/mtk_dp.c static void mtk_dp_get_calibration_data(struct
Quoted 4 lines
index
d8796a904eca..9ecdf62398ee100644drivers/gpu/drm/mediatek/mtk_dp.c +0
-0@@ -1082,7 +1082,7 @@ static void mtk_dp_get_calibration_data(struct
mtk_dp*mtk_dp)drivers/gpu/drm/mediatek/mtk_dp.c static void mtk_dp_get_calibration_data(struct mtk_dp *mtk_dp) · line 1086
Quoted 6 lines
drivers/gpu/drm/mediatek/mtk_dp.c +1
-1buf = (u32 *)nvmem_cell_read (cell, &len);nvmem_cell_put (cell); -if (IS_ERR (buf) || ((len /sizeof (u32)) !=4 )) { +if (IS_ERR (buf) || !len || ((len /sizeof (u32)) !=4 )) {dev_warn (dev,"Failed to read nvmem_cell_read\n" );Hello Liankun,
Would you be able to describe the crash with more details?
Quoted 7 lines
I'm afraid I don't understand the fix?
if len is 0, dividing 0 by sizeof(u32) is 0 and thus != 4 So to me, checking for len != 0 is redundant?
Thx,
Guillaume.
Hello Guillaume,
Thank you for your correction.
The check for len != 0 is redundant.
I did not review this patch carefully, and will review it again next time.
Thx,
Liankun.
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/mediatek/mtk_dp.c +0
-1if (!IS_ERR (buf)) --2.45.2
Hi, Liankun:
Quoted 21 lines · Liankun Yang
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")Signed-off-by Liankun Yang <[email protected]>---
Changes in V2:
- Fix the commit title.
- Remove blank line between the Fixes and Signe-off-by.
- Modify the judgment writing method.
Per suggestion from the previous thread:
https://patchwork.kernel.org/project/linux-mediatek/patch/[email protected]/--- drivers/gpu/drm/mediatek/mtk_dp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/mediatek/mtk_dp.c +0
-0
drivers/gpu/drm/mediatek/mtk_dp.c static void mtk_dp_get_calibration_data(struct mtk_dp *mtk_dp) · line 1085
Quoted 4 lines
drivers/gpu/drm/mediatek/mtk_dp.c +0
-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 )) {
In original code, when len = 0, no kernel panic occur. Nacked by me.
Regards,
CK
Quoted 4 lines
drivers/gpu/drm/mediatek/mtk_dp.c +1
-0+if (IS_ERR (buf) || !len || ((len /sizeof (u32)) !=4 )) {dev_warn (dev,"Failed to read nvmem_cell_read\n" );if (!IS_ERR (buf))