mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Bin Luo (University of Electronic Science and Technology of China)" <luob87709@gmail.com>
To: jani.nikula@linux.intel.com, rodrigo.vivi@intel.com
Cc: intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org,
	dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org
Subject: [PATCH] drm/i915/display: hold frontbuffer ref across dirtyfb fence callback
Date: Thu, 26 Nov 2026 14:08:18 +0800	[thread overview]
Message-ID: <20261126060818.1654-1-luob87709@gmail.com> (raw)

intel_user_framebuffer_dirty() stores the raw intel_frontbuffer pointer
in frontbuffer_fence_cb without taking a frontbuffer reference. If the
framebuffer is destroyed and its owner frontbuffer reference is dropped
before the reservation dma_fence signals,
intel_user_framebuffer_fence_wake() passes a freed intel_frontbuffer
pointer to intel_frontbuffer_queue_flush(), causing a use-after-free.

Take a frontbuffer reference via intel_parent_frontbuffer_ref() before
registering the fence callback, and release it via
intel_parent_frontbuffer_put() in intel_user_framebuffer_fence_wake()
after queuing the flush.

Fixes: 1bb2af547a4b ("drm/i915: Handle dma fences in dirtyfb callback")
Signed-off-by: Bin Luo (University of Electronic Science and Technology of China) <luob87709@gmail.com>
---
Found by code inspection. Compile-tested on x86_64 with W=1 and KASAN
for both i915 (drivers/gpu/drm/i915/display/intel_fb.o) and xe
(drivers/gpu/drm/xe/i915-display/intel_fb.o); not runtime-tested on
Intel display hardware.

 drivers/gpu/drm/i915/display/intel_fb.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/display/intel_fb.c b/drivers/gpu/drm/i915/display/intel_fb.c
index 9d71f59..3bbbedc 100644
--- a/drivers/gpu/drm/i915/display/intel_fb.c
+++ b/drivers/gpu/drm/i915/display/intel_fb.c
@@ -2148,8 +2148,10 @@ static void intel_user_framebuffer_fence_wake(struct dma_fence *dma,
 					      struct dma_fence_cb *data)
 {
 	struct frontbuffer_fence_cb *cb = container_of(data, typeof(*cb), base);
+	struct intel_frontbuffer *front = cb->front;
 
-	intel_frontbuffer_queue_flush(cb->front);
+	intel_frontbuffer_queue_flush(front);
+	intel_parent_frontbuffer_put(front->display, front);
 	kfree(cb);
 	dma_fence_put(dma);
 }
@@ -2160,6 +2162,7 @@ static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb,
 					struct drm_clip_rect *clips,
 					unsigned int num_clips)
 {
+	struct intel_display *display = to_intel_display(fb->dev);
 	struct drm_gem_object *obj = intel_fb_bo(fb);
 	struct intel_frontbuffer *front = to_intel_frontbuffer(fb);
 	struct dma_fence *fence;
@@ -2185,6 +2188,7 @@ static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb,
 	}
 
 	cb->front = front;
+	intel_parent_frontbuffer_ref(display, front);
 
 	intel_frontbuffer_invalidate(front, ORIGIN_DIRTYFB);
 
-- 
2.43.0


                 reply	other threads:[~2026-11-26  6:08 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261126060818.1654-1-luob87709@gmail.com \
    --to=luob87709@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rodrigo.vivi@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®