All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/meson: skip invisible planes in atomic_update
@ 2026-12-05  2:17 ` Shirong Zhao
  0 siblings, 0 replies; 6+ messages in thread
From: Shirong Zhao @ 2026-12-05  2:17 UTC (permalink / raw)
  To: Neil Armstrong
  Cc: Kevin Hilman, Jerome Brunet, Martin Blumenstingl, dri-devel,
	linux-amlogic, stable, Shirong Zhao

meson_plane_atomic_update() computes the scaler phase steps as

	hf_phase_step = ((src_w << 18) / dst_w) << 6;
	vf_phase_step = (src_h << 20) / dst_h;

without checking new_state->visible.  When userspace submits a zero
destination size through the atomic ioctl,
drm_atomic_helper_check_plane_state() marks the plane invisible but
drm_atomic_helper_commit_planes() still calls ->atomic_update() for a
plane that keeps its CRTC, so dst_w/dst_h can be 0 and the divisions
above raise a divide error.

Return early for an invisible plane.

Fixes: bbbe775ec5b5 ("drm: Add support for Amlogic Meson Graphic Controller")
Signed-off-by: Shirong Zhao <shxzhaosr@163.com>
---
 drivers/gpu/drm/meson/meson_plane.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/gpu/drm/meson/meson_plane.c b/drivers/gpu/drm/meson/meson_plane.c
index 76eb8b8..5eeee77 100644
--- a/drivers/gpu/drm/meson/meson_plane.c
+++ b/drivers/gpu/drm/meson/meson_plane.c
@@ -152,6 +152,15 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
 	int vf_bank_len;
 	u8 canvas_id_osd1;
 
+	/*
+	 * A zero destination size makes the plane invisible, but
+	 * drm_atomic_helper_commit_planes() still calls ->atomic_update() for
+	 * planes that keep their CRTC.  The scaler factor computation below
+	 * divides by dst_w/dst_h, so bail out for an invisible plane.
+	 */
+	if (!new_state->visible)
+		return;
+
 	/*
 	 * Update Coordinates
 	 * Update Formats
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH] drm/meson: skip invisible planes in atomic_update
@ 2026-12-05  2:17 ` Shirong Zhao
  0 siblings, 0 replies; 6+ messages in thread
From: Shirong Zhao @ 2026-12-05  2:17 UTC (permalink / raw)
  To: Neil Armstrong
  Cc: Kevin Hilman, Jerome Brunet, Martin Blumenstingl, dri-devel,
	linux-amlogic, stable, Shirong Zhao

meson_plane_atomic_update() computes the scaler phase steps as

	hf_phase_step = ((src_w << 18) / dst_w) << 6;
	vf_phase_step = (src_h << 20) / dst_h;

without checking new_state->visible.  When userspace submits a zero
destination size through the atomic ioctl,
drm_atomic_helper_check_plane_state() marks the plane invisible but
drm_atomic_helper_commit_planes() still calls ->atomic_update() for a
plane that keeps its CRTC, so dst_w/dst_h can be 0 and the divisions
above raise a divide error.

Return early for an invisible plane.

Fixes: bbbe775ec5b5 ("drm: Add support for Amlogic Meson Graphic Controller")
Signed-off-by: Shirong Zhao <shxzhaosr@163.com>
---
 drivers/gpu/drm/meson/meson_plane.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/gpu/drm/meson/meson_plane.c b/drivers/gpu/drm/meson/meson_plane.c
index 76eb8b8..5eeee77 100644
--- a/drivers/gpu/drm/meson/meson_plane.c
+++ b/drivers/gpu/drm/meson/meson_plane.c
@@ -152,6 +152,15 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
 	int vf_bank_len;
 	u8 canvas_id_osd1;
 
+	/*
+	 * A zero destination size makes the plane invisible, but
+	 * drm_atomic_helper_commit_planes() still calls ->atomic_update() for
+	 * planes that keep their CRTC.  The scaler factor computation below
+	 * divides by dst_w/dst_h, so bail out for an invisible plane.
+	 */
+	if (!new_state->visible)
+		return;
+
 	/*
 	 * Update Coordinates
 	 * Update Formats
-- 
2.53.0


_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] drm/meson: skip invisible planes in atomic_update
  2026-12-05  2:17 ` Shirong Zhao
@ 2026-12-05  2:34   ` sashiko-bot
  -1 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-12-05  2:34 UTC (permalink / raw)
  To: Shirong Zhao; +Cc: dri-devel, linux-amlogic, neil.armstrong

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] drm/meson: invisible plane skip leaves OSD1 enabled causing DMA
  UAF
- [Low] drm/meson: Fixes tag cites bbbe775ec5b5 instead of 7db647aa8b13
--

commit 2897024e4c3710997999b1de11959966a195a61b
Author: Shirong Zhao <shxzhaosr@163.com>

> drm/meson: skip invisible planes in atomic_update
>
> meson_plane_atomic_update() computes the scaler phase steps as
>
>         hf_phase_step = ((src_w << 18) / dst_w) << 6;
>         vf_phase_step = (src_h << 20) / dst_h;
>
> without checking new_state->visible.  When userspace submits a zero
> destination size through the atomic ioctl,
> drm_atomic_helper_check_plane_state() marks the plane invisible but
> drm_atomic_helper_commit_planes() still calls ->atomic_update() for a
> plane that keeps its CRTC, so dst_w/dst_h can be 0 and the divisions
> above raise a divide error.
>
> Return early for an invisible plane.
>
> Fixes: bbbe775ec5b5 ("drm: Add support for Amlogic Meson Graphic Controller")
> Signed-off-by: Shirong Zhao <shxzhaosr@163.com>

[Severity: Low]
Should the Fixes tag cite 7db647aa8b13 ("drm/meson: Add primary plane
scaling") instead?  Commit bbbe775ec5b5 ("drm: Add support for Amlogic
Meson Graphic Controller") did not have the scaler phase-step divisions
by dst_w and dst_h.

> diff --git a/drivers/gpu/drm/meson/meson_plane.c b/drivers/gpu/drm/meson/meson_plane.c
> index c17afe6712f93..80d685b875a74 100644
> --- a/drivers/gpu/drm/meson/meson_plane.c
> +++ b/drivers/gpu/drm/meson/meson_plane.c
> @@ -152,6 +152,15 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
>  	int vf_bank_len;
>  	u8 canvas_id_osd1;
>  
> +	/*
> +	 * A zero destination size makes the plane invisible, but
> +	 * drm_atomic_helper_commit_planes() still calls ->atomic_update() for
> +	 * planes that keep their CRTC.  The scaler factor computation below
> +	 * divides by dst_w/dst_h, so bail out for an invisible plane.
> +	 */
> +	if (!new_state->visible)
> +		return;
> +
>  	/*
>  	 * Update Coordinates
>  	 * Update Formats

[Severity: High]
Does returning early here leave OSD1 enabled and scanning out the
previous framebuffer's DMA address?

When a visible plane becomes invisible while keeping its CRTC,
drm_atomic_helper_commit_planes() skips ->atomic_disable() and calls
meson_plane_atomic_update() instead.  Bailing out leaves
priv->viu.osd1_enabled true and priv->viu.osd1_addr set to the old buffer.

meson_crtc_atomic_flush() then still sets priv->viu.osd1_commit, so
meson_crtc_irq() keeps programming OSD1 with that stale address.  If the
commit replaced the framebuffer, freeing the old GEM buffer results in a
DMA use-after-free while OSD1 continues scanning it out.

Calling meson_plane_atomic_disable(plane, state) before returning would
disable OSD1 and clear priv->viu.osd1_enabled.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261205021754.64-1-shxzhaosr@163.com?part=1

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] drm/meson: skip invisible planes in atomic_update
@ 2026-12-05  2:34   ` sashiko-bot
  0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-12-05  2:34 UTC (permalink / raw)
  To: Shirong Zhao; +Cc: dri-devel, linux-amlogic, neil.armstrong

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] drm/meson: invisible plane skip leaves OSD1 enabled causing DMA
  UAF
- [Low] drm/meson: Fixes tag cites bbbe775ec5b5 instead of 7db647aa8b13
--

commit 2897024e4c3710997999b1de11959966a195a61b
Author: Shirong Zhao <shxzhaosr@163.com>

> drm/meson: skip invisible planes in atomic_update
>
> meson_plane_atomic_update() computes the scaler phase steps as
>
>         hf_phase_step = ((src_w << 18) / dst_w) << 6;
>         vf_phase_step = (src_h << 20) / dst_h;
>
> without checking new_state->visible.  When userspace submits a zero
> destination size through the atomic ioctl,
> drm_atomic_helper_check_plane_state() marks the plane invisible but
> drm_atomic_helper_commit_planes() still calls ->atomic_update() for a
> plane that keeps its CRTC, so dst_w/dst_h can be 0 and the divisions
> above raise a divide error.
>
> Return early for an invisible plane.
>
> Fixes: bbbe775ec5b5 ("drm: Add support for Amlogic Meson Graphic Controller")
> Signed-off-by: Shirong Zhao <shxzhaosr@163.com>

[Severity: Low]
Should the Fixes tag cite 7db647aa8b13 ("drm/meson: Add primary plane
scaling") instead?  Commit bbbe775ec5b5 ("drm: Add support for Amlogic
Meson Graphic Controller") did not have the scaler phase-step divisions
by dst_w and dst_h.

> diff --git a/drivers/gpu/drm/meson/meson_plane.c b/drivers/gpu/drm/meson/meson_plane.c
> index c17afe6712f93..80d685b875a74 100644
> --- a/drivers/gpu/drm/meson/meson_plane.c
> +++ b/drivers/gpu/drm/meson/meson_plane.c
> @@ -152,6 +152,15 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
>  	int vf_bank_len;
>  	u8 canvas_id_osd1;
>  
> +	/*
> +	 * A zero destination size makes the plane invisible, but
> +	 * drm_atomic_helper_commit_planes() still calls ->atomic_update() for
> +	 * planes that keep their CRTC.  The scaler factor computation below
> +	 * divides by dst_w/dst_h, so bail out for an invisible plane.
> +	 */
> +	if (!new_state->visible)
> +		return;
> +
>  	/*
>  	 * Update Coordinates
>  	 * Update Formats

[Severity: High]
Does returning early here leave OSD1 enabled and scanning out the
previous framebuffer's DMA address?

When a visible plane becomes invisible while keeping its CRTC,
drm_atomic_helper_commit_planes() skips ->atomic_disable() and calls
meson_plane_atomic_update() instead.  Bailing out leaves
priv->viu.osd1_enabled true and priv->viu.osd1_addr set to the old buffer.

meson_crtc_atomic_flush() then still sets priv->viu.osd1_commit, so
meson_crtc_irq() keeps programming OSD1 with that stale address.  If the
commit replaced the framebuffer, freeing the old GEM buffer results in a
DMA use-after-free while OSD1 continues scanning it out.

Calling meson_plane_atomic_disable(plane, state) before returning would
disable OSD1 and clear priv->viu.osd1_enabled.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261205021754.64-1-shxzhaosr@163.com?part=1

_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2] drm/meson: disable OSD1 for invisible planes in atomic_update
  2026-12-05  2:17 ` Shirong Zhao
@ 2026-12-05  2:41   ` Shirong Zhao
  -1 siblings, 0 replies; 6+ messages in thread
From: Shirong Zhao @ 2026-12-05  2:41 UTC (permalink / raw)
  To: Neil Armstrong
  Cc: Kevin Hilman, Jerome Brunet, Martin Blumenstingl, dri-devel,
	linux-amlogic, stable, Shirong Zhao

meson_plane_atomic_update() computes the scaler phase steps as

	hf_phase_step = ((src_w << 18) / dst_w) << 6;
	vf_phase_step = (src_h << 20) / dst_h;

using the plane destination size.  When a plane becomes invisible (for
example a zero destination size submitted through the atomic ioctl),
drm_atomic_helper_commit_planes() does not call ->atomic_disable() for a
plane that keeps its CRTC; it calls ->atomic_update() instead, so dst_w or
dst_h can be 0 and the divisions raise a divide error.

Handling only the division is not enough: returning early would leave OSD1
enabled and still scanning out the previous buffer's DMA address, so a
commit that replaced the framebuffer and freed the old GEM buffer would
become a DMA use-after-free.  Call meson_plane_atomic_disable(), which
clears priv->viu.osd1_enabled and disables OSD1, and return.

Fixes: 7db647aa8b13 ("drm/meson: Add primary plane scaling")
Signed-off-by: Shirong Zhao <shxzhaosr@163.com>
---
 drivers/gpu/drm/meson/meson_plane.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/drivers/gpu/drm/meson/meson_plane.c b/drivers/gpu/drm/meson/meson_plane.c
index 76eb8b8..f836c8f 100644
--- a/drivers/gpu/drm/meson/meson_plane.c
+++ b/drivers/gpu/drm/meson/meson_plane.c
@@ -131,6 +131,9 @@ static u32 meson_g12a_afbcd_line_stride(struct meson_drm *priv)
 	return ((line_stride + 1) >> 1) << 1;
 }
 
+static void meson_plane_atomic_disable(struct drm_plane *plane,
+				       struct drm_atomic_commit *state);
+
 static void meson_plane_atomic_update(struct drm_plane *plane,
 				      struct drm_atomic_commit *state)
 {
@@ -152,6 +155,17 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
 	int vf_bank_len;
 	u8 canvas_id_osd1;
 
+	/*
+	 * A zero destination size makes the plane invisible and
+	 * drm_atomic_helper_commit_planes() still calls ->atomic_update() for a
+	 * plane that keeps its CRTC.  Disable OSD1 instead of dividing by a zero
+	 * dst_w/dst_h below, and to avoid leaving it scanning out a stale buffer.
+	 */
+	if (!new_state->visible) {
+		meson_plane_atomic_disable(plane, state);
+		return;
+	}
+
 	/*
 	 * Update Coordinates
 	 * Update Formats
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2] drm/meson: disable OSD1 for invisible planes in atomic_update
@ 2026-12-05  2:41   ` Shirong Zhao
  0 siblings, 0 replies; 6+ messages in thread
From: Shirong Zhao @ 2026-12-05  2:41 UTC (permalink / raw)
  To: Neil Armstrong
  Cc: Kevin Hilman, Jerome Brunet, Martin Blumenstingl, dri-devel,
	linux-amlogic, stable, Shirong Zhao

meson_plane_atomic_update() computes the scaler phase steps as

	hf_phase_step = ((src_w << 18) / dst_w) << 6;
	vf_phase_step = (src_h << 20) / dst_h;

using the plane destination size.  When a plane becomes invisible (for
example a zero destination size submitted through the atomic ioctl),
drm_atomic_helper_commit_planes() does not call ->atomic_disable() for a
plane that keeps its CRTC; it calls ->atomic_update() instead, so dst_w or
dst_h can be 0 and the divisions raise a divide error.

Handling only the division is not enough: returning early would leave OSD1
enabled and still scanning out the previous buffer's DMA address, so a
commit that replaced the framebuffer and freed the old GEM buffer would
become a DMA use-after-free.  Call meson_plane_atomic_disable(), which
clears priv->viu.osd1_enabled and disables OSD1, and return.

Fixes: 7db647aa8b13 ("drm/meson: Add primary plane scaling")
Signed-off-by: Shirong Zhao <shxzhaosr@163.com>
---
 drivers/gpu/drm/meson/meson_plane.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/drivers/gpu/drm/meson/meson_plane.c b/drivers/gpu/drm/meson/meson_plane.c
index 76eb8b8..f836c8f 100644
--- a/drivers/gpu/drm/meson/meson_plane.c
+++ b/drivers/gpu/drm/meson/meson_plane.c
@@ -131,6 +131,9 @@ static u32 meson_g12a_afbcd_line_stride(struct meson_drm *priv)
 	return ((line_stride + 1) >> 1) << 1;
 }
 
+static void meson_plane_atomic_disable(struct drm_plane *plane,
+				       struct drm_atomic_commit *state);
+
 static void meson_plane_atomic_update(struct drm_plane *plane,
 				      struct drm_atomic_commit *state)
 {
@@ -152,6 +155,17 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
 	int vf_bank_len;
 	u8 canvas_id_osd1;
 
+	/*
+	 * A zero destination size makes the plane invisible and
+	 * drm_atomic_helper_commit_planes() still calls ->atomic_update() for a
+	 * plane that keeps its CRTC.  Disable OSD1 instead of dividing by a zero
+	 * dst_w/dst_h below, and to avoid leaving it scanning out a stale buffer.
+	 */
+	if (!new_state->visible) {
+		meson_plane_atomic_disable(plane, state);
+		return;
+	}
+
 	/*
 	 * Update Coordinates
 	 * Update Formats
-- 
2.53.0


_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-12-05  2:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05  2:17 [PATCH] drm/meson: skip invisible planes in atomic_update Shirong Zhao
2026-12-05  2:17 ` Shirong Zhao
2026-12-05  2:34 ` sashiko-bot
2026-12-05  2:34   ` sashiko-bot
2026-12-05  2:41 ` [PATCH v2] drm/meson: disable OSD1 for " Shirong Zhao
2026-12-05  2:41   ` Shirong Zhao

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.