public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Ben Widawsky <ben@bwidawsk.net>
To: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Intel Graphics Development <intel-gfx@lists.freedesktop.org>
Subject: Re: [PATCH 4/5] drm/i915: check for allocation overflow in error state capture
Date: Fri, 20 Sep 2013 16:39:12 -0700	[thread overview]
Message-ID: <20130920233912.GA1710@bwidawsk.net> (raw)
In-Reply-To: <1379585916-6521-4-git-send-email-daniel.vetter@ffwll.ch>

On Thu, Sep 19, 2013 at 12:18:35PM +0200, Daniel Vetter wrote:
> Pretty harmless since actually binding such a giant thing would be
> really hard to pull off - it doesn't fit into the gtt of any shipping
> gpu right now.
> 
> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
> ---
>  drivers/gpu/drm/i915/i915_gpu_error.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_gpu_error.c b/drivers/gpu/drm/i915/i915_gpu_error.c
> index 763283e..6c80636 100644
> --- a/drivers/gpu/drm/i915/i915_gpu_error.c
> +++ b/drivers/gpu/drm/i915/i915_gpu_error.c
> @@ -478,7 +478,7 @@ static void i915_error_state_free(struct kref *error_ref)
>  static struct drm_i915_error_object *
>  i915_error_object_create_sized(struct drm_i915_private *dev_priv,
>  			       struct drm_i915_gem_object *src,
> -			       const int num_pages)
> +			       const unsigned int num_pages)
>  {
>  	struct drm_i915_error_object *dst;
>  	int i;
> @@ -487,6 +487,12 @@ i915_error_object_create_sized(struct drm_i915_private *dev_priv,
>  	if (src == NULL || src->pages == NULL)
>  		return NULL;
>  
> +	if (num_pages > (UINT_MAX - sizeof(*dst)) / sizeof(u32 *)) {
> +		DRM_DEBUG("error object with overflowing num_pages %u\n",
> +			  num_pages);
> +		return NULL;
> +	}
> +

I think either of these two assertions would be much better:
if (num_pages > src->base.size >> PAGE_SHIFT)

or

if (num_pages > dev_priv->gtt.base.total >> 12)...

Later with PPGTT, the gtt will just be a VM.

>  	dst = kmalloc(sizeof(*dst) + num_pages * sizeof(u32 *), GFP_ATOMIC);
>  	if (dst == NULL)
>  		return NULL;

-- 
Ben Widawsky, Intel Open Source Technology Center

  reply	other threads:[~2013-09-20 23:39 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-19 10:18 [PATCH 1/5] drm/i915: use pointer = k[cmz...]alloc(sizeof(*pointer), ...) pattern Daniel Vetter
2013-09-19 10:18 ` [PATCH 2/5] drm/i915: Use kcalloc more Daniel Vetter
2013-09-19 10:38   ` Jani Nikula
2013-09-19 10:50     ` Chris Wilson
2013-09-19 11:00       ` Jani Nikula
2013-09-19 11:12         ` Chris Wilson
2013-09-19 10:46   ` Chris Wilson
2013-09-19 11:53     ` Daniel Vetter
2013-09-19 12:06     ` [PATCH] " Daniel Vetter
2013-09-19 12:30       ` Chris Wilson
2013-09-19 12:35         ` Daniel Vetter
2013-09-19 12:41           ` Chris Wilson
2013-09-19 12:51             ` Daniel Vetter
2013-09-19 12:58               ` Chris Wilson
2013-09-20 22:37                 ` Daniel Vetter
2013-09-19 13:40       ` Jani Nikula
2013-09-19 10:18 ` [PATCH 3/5] drm/i915: Ditch INTELFB_CONN_LIMIT Daniel Vetter
2013-09-19 10:53   ` Jani Nikula
2013-09-19 12:05     ` [PATCH] " Daniel Vetter
2013-09-19 13:32       ` Jani Nikula
2013-09-19 10:18 ` [PATCH 4/5] drm/i915: check for allocation overflow in error state capture Daniel Vetter
2013-09-20 23:39   ` Ben Widawsky [this message]
2013-09-19 10:18 ` [PATCH 5/5] drm/i915: Use unsigned for overflow checks in execbuf Daniel Vetter
2013-09-19 10:44   ` Chris Wilson
2013-09-19 12:00     ` [PATCH] " Daniel Vetter
2013-09-19 12:53       ` Daniel Vetter
2013-09-19 13:05         ` Chris Wilson
2013-09-19 10:46   ` [PATCH 5/5] " Jani Nikula
2013-09-19 10:34 ` [PATCH 1/5] drm/i915: use pointer = k[cmz...]alloc(sizeof(*pointer), ...) pattern Jani Nikula

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=20130920233912.GA1710@bwidawsk.net \
    --to=ben@bwidawsk.net \
    --cc=daniel.vetter@ffwll.ch \
    --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