dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [RFC 0/4] Some (drm_sched_|dma_)fence lifetime issues
@ 2025-04-18 16:42 Tvrtko Ursulin
  2025-04-18 16:42 ` [RFC 1/4] sync_file: Weakly paper over one use-after-free resulting race Tvrtko Ursulin
                   ` (4 more replies)
  0 siblings, 5 replies; 13+ messages in thread
From: Tvrtko Ursulin @ 2025-04-18 16:42 UTC (permalink / raw)
  To: dri-devel
  Cc: kernel-dev, Tvrtko Ursulin, Christian König,
	Danilo Krummrich, Lucas De Marchi, Matthew Brost, Philipp Stanner,
	Rodrigo Vivi

Hi all,

Recently I mentioned to Danilo about some fence lifetime issues so here is a
rough series, more than anything intended to start the discussion.

Most of the problem statement can be found in the first patch but to briefly
summarise - because sched fence can outlive the scheduler, we can trivially
engineer an use after free with xe and possibly other drivers. All that is
needed is to convert a syncobj into a sync file behind drivers back, and I don't
see what the driver can do about it.

IGT that exploits the problem:
https://patchwork.freedesktop.org/patch/642709/?series=146211&rev=2

Different flavour of the problem space is if we had a close(drm_fd) in that test
before the sleep. In that case we can even unload xe.ko and gpu-sched.ko for
even more fun. Last two patches in the series close that gap.

But first two patches are just shrinking the race window. They are not proper
fixes. This is what I want to discuss since I understand reference counting all
the involved objects has been rejected in the past. And since the problem
probably expands to all dma fences it certainly isn't easy.

To be clear once more - lets not focus on how this does not fix it fully - I am
primarily trying to start the conversation.

Cc: Christian König <christian.koenig@amd.com>
Cc: Danilo Krummrich <dakr@kernel.org>
Cc: Lucas De Marchi <lucas.demarchi@intel.com>
Cc: Matthew Brost <matthew.brost@intel.com>
Cc: Philipp Stanner <phasta@kernel.org>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>

Tvrtko Ursulin (4):
  sync_file: Weakly paper over one use-after-free resulting race
  dma-fence: Slightly safer dma_fence_set_deadline
  drm/sched: Keep module reference while there are active fences
  drm/xe: Keep module reference while there are active fences

 drivers/dma-buf/dma-fence.c             |  2 +-
 drivers/dma-buf/sync_file.c             | 29 ++++++++++++++++++++-----
 drivers/gpu/drm/scheduler/sched_fence.c | 12 ++++++++--
 drivers/gpu/drm/xe/xe_hw_fence.c        | 13 ++++++++++-
 4 files changed, 47 insertions(+), 9 deletions(-)

-- 
2.48.0

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

end of thread, other threads:[~2025-05-07 14:50 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-18 16:42 [RFC 0/4] Some (drm_sched_|dma_)fence lifetime issues Tvrtko Ursulin
2025-04-18 16:42 ` [RFC 1/4] sync_file: Weakly paper over one use-after-free resulting race Tvrtko Ursulin
2025-04-18 16:42 ` [RFC 2/4] dma-fence: Slightly safer dma_fence_set_deadline Tvrtko Ursulin
2025-04-18 16:42 ` [RFC 3/4] drm/sched: Keep module reference while there are active fences Tvrtko Ursulin
2025-04-18 16:42 ` [RFC 4/4] drm/xe: " Tvrtko Ursulin
2025-04-23 13:12 ` [RFC 0/4] Some (drm_sched_|dma_)fence lifetime issues Christian König
2025-04-24  6:11   ` Matthew Brost
2025-04-24  7:07   ` Tvrtko Ursulin
2025-04-28 13:15     ` Christian König
2025-05-07 12:28       ` Tvrtko Ursulin
2025-05-07 12:54         ` Christian König
2025-05-07 14:07           ` Tvrtko Ursulin
2025-05-07 14:50             ` Christian König

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox