* [PATCH v2] drm/mediatek: Clean dangling pointer on bind error path
@ 2022-11-22 14:39 Nícolas F. R. A. Prado
2022-11-23 9:15 ` AngeloGioacchino Del Regno
2023-01-27 15:12 ` Chun-Kuang Hu
0 siblings, 2 replies; 5+ messages in thread
From: Nícolas F. R. A. Prado @ 2022-11-22 14:39 UTC (permalink / raw)
To: Chun-Kuang Hu
Cc: kernel, Nancy . Lin, AngeloGioacchino Del Regno,
Nícolas F. R. A. Prado, CK Hu, Daniel Kurtz, Daniel Vetter,
David Airlie, Mao Huang, Matthias Brugger, Philipp Zabel,
YT Shen, dri-devel, linux-arm-kernel, linux-kernel,
linux-mediatek
mtk_drm_bind() can fail, in which case drm_dev_put() is called,
destroying the drm_device object. However a pointer to it was still
being held in the private object, and that pointer would be passed along
to DRM in mtk_drm_sys_prepare() if a suspend were triggered at that
point, resulting in a panic. Clean the pointer when destroying the
object in the error path to prevent this from happening.
Fixes: 119f5173628a ("drm/mediatek: Add DRM Driver for Mediatek SoC MT8173.")
Signed-off-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>
---
Changes in v2:
- Added Fixes tag
drivers/gpu/drm/mediatek/mtk_drm_drv.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.c b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
index 39a42dc8fb85..a21ff1b3258c 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
@@ -514,6 +514,7 @@ static int mtk_drm_bind(struct device *dev)
err_deinit:
mtk_drm_kms_deinit(drm);
err_free:
+ private->drm = NULL;
drm_dev_put(drm);
return ret;
}
--
2.38.1
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v2] drm/mediatek: Clean dangling pointer on bind error path 2022-11-22 14:39 [PATCH v2] drm/mediatek: Clean dangling pointer on bind error path Nícolas F. R. A. Prado @ 2022-11-23 9:15 ` AngeloGioacchino Del Regno 2022-11-25 16:34 ` Nícolas F. R. A. Prado 2023-01-27 15:12 ` Chun-Kuang Hu 1 sibling, 1 reply; 5+ messages in thread From: AngeloGioacchino Del Regno @ 2022-11-23 9:15 UTC (permalink / raw) To: Nícolas F. R. A. Prado, Chun-Kuang Hu Cc: kernel, Nancy . Lin, CK Hu, Daniel Kurtz, Daniel Vetter, David Airlie, Mao Huang, Matthias Brugger, Philipp Zabel, YT Shen, dri-devel, linux-arm-kernel, linux-kernel, linux-mediatek Il 22/11/22 15:39, Nícolas F. R. A. Prado ha scritto: > mtk_drm_bind() can fail, in which case drm_dev_put() is called, > destroying the drm_device object. However a pointer to it was still > being held in the private object, and that pointer would be passed along > to DRM in mtk_drm_sys_prepare() if a suspend were triggered at that > point, resulting in a panic. Clean the pointer when destroying the > object in the error path to prevent this from happening. > > Fixes: 119f5173628a ("drm/mediatek: Add DRM Driver for Mediatek SoC MT8173.") > Signed-off-by: Nícolas F. R. A. Prado <nfraprado@collabora.com> > > --- > > Changes in v2: > - Added Fixes tag > > drivers/gpu/drm/mediatek/mtk_drm_drv.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.c b/drivers/gpu/drm/mediatek/mtk_drm_drv.c > index 39a42dc8fb85..a21ff1b3258c 100644 > --- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c > +++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c > @@ -514,6 +514,7 @@ static int mtk_drm_bind(struct device *dev) > err_deinit: > mtk_drm_kms_deinit(drm); > err_free: > + private->drm = NULL; Sorry for not noticing that in v1, but I've rechecked this function and, while this commit does indeed actually solve the described issue, I think it's incomplete. A few lines before, we have a loop that sets private->all_drm_private[i]->drm = drm; ...so here you should do... private->drm = NULL; while (i--) /* a for loop will also do, your choice */ private->all_drm_private[i]->drm = NULL; That makes sure that you cleanup *everything* :-) Cheers, Angelo ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] drm/mediatek: Clean dangling pointer on bind error path 2022-11-23 9:15 ` AngeloGioacchino Del Regno @ 2022-11-25 16:34 ` Nícolas F. R. A. Prado 2022-11-28 13:09 ` AngeloGioacchino Del Regno 0 siblings, 1 reply; 5+ messages in thread From: Nícolas F. R. A. Prado @ 2022-11-25 16:34 UTC (permalink / raw) To: AngeloGioacchino Del Regno Cc: Chun-Kuang Hu, kernel, Nancy . Lin, CK Hu, Daniel Kurtz, Daniel Vetter, David Airlie, Mao Huang, Matthias Brugger, Philipp Zabel, YT Shen, dri-devel, linux-arm-kernel, linux-kernel, linux-mediatek On Wed, Nov 23, 2022 at 10:15:25AM +0100, AngeloGioacchino Del Regno wrote: > Il 22/11/22 15:39, Nícolas F. R. A. Prado ha scritto: > > mtk_drm_bind() can fail, in which case drm_dev_put() is called, > > destroying the drm_device object. However a pointer to it was still > > being held in the private object, and that pointer would be passed along > > to DRM in mtk_drm_sys_prepare() if a suspend were triggered at that > > point, resulting in a panic. Clean the pointer when destroying the > > object in the error path to prevent this from happening. > > > > Fixes: 119f5173628a ("drm/mediatek: Add DRM Driver for Mediatek SoC MT8173.") > > Signed-off-by: Nícolas F. R. A. Prado <nfraprado@collabora.com> > > > > --- > > > > Changes in v2: > > - Added Fixes tag > > > > drivers/gpu/drm/mediatek/mtk_drm_drv.c | 1 + > > 1 file changed, 1 insertion(+) > > > > diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.c b/drivers/gpu/drm/mediatek/mtk_drm_drv.c > > index 39a42dc8fb85..a21ff1b3258c 100644 > > --- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c > > +++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c > > @@ -514,6 +514,7 @@ static int mtk_drm_bind(struct device *dev) > > err_deinit: > > mtk_drm_kms_deinit(drm); > > err_free: > > + private->drm = NULL; > > Sorry for not noticing that in v1, but I've rechecked this function and, while this > commit does indeed actually solve the described issue, I think it's incomplete. > > A few lines before, we have a loop that sets > > private->all_drm_private[i]->drm = drm; Actually that line only exists with [1] applied, but that commit hasn't been merged as of yet. I debated whether it would be better to send this fix as is, or ask Nancy Lin to add the tweaked fix you mention below to that series, but sending this fix as is seemed better since it can be backported to older kernel versions. So assuming this commit gets merged first, Nancy should make that tweak you mentioned below to ensure all the pointers are zeroed out, which is why I've added Nancy to CC. (As a side note, given that only the mmsys with drm_master = true would ever call the drm suspend helper, even this patch as is is enough to avoid the panic even with that series applied, still we should zero out all pointers for good measure) [1] https://lore.kernel.org/linux-mediatek/20221107072413.16178-6-nancy.lin@mediatek.com/ Thanks, Nícolas > > ...so here you should do... > > private->drm = NULL; > > while (i--) /* a for loop will also do, your choice */ > private->all_drm_private[i]->drm = NULL; > > That makes sure that you cleanup *everything* :-) > > Cheers, > Angelo > ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] drm/mediatek: Clean dangling pointer on bind error path 2022-11-25 16:34 ` Nícolas F. R. A. Prado @ 2022-11-28 13:09 ` AngeloGioacchino Del Regno 0 siblings, 0 replies; 5+ messages in thread From: AngeloGioacchino Del Regno @ 2022-11-28 13:09 UTC (permalink / raw) To: Nícolas F. R. A. Prado Cc: Chun-Kuang Hu, kernel, Nancy . Lin, CK Hu, Daniel Kurtz, Daniel Vetter, David Airlie, Mao Huang, Matthias Brugger, Philipp Zabel, YT Shen, dri-devel, linux-arm-kernel, linux-kernel, linux-mediatek Il 25/11/22 17:34, Nícolas F. R. A. Prado ha scritto: > On Wed, Nov 23, 2022 at 10:15:25AM +0100, AngeloGioacchino Del Regno wrote: >> Il 22/11/22 15:39, Nícolas F. R. A. Prado ha scritto: >>> mtk_drm_bind() can fail, in which case drm_dev_put() is called, >>> destroying the drm_device object. However a pointer to it was still >>> being held in the private object, and that pointer would be passed along >>> to DRM in mtk_drm_sys_prepare() if a suspend were triggered at that >>> point, resulting in a panic. Clean the pointer when destroying the >>> object in the error path to prevent this from happening. >>> >>> Fixes: 119f5173628a ("drm/mediatek: Add DRM Driver for Mediatek SoC MT8173.") >>> Signed-off-by: Nícolas F. R. A. Prado <nfraprado@collabora.com> >>> >>> --- >>> >>> Changes in v2: >>> - Added Fixes tag >>> >>> drivers/gpu/drm/mediatek/mtk_drm_drv.c | 1 + >>> 1 file changed, 1 insertion(+) >>> >>> diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.c b/drivers/gpu/drm/mediatek/mtk_drm_drv.c >>> index 39a42dc8fb85..a21ff1b3258c 100644 >>> --- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c >>> +++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c >>> @@ -514,6 +514,7 @@ static int mtk_drm_bind(struct device *dev) >>> err_deinit: >>> mtk_drm_kms_deinit(drm); >>> err_free: >>> + private->drm = NULL; >> >> Sorry for not noticing that in v1, but I've rechecked this function and, while this >> commit does indeed actually solve the described issue, I think it's incomplete. >> >> A few lines before, we have a loop that sets >> >> private->all_drm_private[i]->drm = drm; > > Actually that line only exists with [1] applied, but that commit hasn't been > merged as of yet. I debated whether it would be better to send this fix as is, > or ask Nancy Lin to add the tweaked fix you mention below to that series, but > sending this fix as is seemed better since it can be backported to older kernel > versions. > > So assuming this commit gets merged first, Nancy should make that tweak you > mentioned below to ensure all the pointers are zeroed out, which is why I've > added Nancy to CC. (As a side note, given that only the mmsys with drm_master = > true would ever call the drm suspend helper, even this patch as is is enough to > avoid the panic even with that series applied, still we should zero out all > pointers for good measure) > > [1] https://lore.kernel.org/linux-mediatek/20221107072413.16178-6-nancy.lin@mediatek.com/ > Sorry about that, you're right - the proposed fix is for the commit you linked, I got confused somehow. This means that you get my Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Cheers! ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] drm/mediatek: Clean dangling pointer on bind error path 2022-11-22 14:39 [PATCH v2] drm/mediatek: Clean dangling pointer on bind error path Nícolas F. R. A. Prado 2022-11-23 9:15 ` AngeloGioacchino Del Regno @ 2023-01-27 15:12 ` Chun-Kuang Hu 1 sibling, 0 replies; 5+ messages in thread From: Chun-Kuang Hu @ 2023-01-27 15:12 UTC (permalink / raw) To: Nícolas F. R. A. Prado Cc: Chun-Kuang Hu, kernel, Nancy . Lin, AngeloGioacchino Del Regno, CK Hu, Daniel Kurtz, Daniel Vetter, David Airlie, Mao Huang, Matthias Brugger, Philipp Zabel, YT Shen, dri-devel, linux-arm-kernel, linux-kernel, linux-mediatek Hi, Nicolas: Nícolas F. R. A. Prado <nfraprado@collabora.com> 於 2022年11月22日 週二 下午10:39寫道: > > mtk_drm_bind() can fail, in which case drm_dev_put() is called, > destroying the drm_device object. However a pointer to it was still > being held in the private object, and that pointer would be passed along > to DRM in mtk_drm_sys_prepare() if a suspend were triggered at that > point, resulting in a panic. Clean the pointer when destroying the > object in the error path to prevent this from happening. Applied to mediatek-drm-next [1], thanks. [1] https://git.kernel.org/pub/scm/linux/kernel/git/chunkuang.hu/linux.git/log/?h=mediatek-drm-next Regards, Chun-Kuang. > > Fixes: 119f5173628a ("drm/mediatek: Add DRM Driver for Mediatek SoC MT8173.") > Signed-off-by: Nícolas F. R. A. Prado <nfraprado@collabora.com> > > --- > > Changes in v2: > - Added Fixes tag > > drivers/gpu/drm/mediatek/mtk_drm_drv.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.c b/drivers/gpu/drm/mediatek/mtk_drm_drv.c > index 39a42dc8fb85..a21ff1b3258c 100644 > --- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c > +++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c > @@ -514,6 +514,7 @@ static int mtk_drm_bind(struct device *dev) > err_deinit: > mtk_drm_kms_deinit(drm); > err_free: > + private->drm = NULL; > drm_dev_put(drm); > return ret; > } > -- > 2.38.1 > ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-01-27 15:12 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2022-11-22 14:39 [PATCH v2] drm/mediatek: Clean dangling pointer on bind error path Nícolas F. R. A. Prado 2022-11-23 9:15 ` AngeloGioacchino Del Regno 2022-11-25 16:34 ` Nícolas F. R. A. Prado 2022-11-28 13:09 ` AngeloGioacchino Del Regno 2023-01-27 15:12 ` Chun-Kuang Hu
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®