* [PATCH] drm/msm/dpu: reorder pointer operations after sanity checks to avoid NULL deref
@ 2025-03-08 14:48 Qasim Ijaz
2025-03-09 8:16 ` Dmitry Baryshkov
2025-03-09 10:00 ` Markus Elfring
0 siblings, 2 replies; 3+ messages in thread
From: Qasim Ijaz @ 2025-03-08 14:48 UTC (permalink / raw)
To: robdclark, quic_abhinavk, dmitry.baryshkov, sean, marijn.suijten,
airlied, simona, quic_jesszhan
Cc: linux-arm-msm, dri-devel, freedreno, linux-kernel
_dpu_encoder_trigger_start dereferences "struct dpu_encoder_phys *phys"
before the sanity checks which can lead to a NULL pointer dereference if
phys is NULL.
Fix this by reordering the dereference after the sanity checks.
Signed-off-by: Qasim Ijaz <qasdev00@gmail.com>
Fixes: 8144d17a81d9 ("drm/msm/dpu: Skip trigger flush and start for CWB")
---
drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c b/drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c
index 0eed93a4d056..ba8b2a163232 100644
--- a/drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c
+++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c
@@ -1667,8 +1667,6 @@ static void _dpu_encoder_trigger_flush(struct drm_encoder *drm_enc,
*/
static void _dpu_encoder_trigger_start(struct dpu_encoder_phys *phys)
{
- struct dpu_encoder_virt *dpu_enc = to_dpu_encoder_virt(phys->parent);
-
if (!phys) {
DPU_ERROR("invalid argument(s)\n");
return;
@@ -1679,6 +1677,8 @@ static void _dpu_encoder_trigger_start(struct dpu_encoder_phys *phys)
return;
}
+ struct dpu_encoder_virt *dpu_enc = to_dpu_encoder_virt(phys->parent);
+
if (phys->parent->encoder_type == DRM_MODE_ENCODER_VIRTUAL &&
dpu_enc->cwb_mask) {
DPU_DEBUG("encoder %d CWB enabled, skipping\n", DRMID(phys->parent));
--
2.39.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] drm/msm/dpu: reorder pointer operations after sanity checks to avoid NULL deref
2025-03-08 14:48 [PATCH] drm/msm/dpu: reorder pointer operations after sanity checks to avoid NULL deref Qasim Ijaz
@ 2025-03-09 8:16 ` Dmitry Baryshkov
2025-03-09 10:00 ` Markus Elfring
1 sibling, 0 replies; 3+ messages in thread
From: Dmitry Baryshkov @ 2025-03-09 8:16 UTC (permalink / raw)
To: Qasim Ijaz
Cc: robdclark, quic_abhinavk, sean, marijn.suijten, airlied, simona,
quic_jesszhan, linux-arm-msm, dri-devel, freedreno, linux-kernel
On Sat, Mar 08, 2025 at 02:48:39PM +0000, Qasim Ijaz wrote:
> _dpu_encoder_trigger_start dereferences "struct dpu_encoder_phys *phys"
> before the sanity checks which can lead to a NULL pointer dereference if
> phys is NULL.
>
> Fix this by reordering the dereference after the sanity checks.
>
> Signed-off-by: Qasim Ijaz <qasdev00@gmail.com>
> Fixes: 8144d17a81d9 ("drm/msm/dpu: Skip trigger flush and start for CWB")
Your SoB should be the last tag. Fixes comes before it.
> ---
> drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c b/drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c
> index 0eed93a4d056..ba8b2a163232 100644
> --- a/drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c
> +++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c
> @@ -1667,8 +1667,6 @@ static void _dpu_encoder_trigger_flush(struct drm_encoder *drm_enc,
> */
> static void _dpu_encoder_trigger_start(struct dpu_encoder_phys *phys)
> {
> - struct dpu_encoder_virt *dpu_enc = to_dpu_encoder_virt(phys->parent);
> -
> if (!phys) {
> DPU_ERROR("invalid argument(s)\n");
> return;
> @@ -1679,6 +1677,8 @@ static void _dpu_encoder_trigger_start(struct dpu_encoder_phys *phys)
> return;
> }
>
> + struct dpu_encoder_virt *dpu_enc = to_dpu_encoder_virt(phys->parent);
> +
I'm not a fan of having variable defs in the middle of the code. Please
keep the def at the top and assign it here.
> if (phys->parent->encoder_type == DRM_MODE_ENCODER_VIRTUAL &&
> dpu_enc->cwb_mask) {
> DPU_DEBUG("encoder %d CWB enabled, skipping\n", DRMID(phys->parent));
> --
> 2.39.5
>
--
With best wishes
Dmitry
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] drm/msm/dpu: reorder pointer operations after sanity checks to avoid NULL deref
2025-03-08 14:48 [PATCH] drm/msm/dpu: reorder pointer operations after sanity checks to avoid NULL deref Qasim Ijaz
2025-03-09 8:16 ` Dmitry Baryshkov
@ 2025-03-09 10:00 ` Markus Elfring
1 sibling, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2025-03-09 10:00 UTC (permalink / raw)
To: Qasim Ijaz, dri-devel, freedreno, linux-arm-msm
Cc: LKML, Abhinav Kumar, David Airlie, Dmitry Baryshkov,
Jessica Zhang, Marijn Suijten, Rob Clark, Sean Paul,
Simona Vetter
…
> Fix this by reordering the dereference after the sanity checks.
Another wording suggestion:
Thus move the assignment of the variable “dpu_enc” behind a null pointer check.
Would an other summary phrase be nicer?
Regards,
Markus
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-03-09 10:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-08 14:48 [PATCH] drm/msm/dpu: reorder pointer operations after sanity checks to avoid NULL deref Qasim Ijaz
2025-03-09 8:16 ` Dmitry Baryshkov
2025-03-09 10:00 ` Markus Elfring
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox