From: Luben Tuikov <luben.tuikov@amd.com>
To: Asahi Lina <lina@asahilina.net>, David Airlie <airlied@gmail.com>,
Daniel Vetter <daniel@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
asahi@lists.linux.dev
Subject: Re: [PATCH] drm/scheduler: Fix UAF race in drm_sched_entity_push_job()
Date: Wed, 5 Apr 2023 14:23:32 -0400 [thread overview]
Message-ID: <9bce7374-ef67-75d0-4040-870ba131819e@amd.com> (raw)
In-Reply-To: <20230406-scheduler-uaf-2-v1-1-972531cf0a81@asahilina.net>
On 2023-04-05 12:37, Asahi Lina wrote:
> After a job is pushed into the queue, it is owned by the scheduler core
> and may be freed at any time, so we can't write nor read the submit
> timestamp after that point.
>
> Fixes oopses observed with the drm/asahi driver, found with kASAN.
>
> Signed-off-by: Asahi Lina <lina@asahilina.net>
> ---
That's a good fix! Thanks for fixing this. I'll push
this through drm-misc-next and drm-misc-fixes, if there
are no objections.
Reviewed-by: Luben Tuikov <luben.tuikov@amd.com>
Regards,
Luben
> drivers/gpu/drm/scheduler/sched_entity.c | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/scheduler/sched_entity.c b/drivers/gpu/drm/scheduler/sched_entity.c
> index 15d04a0ec623..e0a8890a62e2 100644
> --- a/drivers/gpu/drm/scheduler/sched_entity.c
> +++ b/drivers/gpu/drm/scheduler/sched_entity.c
> @@ -507,12 +507,19 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job)
> {
> struct drm_sched_entity *entity = sched_job->entity;
> bool first;
> + ktime_t submit_ts;
>
> trace_drm_sched_job(sched_job, entity);
> atomic_inc(entity->rq->sched->score);
> WRITE_ONCE(entity->last_user, current->group_leader);
> +
> + /*
> + * After the sched_job is pushed into the entity queue, it may be
> + * completed and freed up at any time. We can no longer access it.
> + * Make sure to set the submit_ts first, to avoid a race.
> + */
> + sched_job->submit_ts = submit_ts = ktime_get();
> first = spsc_queue_push(&entity->job_queue, &sched_job->queue_node);
> - sched_job->submit_ts = ktime_get();
>
> /* first job wakes up scheduler */
> if (first) {
> @@ -529,7 +536,7 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job)
> spin_unlock(&entity->rq_lock);
>
> if (drm_sched_policy == DRM_SCHED_POLICY_FIFO)
> - drm_sched_rq_update_fifo(entity, sched_job->submit_ts);
> + drm_sched_rq_update_fifo(entity, submit_ts);
>
> drm_sched_wakeup(entity->rq->sched);
> }
>
> ---
> base-commit: fe15c26ee26efa11741a7b632e9f23b01aca4cc6
> change-id: 20230406-scheduler-uaf-2-44cf8faed245
>
> Thank you,
> ~~ Lina
>
prev parent reply other threads:[~2023-04-05 18:23 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-05 16:37 [PATCH] drm/scheduler: Fix UAF race in drm_sched_entity_push_job() Asahi Lina
2023-04-05 18:23 ` Luben Tuikov [this message]
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=9bce7374-ef67-75d0-4040-870ba131819e@amd.com \
--to=luben.tuikov@amd.com \
--cc=airlied@gmail.com \
--cc=asahi@lists.linux.dev \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=lina@asahilina.net \
--cc=linux-kernel@vger.kernel.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).