From: Asahi Lina <lina@asahilina.net>
To: "Christian König" <christian.koenig@amd.com>,
"Luben Tuikov" <luben.tuikov@amd.com>,
"David Airlie" <airlied@gmail.com>,
"Daniel Vetter" <daniel@ffwll.ch>,
"Sumit Semwal" <sumit.semwal@linaro.org>
Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
linux-media@vger.kernel.org, asahi@lists.linux.dev
Subject: Re: [PATCH] drm/scheduler: Fix UAF in drm_sched_fence_get_timeline_name
Date: Thu, 6 Apr 2023 17:49:17 +0900 [thread overview]
Message-ID: <cfbaceae-6d40-a8b3-e449-6473be234d2d@asahilina.net> (raw)
In-Reply-To: <6b3433ee-0712-f789-51ee-3047ead9bb79@amd.com>
On 06/04/2023 17.29, Christian König wrote:
> Am 05.04.23 um 18:34 schrieb Asahi Lina:
>> A signaled scheduler fence can outlive its scheduler, since fences are
>> independently reference counted.
>
> Well that is actually not correct. Schedulers are supposed to stay
> around until the hw they have been driving is no longer present.
But the fences can outlive that. You can GPU render into an imported
buffer, which attaches a fence to it. Then the GPU goes away but the
fence is still attached to the buffer. Then you oops when you cat that
debugfs file...
My use case does this way more often (since schedulers are tied to UAPI
objects), which is how I found this, but as far as I can tell this is
already broken for all drivers on unplug/unbind/anything else that would
destroy the schedulers with fences potentially referenced on separate
scanout devices or at any other DMA-BUF consumer.
> E.g. the reference was scheduler_fence->hw_fence->driver->scheduler.
It's up to drivers not to mess that up, since the HW fence has the same
requirements that it can outlive other driver objects, just like any
other fence. That's not something the scheduler has to be concerned
with, it's a driver correctness issue.
Of course, in C you have to get it right yourself, while with correct
Rust abstractions will cause your code to fail to compile if you do it
wrong ^^
In my particular case, the hw_fence is a very dumb object that has no
references to anything, only an ID and a pending op count. Jobs hold
references to it and decrement it until it signals, not the other way
around. So that object can live forever regardless of whether the rest
of the device is gone.
> Your use case is now completely different to that and this won't work
> any more.
>
> This here might just be the first case where that breaks.
This bug already exists, it's just a lot rarer for existing use cases...
but either way Xe is doing the same thing I am, so I'm not the only one
here either.
~~ Lina
next prev parent reply other threads:[~2023-04-06 8:49 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-05 16:34 Asahi Lina
2023-04-05 18:09 ` Luben Tuikov
2023-04-06 8:29 ` Christian König
2023-04-06 8:44 ` Daniel Vetter
2023-04-06 8:49 ` Asahi Lina [this message]
2023-04-06 9:06 ` Christian König
2023-04-06 9:15 ` Asahi Lina
2023-04-06 9:27 ` Asahi Lina
2023-04-06 9:48 ` Daniel Vetter
2023-04-06 13:36 ` Asahi Lina
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=cfbaceae-6d40-a8b3-e449-6473be234d2d@asahilina.net \
--to=lina@asahilina.net \
--cc=airlied@gmail.com \
--cc=asahi@lists.linux.dev \
--cc=christian.koenig@amd.com \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=luben.tuikov@amd.com \
--cc=sumit.semwal@linaro.org \
/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®