dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: David Herrmann <dh.herrmann@gmail.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v2 5/6] drm/crtc: add sanity checks to create_dumb()
Date: Thu, 23 Jan 2014 15:55:16 +0200	[thread overview]
Message-ID: <20140123135516.GV9454@intel.com> (raw)
In-Reply-To: <1390481595-512-1-git-send-email-dh.herrmann@gmail.com>

On Thu, Jan 23, 2014 at 01:53:15PM +0100, David Herrmann wrote:
> Lets make sure some basic expressions are always true:
>   bpp != NULL
>   width != NULL
>   height != NULL
>   stride = bpp * width < 2^32
>   size = stride * height < 2^32
>   PAGE_ALIGN(size) < 2^32
> 
> At least the udl driver doesn't check for multiplication-overflows, so
> lets just make sure it will never happen. These checks allow drivers to do
> any 32bit math without having to test for mult-overflows themselves.
> 
> The two divisions might hurt performance a bit, but dumb_create() is only
> used for scanout-buffers, so that should be fine. We could use 64bit math
> to avoid the divisions, but that may be slow on 32bit machines.. Or maybe
> there should just be a "safe_mult32()" helper, which currently doesn't
> exist (I think?).
> 
> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
> Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
> ---
>  drivers/gpu/drm/drm_crtc.c | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
> index 266a01d..2b50702 100644
> --- a/drivers/gpu/drm/drm_crtc.c
> +++ b/drivers/gpu/drm/drm_crtc.c
> @@ -3738,9 +3738,26 @@ int drm_mode_create_dumb_ioctl(struct drm_device *dev,
>  			       void *data, struct drm_file *file_priv)
>  {
>  	struct drm_mode_create_dumb *args = data;
> +	u32 cpp, stride, size;
>  
>  	if (!dev->driver->dumb_create)
>  		return -ENOSYS;
> +	if (!args->width || !args->height || !args->bpp)
> +		return -EINVAL;
> +
> +	/* overflow checks for 32bit size calculations */
> +	cpp = DIV_ROUND_UP(args->bpp, 8);
> +	if (cpp > 0xffffffffU / args->width)
> +		return -EINVAL;

IIRC I used -ERANGE for such things in some drm_framebuffer checks. Not
sure if that's the best error value or not, but using the same one in
both places would be nice.

> +	stride = cpp * args->width;
> +	if (args->height > 0xffffffffU / stride)
> +		return -EINVAL;
> +
> +	/* test for wrap-around */
> +	size = args->height * stride;
> +	if (PAGE_ALIGN(size) == 0)
> +		return -EINVAL;
> +
>  	return dev->driver->dumb_create(file_priv, dev, args);
>  }
>  
> -- 
> 1.8.5.3
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel

-- 
Ville Syrjälä
Intel OTC

  reply	other threads:[~2014-01-23 13:55 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-20 19:26 [PATCH 1/7] drm/udl: fix error-path when damage-req fails David Herrmann
2014-01-20 19:26 ` [PATCH 2/7] drm/udl: fix Bpp calculation in dumb_create() David Herrmann
2014-01-21  9:38   ` Daniel Vetter
2014-01-21 11:13     ` David Herrmann
2014-01-23 12:50   ` [PATCH v2 2/6] " David Herrmann
2014-02-05 21:28     ` David Herrmann
2014-01-20 19:26 ` [PATCH 3/7] drm/udl: import prime-fds with proper page-alignment David Herrmann
2014-01-21  9:41   ` Daniel Vetter
2014-01-23 12:51     ` David Herrmann
2014-01-20 19:26 ` [PATCH 4/7] drm/gem: fix indentation David Herrmann
2014-02-05 21:28   ` David Herrmann
2014-01-20 19:26 ` [PATCH 5/7] drm/gem: free vma-node during object-cleanup David Herrmann
2014-02-05 21:29   ` David Herrmann
2014-01-20 19:26 ` [PATCH 6/7] drm/crtc: add sanity checks to create_dumb() David Herrmann
2014-01-21  9:49   ` Daniel Vetter
2014-01-21 11:17     ` David Herrmann
2014-01-21 11:42       ` Ville Syrjälä
2014-01-21 11:52         ` David Herrmann
2014-01-21 11:57           ` Chris Wilson
2014-01-23 12:53   ` [PATCH v2 5/6] " David Herrmann
2014-01-23 13:55     ` Ville Syrjälä [this message]
2014-01-23 14:10       ` David Herrmann
2014-02-05 21:29         ` David Herrmann
2014-01-20 19:26 ` [PATCH 7/7] drm/gem: dont init "ret" in drm_gem_mmap() David Herrmann
2014-01-21  9:51   ` Daniel Vetter
2014-02-05 21:29     ` David Herrmann
2014-01-21  9:43 ` [PATCH 1/7] drm/udl: fix error-path when damage-req fails Daniel Vetter
2014-01-23 12:48 ` [PATCH v2 1/6] " David Herrmann
2014-02-05 21:28   ` David Herrmann

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=20140123135516.GV9454@intel.com \
    --to=ville.syrjala@linux.intel.com \
    --cc=daniel.vetter@ffwll.ch \
    --cc=dh.herrmann@gmail.com \
    --cc=dri-devel@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