* [PATCH v2 1/1] drm/mediatek: Fix potential KP on 0 bytes nvmem cell read
@ 2024-09-27 9:03 Liankun Yang
2024-10-09 15:41 ` Guillaume Ranquet
2024-10-23 5:15 ` CK Hu (胡俊光)
0 siblings, 2 replies; 4+ messages in thread
From: Liankun Yang @ 2024-09-27 9:03 UTC (permalink / raw)
To: chunkuang.hu, p.zabel, airlied, simona, matthias.bgg,
angelogioacchino.delregno, rex-bc.chen, msp, granquet, ck.hu,
jitao.shi, mac.shen, peng.liu, liankun.yang
Cc: Project_Global_Chrome_Upstream_Group, dri-devel, linux-mediatek,
linux-kernel, linux-arm-kernel
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 <liankun.yang@mediatek.com>
---
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/20240925084116.28848-1-liankun.yang@mediatek.com/
---
drivers/gpu/drm/mediatek/mtk_dp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/mediatek/mtk_dp.c b/drivers/gpu/drm/mediatek/mtk_dp.c
index d8796a904eca..9ecdf62398ee 100644
--- a/drivers/gpu/drm/mediatek/mtk_dp.c
+++ b/drivers/gpu/drm/mediatek/mtk_dp.c
@@ -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))
--
2.45.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2 1/1] drm/mediatek: Fix potential KP on 0 bytes nvmem cell read
2024-09-27 9:03 [PATCH v2 1/1] drm/mediatek: Fix potential KP on 0 bytes nvmem cell read Liankun Yang
@ 2024-10-09 15:41 ` Guillaume Ranquet
2024-10-28 13:18 ` LIANKUN YANG (杨连坤)
2024-10-23 5:15 ` CK Hu (胡俊光)
1 sibling, 1 reply; 4+ messages in thread
From: Guillaume Ranquet @ 2024-10-09 15:41 UTC (permalink / raw)
To: Liankun Yang, chunkuang.hu, p.zabel, airlied, simona,
matthias.bgg, angelogioacchino.delregno, rex-bc.chen, msp, ck.hu,
jitao.shi, mac.shen, peng.liu
Cc: Project_Global_Chrome_Upstream_Group, dri-devel, linux-mediatek,
linux-kernel, linux-arm-kernel
On Fri, 27 Sep 2024 11:03, Liankun Yang <liankun.yang@mediatek.com> wrote:
>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 <liankun.yang@mediatek.com>
>---
>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/20240925084116.28848-1-liankun.yang@mediatek.com/
>---
> drivers/gpu/drm/mediatek/mtk_dp.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/drivers/gpu/drm/mediatek/mtk_dp.c b/drivers/gpu/drm/mediatek/mtk_dp.c
>index d8796a904eca..9ecdf62398ee 100644
>--- a/drivers/gpu/drm/mediatek/mtk_dp.c
>+++ b/drivers/gpu/drm/mediatek/mtk_dp.c
>@@ -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.
>
> if (!IS_ERR(buf))
>--
>2.45.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2 1/1] drm/mediatek: Fix potential KP on 0 bytes nvmem cell read
2024-09-27 9:03 [PATCH v2 1/1] drm/mediatek: Fix potential KP on 0 bytes nvmem cell read Liankun Yang
2024-10-09 15:41 ` Guillaume Ranquet
@ 2024-10-23 5:15 ` CK Hu (胡俊光)
1 sibling, 0 replies; 4+ messages in thread
From: CK Hu (胡俊光) @ 2024-10-23 5:15 UTC (permalink / raw)
To: Peng Liu (刘鹏), Mac Shen (沈俊),
chunkuang.hu@kernel.org, simona@ffwll.ch,
Jitao Shi (石记涛),
LIANKUN YANG (杨连坤), p.zabel@pengutronix.de,
granquet@baylibre.com, airlied@gmail.com, msp@baylibre.com,
matthias.bgg@gmail.com, Rex-BC Chen (陳柏辰),
AngeloGioacchino Del Regno
Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
linux-mediatek@lists.infradead.org,
linux-arm-kernel@lists.infradead.org,
Project_Global_Chrome_Upstream_Group
Hi, Liankun:
On Fri, 2024-09-27 at 17:03 +0800, Liankun Yang wrote:
> 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 <liankun.yang@mediatek.com>
> ---
> 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/20240925084116.28848-1-liankun.yang@mediatek.com/
> ---
> drivers/gpu/drm/mediatek/mtk_dp.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/mediatek/mtk_dp.c b/drivers/gpu/drm/mediatek/mtk_dp.c
> index d8796a904eca..9ecdf62398ee 100644
> --- a/drivers/gpu/drm/mediatek/mtk_dp.c
> +++ b/drivers/gpu/drm/mediatek/mtk_dp.c
> @@ -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
> + if (IS_ERR(buf) || !len || ((len / sizeof(u32)) != 4)) {
> dev_warn(dev, "Failed to read nvmem_cell_read\n");
>
> if (!IS_ERR(buf))
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2 1/1] drm/mediatek: Fix potential KP on 0 bytes nvmem cell read
2024-10-09 15:41 ` Guillaume Ranquet
@ 2024-10-28 13:18 ` LIANKUN YANG (杨连坤)
0 siblings, 0 replies; 4+ messages in thread
From: LIANKUN YANG (杨连坤) @ 2024-10-28 13:18 UTC (permalink / raw)
To: Peng Liu (刘鹏), Mac Shen (沈俊),
chunkuang.hu@kernel.org, simona@ffwll.ch,
Jitao Shi (石记涛), p.zabel@pengutronix.de,
granquet@baylibre.com, CK Hu (胡俊光),
airlied@gmail.com, msp@baylibre.com, matthias.bgg@gmail.com,
Rex-BC Chen (陳柏辰),
AngeloGioacchino Del Regno
Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
linux-mediatek@lists.infradead.org,
linux-arm-kernel@lists.infradead.org,
Project_Global_Chrome_Upstream_Group
On Wed, 2024-10-09 at 08:41 -0700, Guillaume Ranquet wrote:
>
> External email : Please do not click links or open attachments until
> you have verified the sender or the content.
> On Fri, 27 Sep 2024 11:03, Liankun Yang <liankun.yang@mediatek.com>
> wrote:
> >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 <liankun.yang@mediatek.com>
> >---
> >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/20240925084116.28848-1-liankun.yang@mediatek.com/
> >---
> > drivers/gpu/drm/mediatek/mtk_dp.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> >diff --git a/drivers/gpu/drm/mediatek/mtk_dp.c
> b/drivers/gpu/drm/mediatek/mtk_dp.c
> >index d8796a904eca..9ecdf62398ee 100644
> >--- a/drivers/gpu/drm/mediatek/mtk_dp.c
> >+++ b/drivers/gpu/drm/mediatek/mtk_dp.c
> >@@ -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.
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.
> >
> > if (!IS_ERR(buf))
> >--
> >2.45.2
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-10-28 13:18 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-27 9:03 [PATCH v2 1/1] drm/mediatek: Fix potential KP on 0 bytes nvmem cell read Liankun Yang
2024-10-09 15:41 ` Guillaume Ranquet
2024-10-28 13:18 ` LIANKUN YANG (杨连坤)
2024-10-23 5:15 ` CK Hu (胡俊光)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox