All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: Daniel Vetter <daniel@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 2/3] drm: Be more paranoid with integer overflows
Date: Thu, 24 May 2012 21:54:37 +0300	[thread overview]
Message-ID: <20120524185437.GM13065@intel.com> (raw)
In-Reply-To: <20120524183023.GE5078@phenom.ffwll.local>

On Thu, May 24, 2012 at 08:30:23PM +0200, Daniel Vetter wrote:
> On Thu, May 24, 2012 at 08:53:59PM +0300, ville.syrjala@linux.intel.com wrote:
> > From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > 
> > Make sure 'width * cpp' and 'height * pitch + offset' don't exceed
> > UINT_MAX.
> > 
> > Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > ---
> >  drivers/gpu/drm/drm_crtc.c |   10 +++++++++-
> >  1 files changed, 9 insertions(+), 1 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
> > index 80a34e7..e1b53fb 100644
> > --- a/drivers/gpu/drm/drm_crtc.c
> > +++ b/drivers/gpu/drm/drm_crtc.c
> > @@ -2211,13 +2211,21 @@ static int framebuffer_check(struct drm_mode_fb_cmd2 *r)
> >  
> >  	for (i = 0; i < num_planes; i++) {
> >  		unsigned int width = r->width / (i != 0 ? hsub : 1);
> > +		unsigned int height = r->height / (i != 0 ? vsub : 1);
> > +		unsigned int cpp = drm_format_plane_cpp(r->pixel_format, i);
> >  
> >  		if (!r->handles[i]) {
> >  			DRM_DEBUG_KMS("no buffer object handle for plane %d\n", i);
> >  			return -EINVAL;
> >  		}
> >  
> > -		if (r->pitches[i] < drm_format_plane_cpp(r->pixel_format, i) * width) {
> > +		if ((uint64_t) width * cpp > UINT_MAX)
> > +			return -ERANGE;
> > +
> 
> iirc that blows up on 32bit because gcc likes to use a compiler built-in.

I think that problem only happens w/ 64bit divs, which is why you have do_div()
and friends. At least with a small test app 'gcc -O2 -m32' generates the obvious
mul+cmp code, and mul+add+adc+cmp for the case w/ offsets[i] added. Maybe other
archs can't do it so neatly though.

> And the usual pattern I've seen is if (UINT_MAX / a < b) return -ERANGE;

I'm not a fan of divs :)

-- 
Ville Syrjälä
Intel OTC

  reply	other threads:[~2012-05-24 18:56 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-24 17:53 [PATCH 0/3] drm: A few misc patches ville.syrjala
2012-05-24 17:53 ` [PATCH 1/3] drm: Use stdint types for consistency ville.syrjala
2012-05-24 17:53 ` [PATCH 2/3] drm: Be more paranoid with integer overflows ville.syrjala
2012-05-24 18:30   ` Daniel Vetter
2012-05-24 18:54     ` Ville Syrjälä [this message]
2012-05-24 19:03       ` Daniel Vetter
2012-05-24 17:54 ` [PATCH 3/3] drm: Constify params to format_check() and framebuffer_checks() ville.syrjala
2012-05-24 18:16 ` [PATCH 0/3] drm: A few misc patches Alex Deucher

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=20120524185437.GM13065@intel.com \
    --to=ville.syrjala@linux.intel.com \
    --cc=daniel@ffwll.ch \
    --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 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.