From: "Antoine, Peter" <peter.antoine@intel.com>
To: "daniel@ffwll.ch" <daniel@ffwll.ch>
Cc: "airlied@redhat.com" <airlied@redhat.com>,
"intel-gfx@lists.freedesktop.org"
<intel-gfx@lists.freedesktop.org>,
"dri-devel@lists.freedesktop.org"
<dri-devel@lists.freedesktop.org>,
"daniel.vetter@ffwll.ch" <daniel.vetter@ffwll.ch>
Subject: Re: [PATCH 3/5] drm: Possible lock priority escalation.
Date: Tue, 5 May 2015 06:45:30 +0000 [thread overview]
Message-ID: <1430808329.15051.14.camel@peterant-linux> (raw)
In-Reply-To: <20150504135603.GD30184@phenom.ffwll.local>
On Mon, 2015-05-04 at 15:56 +0200, Daniel Vetter wrote:
> On Mon, Apr 27, 2015 at 07:52:46PM +0300, Ville Syrjälä wrote:
> > On Thu, Apr 23, 2015 at 03:07:56PM +0100, Peter Antoine wrote:
> > > If an application that has a driver lock created, wants the lock the
> > > kernel context, it is not allowed to. If the call to drm_lock has a
> > > context of 0, it is rejected. If you set the context to _DRM_LOCK_CONT
> > > then call drm lock, it will pass the context == DRM_KERNEL_CONTEXT checks.
> > > But as the DRM_LOCK_CONT bits are not part of the context id this allows
> > > operations on the DRM_KERNEL_CONTEXT.
> > >
> > > Issue: VIZ-5485
> > > Signed-off-by: Peter Antoine <peter.antoine@intel.com>
>
> If you're touching code with drm_legacy_ prefix of in such a file you've
> ended up in the horrible corners of the dri1 dungeons and should head back
> out pronto ;-)
>
> If we can actually run into this code on production i915 then we need to
> improve the locks at the door of these dungeons for kms drivers, not try
> to fix up the mess behind them. That's just plain impossible.
>
> If you want to make really sure we get this right some simple drm igt
> tests to make sure these codepaths are really dead for kms driver might be
> good. But otherwise we really can only annotate this as wontfix in
> code security issue scanners.
> -Daniel
>
There is a test that covers this fix. This is a simple three line fix
that stops a userspace driver locking the kernel context. Yes they are
other problems with this code, but why are they stopping this patch that
does a simple fix from going in?
I'll happily drop this patch if it causes more problems that it fixes.
Peter.
> > > ---
> > > drivers/gpu/drm/drm_context.c | 6 +++---
> > > drivers/gpu/drm/drm_lock.c | 4 ++--
> > > 2 files changed, 5 insertions(+), 5 deletions(-)
> > >
> > > diff --git a/drivers/gpu/drm/drm_context.c b/drivers/gpu/drm/drm_context.c
> > > index 96350d1..1febcd3 100644
> > > --- a/drivers/gpu/drm/drm_context.c
> > > +++ b/drivers/gpu/drm/drm_context.c
> > > @@ -123,7 +123,7 @@ void drm_legacy_ctxbitmap_flush(struct drm_device *dev, struct drm_file *file)
> > >
> > > list_for_each_entry_safe(pos, tmp, &dev->ctxlist, head) {
> > > if (pos->tag == file &&
> > > - pos->handle != DRM_KERNEL_CONTEXT) {
> > > + _DRM_LOCKING_CONTEXT(pos->handle) != DRM_KERNEL_CONTEXT) {
> > > if (dev->driver->context_dtor)
> > > dev->driver->context_dtor(dev, pos->handle);
> > >
> > > @@ -342,7 +342,7 @@ int drm_legacy_addctx(struct drm_device *dev, void *data,
> > > struct drm_ctx *ctx = data;
> > >
> > > ctx->handle = drm_legacy_ctxbitmap_next(dev);
> > > - if (ctx->handle == DRM_KERNEL_CONTEXT) {
> > > + if (_DRM_LOCKING_CONTEXT(ctx->handle) == DRM_KERNEL_CONTEXT) {
> > > /* Skip kernel's context and get a new one. */
> > > ctx->handle = drm_legacy_ctxbitmap_next(dev);
> > > }
> > > @@ -449,7 +449,7 @@ int drm_legacy_rmctx(struct drm_device *dev, void *data,
> > > struct drm_ctx *ctx = data;
> > >
> > > DRM_DEBUG("%d\n", ctx->handle);
> > > - if (ctx->handle != DRM_KERNEL_CONTEXT) {
> > > + if (_DRM_LOCKING_CONTEXT(ctx->handle) != DRM_KERNEL_CONTEXT) {
> > > if (dev->driver->context_dtor)
> > > dev->driver->context_dtor(dev, ctx->handle);
> > > drm_legacy_ctxbitmap_free(dev, ctx->handle);
> >
> > How about just fixing the end parameter passed to idr_alloc()? AFAICS
> > that would take care of the context code.
> >
> > Well, there are a few more issues with the code:
> > - not properly checking for negative return value from idr_alloc()
> > - leaking the ctx id on kmalloc() error
> > - pointless check for idr_alloc() returning 0 even though the min is 1
> >
> > > diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
> > > index 070dd5d..94500930 100644
> > > --- a/drivers/gpu/drm/drm_lock.c
> > > +++ b/drivers/gpu/drm/drm_lock.c
> > > @@ -63,7 +63,7 @@ int drm_legacy_lock(struct drm_device *dev, void *data,
> > >
> > > ++file_priv->lock_count;
> >
> > While you're poking around this dungeopn, maybe you can kill lock_count?
> > We never seem to decrement it, and it's only checked in drm_legacy_i_have_hw_lock().
> >
> > >
> > > - if (lock->context == DRM_KERNEL_CONTEXT) {
> > > + if (_DRM_LOCKING_CONTEXT(lock->context) == DRM_KERNEL_CONTEXT) {
> > > DRM_ERROR("Process %d using kernel context %d\n",
> > > task_pid_nr(current), lock->context);
> > > return -EINVAL;
> > > @@ -153,7 +153,7 @@ int drm_legacy_unlock(struct drm_device *dev, void *data, struct drm_file *file_
> > > struct drm_lock *lock = data;
> > > struct drm_master *master = file_priv->master;
> > >
> > > - if (lock->context == DRM_KERNEL_CONTEXT) {
> > > + if (_DRM_LOCKING_CONTEXT(lock->context) == DRM_KERNEL_CONTEXT) {
> > > DRM_ERROR("Process %d using kernel context %d\n",
> > > task_pid_nr(current), lock->context);
> > > return -EINVAL;
> >
> > These two changes look OK to me.
> >
> > > --
> > > 1.9.1
> > >
> > > _______________________________________________
> > > Intel-gfx mailing list
> > > Intel-gfx@lists.freedesktop.org
> > > http://lists.freedesktop.org/mailman/listinfo/intel-gfx
> >
> > --
> > Ville Syrjälä
> > Intel OTC
>
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
next prev parent reply other threads:[~2015-05-05 6:45 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-23 14:07 [PATCH 0/5] HW_LOCK Security Patches Peter Antoine
2015-04-23 14:07 ` [PATCH 1/5] drm: Kernel Crash in drm_unlock Peter Antoine
2015-04-23 14:19 ` [Intel-gfx] " Chris Wilson
2015-04-23 14:34 ` Antoine, Peter
2015-04-23 14:39 ` [Intel-gfx] " Chris Wilson
2015-04-24 5:52 ` Antoine, Peter
2015-04-28 9:21 ` Dave Gordon
2015-04-28 9:52 ` chris
2015-05-04 13:52 ` Daniel Vetter
2015-05-05 6:37 ` Antoine, Peter
2015-05-05 7:20 ` Daniel Vetter
2015-04-28 14:56 ` Dave Gordon
2015-04-23 14:07 ` [PATCH 2/5] drm: Fixes unsafe deference in locks Peter Antoine
2015-04-23 14:21 ` [Intel-gfx] " Chris Wilson
2015-04-23 14:07 ` [PATCH 3/5] drm: Possible lock priority escalation Peter Antoine
2015-04-27 16:52 ` [Intel-gfx] " Ville Syrjälä
2015-05-04 13:56 ` Daniel Vetter
2015-05-05 6:45 ` Antoine, Peter [this message]
2015-05-05 7:23 ` Daniel Vetter
2015-04-23 14:07 ` [PATCH 4/5] drm: Make HW_LOCK access functions optional Peter Antoine
2015-04-27 17:03 ` Ville Syrjälä
2015-04-28 5:52 ` Antoine, Peter
2015-04-28 10:40 ` Ville Syrjälä
2015-04-28 11:29 ` Antoine, Peter
2015-04-28 13:08 ` Ville Syrjälä
2015-04-28 13:29 ` Antoine, Peter
2015-05-04 14:05 ` Daniel Vetter
2015-05-04 23:02 ` Dave Airlie
2015-04-23 14:07 ` [PATCH 5/5] drm: Make Legacy Context " Peter Antoine
2015-04-23 19:01 ` shuang.he
2015-05-13 6:54 ` [PATCH v2 0/2] HW_LOCK kernel patched Peter Antoine
2015-05-13 6:54 ` [PATCH v2 1/2] drm: Make HW_LOCK access functions optional Peter Antoine
2015-05-13 7:14 ` Daniel Vetter
2015-05-13 7:24 ` Daniel Vetter
2015-05-13 6:54 ` [PATCH v2 2/2] drm: Make Legacy Context " Peter Antoine
2015-05-13 7:19 ` Daniel Vetter
2015-05-13 9:41 ` Ville Syrjälä
2015-05-15 5:58 ` shuang.he
2015-05-13 7:08 ` [PATCH v2 0/2] HW_LOCK kernel patched Daniel Vetter
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=1430808329.15051.14.camel@peterant-linux \
--to=peter.antoine@intel.com \
--cc=airlied@redhat.com \
--cc=daniel.vetter@ffwll.ch \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.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