mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH][next] drm/kmb: Fix dereference of pointer plane before a null check
@ 2025-07-30 13:34 Colin Ian King
  2025-07-30 13:53 ` Daniel Stone
  0 siblings, 1 reply; 2+ messages in thread
From: Colin Ian King @ 2025-07-30 13:34 UTC (permalink / raw)
  To: Anitha Chrisanthus, Edmund Dea, David Airlie, Simona Vetter,
	Laurent Pinchart, Thomas Zimmermann, Maxime Ripard,
	Ville Syrjälä,
	dri-devel
  Cc: kernel-janitors, linux-kernel

Currently pointer plane is being dereferenced on the calls to
drm_atomic_get_old_plane_state and drm_atomic_get_new_plane_state
when assigning old_plane_state and new_plane_state, this could
lead to a null pointer dereference. Fix this by first performing
a null pointer check on plane, then assigning old_plane_state and
new_plance_state and then null pointer checking these.

Fixes: 977697e20b3d ("drm/atomic: Pass the full state to planes atomic disable and update")
Fixes: 37418bf14c13 ("drm: Use state helper instead of the plane state pointer")

Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
---
 drivers/gpu/drm/kmb/kmb_plane.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/kmb/kmb_plane.c b/drivers/gpu/drm/kmb/kmb_plane.c
index 9e0562aa2bcb..07498deba1b6 100644
--- a/drivers/gpu/drm/kmb/kmb_plane.c
+++ b/drivers/gpu/drm/kmb/kmb_plane.c
@@ -341,10 +341,8 @@ static void kmb_plane_set_alpha(struct kmb_drm_private *kmb,
 static void kmb_plane_atomic_update(struct drm_plane *plane,
 				    struct drm_atomic_state *state)
 {
-	struct drm_plane_state *old_plane_state = drm_atomic_get_old_plane_state(state,
-										 plane);
-	struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state,
-										 plane);
+	struct drm_plane_state *old_plane_state;
+	struct drm_plane_state *new_plane_state;
 	struct drm_framebuffer *fb;
 	struct kmb_drm_private *kmb;
 	unsigned int width;
@@ -359,7 +357,12 @@ static void kmb_plane_atomic_update(struct drm_plane *plane,
 	static dma_addr_t addr[MAX_SUB_PLANES];
 	struct disp_cfg *init_disp_cfg;
 
-	if (!plane || !new_plane_state || !old_plane_state)
+	if (!plane)
+		return;
+
+	old_plane_state = drm_atomic_get_old_plane_state(state, plane);
+	new_plane_state = drm_atomic_get_new_plane_state(state, plane);
+	if (!old_plane_state || !new_plane_state)
 		return;
 
 	fb = new_plane_state->fb;
-- 
2.50.0


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

* Re: [PATCH][next] drm/kmb: Fix dereference of pointer plane before a null check
  2025-07-30 13:34 [PATCH][next] drm/kmb: Fix dereference of pointer plane before a null check Colin Ian King
@ 2025-07-30 13:53 ` Daniel Stone
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Stone @ 2025-07-30 13:53 UTC (permalink / raw)
  To: Colin Ian King
  Cc: Anitha Chrisanthus, Edmund Dea, David Airlie, Simona Vetter,
	Laurent Pinchart, Thomas Zimmermann, Maxime Ripard,
	Ville Syrjälä,
	dri-devel, kernel-janitors, linux-kernel

Hi,

On Wed, 30 Jul 2025 at 14:35, Colin Ian King <colin.i.king@gmail.com> wrote:
> Currently pointer plane is being dereferenced on the calls to
> drm_atomic_get_old_plane_state and drm_atomic_get_new_plane_state
> when assigning old_plane_state and new_plane_state, this could
> lead to a null pointer dereference. Fix this by first performing
> a null pointer check on plane, then assigning old_plane_state and
> new_plance_state and then null pointer checking these.

plane cannot be NULL, so that check should just be deleted instead.

Cheers,
Daniel

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

end of thread, other threads:[~2025-07-30 13:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-07-30 13:34 [PATCH][next] drm/kmb: Fix dereference of pointer plane before a null check Colin Ian King
2025-07-30 13:53 ` Daniel Stone

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®