From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: Andi Shyti <andi.shyti@linux.intel.com>, Rob Clark <robdclark@gmail.com>
Cc: dri-devel@lists.freedesktop.org,
"Rob Clark" <robdclark@chromium.org>,
"Jani Nikula" <jani.nikula@linux.intel.com>,
"Joonas Lahtinen" <joonas.lahtinen@linux.intel.com>,
"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
"David Airlie" <airlied@gmail.com>,
"Daniel Vetter" <daniel@ffwll.ch>,
"Chris Wilson" <chris@chris-wilson.co.uk>,
"John Harrison" <John.C.Harrison@intel.com>,
"Matthew Brost" <matthew.brost@intel.com>,
katrinzhou <katrinzhou@tencent.com>,
"Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
"open list:INTEL DRM DRIVERS" <intel-gfx@lists.freedesktop.org>,
"open list" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] drm/i915: Fix potential context UAFs
Date: Thu, 5 Jan 2023 16:00:11 +0000 [thread overview]
Message-ID: <b1aea77b-ba55-61a2-2c33-f7754e0ca586@linux.intel.com> (raw)
In-Reply-To: <Y7byJa9VZyKO2gnT@ashyti-mobl2.lan>
On 05/01/2023 15:52, Andi Shyti wrote:
> Hi Rob,
>
> On Tue, Jan 03, 2023 at 03:49:46PM -0800, Rob Clark wrote:
>> From: Rob Clark <robdclark@chromium.org>
>>
>> gem_context_register() makes the context visible to userspace, and which
>> point a separate thread can trigger the I915_GEM_CONTEXT_DESTROY ioctl.
>> So we need to ensure that nothing uses the ctx ptr after this. And we
>> need to ensure that adding the ctx to the xarray is the *last* thing
>> that gem_context_register() does with the ctx pointer.
>>
>> Signed-off-by: Rob Clark <robdclark@chromium.org>
>
> Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com>
>
> I also agree with Tvrtko that we should add Stable: and Fixes:.
Yeah I'll add them all when merging. Just waiting for full CI results. It will be like this:
Fixes: eb4dedae920a ("drm/i915/gem: Delay tracking the GEM context until it is registered")
Fixes: a4c1cdd34e2c ("drm/i915/gem: Delay context creation (v3)")
Fixes: 49bd54b390c2 ("drm/i915: Track all user contexts per client")
Cc: <stable@vger.kernel.org> # v5.10+
Regards,
Tvrtko
> One little thing, "user after free" is clearer that UAF :)
>
> Thanks,
> Andi
>
>> ---
>> drivers/gpu/drm/i915/gem/i915_gem_context.c | 24 +++++++++++++++------
>> 1 file changed, 18 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c b/drivers/gpu/drm/i915/gem/i915_gem_context.c
>> index 7f2831efc798..6250de9b9196 100644
>> --- a/drivers/gpu/drm/i915/gem/i915_gem_context.c
>> +++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c
>> @@ -1688,6 +1688,10 @@ void i915_gem_init__contexts(struct drm_i915_private *i915)
>> init_contexts(&i915->gem.contexts);
>> }
>>
>> +/*
>> + * Note that this implicitly consumes the ctx reference, by placing
>> + * the ctx in the context_xa.
>> + */
>> static void gem_context_register(struct i915_gem_context *ctx,
>> struct drm_i915_file_private *fpriv,
>> u32 id)
>> @@ -1703,10 +1707,6 @@ static void gem_context_register(struct i915_gem_context *ctx,
>> snprintf(ctx->name, sizeof(ctx->name), "%s[%d]",
>> current->comm, pid_nr(ctx->pid));
>>
>> - /* And finally expose ourselves to userspace via the idr */
>> - old = xa_store(&fpriv->context_xa, id, ctx, GFP_KERNEL);
>> - WARN_ON(old);
>> -
>> spin_lock(&ctx->client->ctx_lock);
>> list_add_tail_rcu(&ctx->client_link, &ctx->client->ctx_list);
>> spin_unlock(&ctx->client->ctx_lock);
>> @@ -1714,6 +1714,10 @@ static void gem_context_register(struct i915_gem_context *ctx,
>> spin_lock(&i915->gem.contexts.lock);
>> list_add_tail(&ctx->link, &i915->gem.contexts.list);
>> spin_unlock(&i915->gem.contexts.lock);
>> +
>> + /* And finally expose ourselves to userspace via the idr */
>> + old = xa_store(&fpriv->context_xa, id, ctx, GFP_KERNEL);
>> + WARN_ON(old);
>> }
>>
>> int i915_gem_context_open(struct drm_i915_private *i915,
>> @@ -2199,14 +2203,22 @@ finalize_create_context_locked(struct drm_i915_file_private *file_priv,
>> if (IS_ERR(ctx))
>> return ctx;
>>
>> + /*
>> + * One for the xarray and one for the caller. We need to grab
>> + * the reference *prior* to making the ctx visble to userspace
>> + * in gem_context_register(), as at any point after that
>> + * userspace can try to race us with another thread destroying
>> + * the context under our feet.
>> + */
>> + i915_gem_context_get(ctx);
>> +
>> gem_context_register(ctx, file_priv, id);
>>
>> old = xa_erase(&file_priv->proto_context_xa, id);
>> GEM_BUG_ON(old != pc);
>> proto_context_close(file_priv->dev_priv, pc);
>>
>> - /* One for the xarray and one for the caller */
>> - return i915_gem_context_get(ctx);
>> + return ctx;
>> }
>>
>> struct i915_gem_context *
>> --
>> 2.38.1
WARNING: multiple messages have this Message-ID (diff)
From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: Andi Shyti <andi.shyti@linux.intel.com>, Rob Clark <robdclark@gmail.com>
Cc: "Rob Clark" <robdclark@chromium.org>,
"Matthew Brost" <matthew.brost@intel.com>,
katrinzhou <katrinzhou@tencent.com>,
"Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
"open list:INTEL DRM DRIVERS" <intel-gfx@lists.freedesktop.org>,
"open list" <linux-kernel@vger.kernel.org>,
"Chris Wilson" <chris@chris-wilson.co.uk>,
dri-devel@lists.freedesktop.org,
"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
"John Harrison" <John.C.Harrison@intel.com>
Subject: Re: [PATCH] drm/i915: Fix potential context UAFs
Date: Thu, 5 Jan 2023 16:00:11 +0000 [thread overview]
Message-ID: <b1aea77b-ba55-61a2-2c33-f7754e0ca586@linux.intel.com> (raw)
In-Reply-To: <Y7byJa9VZyKO2gnT@ashyti-mobl2.lan>
On 05/01/2023 15:52, Andi Shyti wrote:
> Hi Rob,
>
> On Tue, Jan 03, 2023 at 03:49:46PM -0800, Rob Clark wrote:
>> From: Rob Clark <robdclark@chromium.org>
>>
>> gem_context_register() makes the context visible to userspace, and which
>> point a separate thread can trigger the I915_GEM_CONTEXT_DESTROY ioctl.
>> So we need to ensure that nothing uses the ctx ptr after this. And we
>> need to ensure that adding the ctx to the xarray is the *last* thing
>> that gem_context_register() does with the ctx pointer.
>>
>> Signed-off-by: Rob Clark <robdclark@chromium.org>
>
> Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com>
>
> I also agree with Tvrtko that we should add Stable: and Fixes:.
Yeah I'll add them all when merging. Just waiting for full CI results. It will be like this:
Fixes: eb4dedae920a ("drm/i915/gem: Delay tracking the GEM context until it is registered")
Fixes: a4c1cdd34e2c ("drm/i915/gem: Delay context creation (v3)")
Fixes: 49bd54b390c2 ("drm/i915: Track all user contexts per client")
Cc: <stable@vger.kernel.org> # v5.10+
Regards,
Tvrtko
> One little thing, "user after free" is clearer that UAF :)
>
> Thanks,
> Andi
>
>> ---
>> drivers/gpu/drm/i915/gem/i915_gem_context.c | 24 +++++++++++++++------
>> 1 file changed, 18 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c b/drivers/gpu/drm/i915/gem/i915_gem_context.c
>> index 7f2831efc798..6250de9b9196 100644
>> --- a/drivers/gpu/drm/i915/gem/i915_gem_context.c
>> +++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c
>> @@ -1688,6 +1688,10 @@ void i915_gem_init__contexts(struct drm_i915_private *i915)
>> init_contexts(&i915->gem.contexts);
>> }
>>
>> +/*
>> + * Note that this implicitly consumes the ctx reference, by placing
>> + * the ctx in the context_xa.
>> + */
>> static void gem_context_register(struct i915_gem_context *ctx,
>> struct drm_i915_file_private *fpriv,
>> u32 id)
>> @@ -1703,10 +1707,6 @@ static void gem_context_register(struct i915_gem_context *ctx,
>> snprintf(ctx->name, sizeof(ctx->name), "%s[%d]",
>> current->comm, pid_nr(ctx->pid));
>>
>> - /* And finally expose ourselves to userspace via the idr */
>> - old = xa_store(&fpriv->context_xa, id, ctx, GFP_KERNEL);
>> - WARN_ON(old);
>> -
>> spin_lock(&ctx->client->ctx_lock);
>> list_add_tail_rcu(&ctx->client_link, &ctx->client->ctx_list);
>> spin_unlock(&ctx->client->ctx_lock);
>> @@ -1714,6 +1714,10 @@ static void gem_context_register(struct i915_gem_context *ctx,
>> spin_lock(&i915->gem.contexts.lock);
>> list_add_tail(&ctx->link, &i915->gem.contexts.list);
>> spin_unlock(&i915->gem.contexts.lock);
>> +
>> + /* And finally expose ourselves to userspace via the idr */
>> + old = xa_store(&fpriv->context_xa, id, ctx, GFP_KERNEL);
>> + WARN_ON(old);
>> }
>>
>> int i915_gem_context_open(struct drm_i915_private *i915,
>> @@ -2199,14 +2203,22 @@ finalize_create_context_locked(struct drm_i915_file_private *file_priv,
>> if (IS_ERR(ctx))
>> return ctx;
>>
>> + /*
>> + * One for the xarray and one for the caller. We need to grab
>> + * the reference *prior* to making the ctx visble to userspace
>> + * in gem_context_register(), as at any point after that
>> + * userspace can try to race us with another thread destroying
>> + * the context under our feet.
>> + */
>> + i915_gem_context_get(ctx);
>> +
>> gem_context_register(ctx, file_priv, id);
>>
>> old = xa_erase(&file_priv->proto_context_xa, id);
>> GEM_BUG_ON(old != pc);
>> proto_context_close(file_priv->dev_priv, pc);
>>
>> - /* One for the xarray and one for the caller */
>> - return i915_gem_context_get(ctx);
>> + return ctx;
>> }
>>
>> struct i915_gem_context *
>> --
>> 2.38.1
WARNING: multiple messages have this Message-ID (diff)
From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: Andi Shyti <andi.shyti@linux.intel.com>, Rob Clark <robdclark@gmail.com>
Cc: "Rob Clark" <robdclark@chromium.org>,
katrinzhou <katrinzhou@tencent.com>,
"Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
"open list:INTEL DRM DRIVERS" <intel-gfx@lists.freedesktop.org>,
"open list" <linux-kernel@vger.kernel.org>,
"Chris Wilson" <chris@chris-wilson.co.uk>,
dri-devel@lists.freedesktop.org,
"Daniel Vetter" <daniel@ffwll.ch>,
"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
"David Airlie" <airlied@gmail.com>
Subject: Re: [Intel-gfx] [PATCH] drm/i915: Fix potential context UAFs
Date: Thu, 5 Jan 2023 16:00:11 +0000 [thread overview]
Message-ID: <b1aea77b-ba55-61a2-2c33-f7754e0ca586@linux.intel.com> (raw)
In-Reply-To: <Y7byJa9VZyKO2gnT@ashyti-mobl2.lan>
On 05/01/2023 15:52, Andi Shyti wrote:
> Hi Rob,
>
> On Tue, Jan 03, 2023 at 03:49:46PM -0800, Rob Clark wrote:
>> From: Rob Clark <robdclark@chromium.org>
>>
>> gem_context_register() makes the context visible to userspace, and which
>> point a separate thread can trigger the I915_GEM_CONTEXT_DESTROY ioctl.
>> So we need to ensure that nothing uses the ctx ptr after this. And we
>> need to ensure that adding the ctx to the xarray is the *last* thing
>> that gem_context_register() does with the ctx pointer.
>>
>> Signed-off-by: Rob Clark <robdclark@chromium.org>
>
> Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com>
>
> I also agree with Tvrtko that we should add Stable: and Fixes:.
Yeah I'll add them all when merging. Just waiting for full CI results. It will be like this:
Fixes: eb4dedae920a ("drm/i915/gem: Delay tracking the GEM context until it is registered")
Fixes: a4c1cdd34e2c ("drm/i915/gem: Delay context creation (v3)")
Fixes: 49bd54b390c2 ("drm/i915: Track all user contexts per client")
Cc: <stable@vger.kernel.org> # v5.10+
Regards,
Tvrtko
> One little thing, "user after free" is clearer that UAF :)
>
> Thanks,
> Andi
>
>> ---
>> drivers/gpu/drm/i915/gem/i915_gem_context.c | 24 +++++++++++++++------
>> 1 file changed, 18 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c b/drivers/gpu/drm/i915/gem/i915_gem_context.c
>> index 7f2831efc798..6250de9b9196 100644
>> --- a/drivers/gpu/drm/i915/gem/i915_gem_context.c
>> +++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c
>> @@ -1688,6 +1688,10 @@ void i915_gem_init__contexts(struct drm_i915_private *i915)
>> init_contexts(&i915->gem.contexts);
>> }
>>
>> +/*
>> + * Note that this implicitly consumes the ctx reference, by placing
>> + * the ctx in the context_xa.
>> + */
>> static void gem_context_register(struct i915_gem_context *ctx,
>> struct drm_i915_file_private *fpriv,
>> u32 id)
>> @@ -1703,10 +1707,6 @@ static void gem_context_register(struct i915_gem_context *ctx,
>> snprintf(ctx->name, sizeof(ctx->name), "%s[%d]",
>> current->comm, pid_nr(ctx->pid));
>>
>> - /* And finally expose ourselves to userspace via the idr */
>> - old = xa_store(&fpriv->context_xa, id, ctx, GFP_KERNEL);
>> - WARN_ON(old);
>> -
>> spin_lock(&ctx->client->ctx_lock);
>> list_add_tail_rcu(&ctx->client_link, &ctx->client->ctx_list);
>> spin_unlock(&ctx->client->ctx_lock);
>> @@ -1714,6 +1714,10 @@ static void gem_context_register(struct i915_gem_context *ctx,
>> spin_lock(&i915->gem.contexts.lock);
>> list_add_tail(&ctx->link, &i915->gem.contexts.list);
>> spin_unlock(&i915->gem.contexts.lock);
>> +
>> + /* And finally expose ourselves to userspace via the idr */
>> + old = xa_store(&fpriv->context_xa, id, ctx, GFP_KERNEL);
>> + WARN_ON(old);
>> }
>>
>> int i915_gem_context_open(struct drm_i915_private *i915,
>> @@ -2199,14 +2203,22 @@ finalize_create_context_locked(struct drm_i915_file_private *file_priv,
>> if (IS_ERR(ctx))
>> return ctx;
>>
>> + /*
>> + * One for the xarray and one for the caller. We need to grab
>> + * the reference *prior* to making the ctx visble to userspace
>> + * in gem_context_register(), as at any point after that
>> + * userspace can try to race us with another thread destroying
>> + * the context under our feet.
>> + */
>> + i915_gem_context_get(ctx);
>> +
>> gem_context_register(ctx, file_priv, id);
>>
>> old = xa_erase(&file_priv->proto_context_xa, id);
>> GEM_BUG_ON(old != pc);
>> proto_context_close(file_priv->dev_priv, pc);
>>
>> - /* One for the xarray and one for the caller */
>> - return i915_gem_context_get(ctx);
>> + return ctx;
>> }
>>
>> struct i915_gem_context *
>> --
>> 2.38.1
next prev parent reply other threads:[~2023-01-05 16:00 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-03 23:49 [PATCH] drm/i915: Fix potential context UAFs Rob Clark
2023-01-03 23:49 ` [Intel-gfx] " Rob Clark
2023-01-03 23:49 ` Rob Clark
2023-01-04 9:33 ` Tvrtko Ursulin
2023-01-04 9:33 ` [Intel-gfx] " Tvrtko Ursulin
2023-01-04 9:33 ` Tvrtko Ursulin
2023-01-04 16:01 ` Rob Clark
2023-01-04 16:01 ` [Intel-gfx] " Rob Clark
2023-01-04 16:01 ` Rob Clark
2023-01-04 13:41 ` [Intel-gfx] ✗ Fi.CI.BAT: failure for " Patchwork
2023-01-05 12:33 ` [Intel-gfx] ✓ Fi.CI.BAT: success for drm/i915: Fix potential context UAFs (rev2) Patchwork
2023-01-05 15:52 ` [PATCH] drm/i915: Fix potential context UAFs Andi Shyti
2023-01-05 15:52 ` [Intel-gfx] " Andi Shyti
2023-01-05 15:52 ` Andi Shyti
2023-01-05 16:00 ` Tvrtko Ursulin [this message]
2023-01-05 16:00 ` [Intel-gfx] " Tvrtko Ursulin
2023-01-05 16:00 ` Tvrtko Ursulin
2023-01-06 10:15 ` Tvrtko Ursulin
2023-01-06 10:15 ` [Intel-gfx] " Tvrtko Ursulin
2023-01-06 10:15 ` Tvrtko Ursulin
2023-01-06 9:34 ` [Intel-gfx] ✓ Fi.CI.IGT: success for drm/i915: Fix potential context UAFs (rev2) Patchwork
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=b1aea77b-ba55-61a2-2c33-f7754e0ca586@linux.intel.com \
--to=tvrtko.ursulin@linux.intel.com \
--cc=John.C.Harrison@intel.com \
--cc=airlied@gmail.com \
--cc=andi.shyti@linux.intel.com \
--cc=chris@chris-wilson.co.uk \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=jani.nikula@linux.intel.com \
--cc=joonas.lahtinen@linux.intel.com \
--cc=katrinzhou@tencent.com \
--cc=linux-kernel@vger.kernel.org \
--cc=matthew.brost@intel.com \
--cc=robdclark@chromium.org \
--cc=robdclark@gmail.com \
--cc=rodrigo.vivi@intel.com \
--cc=thomas.hellstrom@linux.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.