From: Daniel Vetter Subject: Re: [PATCH 2/3] drm: Be more paranoid with integer overflows Date: Thu, 24 May 2012 21:03:43 +0200 Message-ID: <20120524190343.GH5078@phenom.ffwll.local> References: <1337882040-16074-1-git-send-email-ville.syrjala@linux.intel.com> <1337882040-16074-3-git-send-email-ville.syrjala@linux.intel.com> <20120524183023.GE5078@phenom.ffwll.local> <20120524185437.GM13065@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Return-path: Received: from mail-wg0-f43.google.com (mail-wg0-f43.google.com [74.125.82.43]) by gabe.freedesktop.org (Postfix) with ESMTP id 7F56AA0AA0 for ; Thu, 24 May 2012 12:02:23 -0700 (PDT) Received: by wgbdr1 with SMTP id dr1so96521wgb.12 for ; Thu, 24 May 2012 12:02:22 -0700 (PDT) Content-Disposition: inline In-Reply-To: <20120524185437.GM13065@intel.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dri-devel-bounces+sf-dri-devel=m.gmane.org@lists.freedesktop.org Errors-To: dri-devel-bounces+sf-dri-devel=m.gmane.org@lists.freedesktop.org To: Ville =?iso-8859-1?Q?Syrj=E4l=E4?= Cc: dri-devel@lists.freedesktop.org List-Id: dri-devel@lists.freedesktop.org On Thu, May 24, 2012 at 09:54:37PM +0300, Ville Syrj=E4l=E4 wrote: > 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=E4l=E4 > > > = > > > Make sure 'width * cpp' and 'height * pitch + offset' don't exceed > > > UINT_MAX. > > > = > > > Signed-off-by: Ville Syrj=E4l=E4 > > > --- > > > 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 =3D 0; i < num_planes; i++) { > > > unsigned int width =3D r->width / (i !=3D 0 ? hsub : 1); > > > + unsigned int height =3D r->height / (i !=3D 0 ? vsub : 1); > > > + unsigned int cpp =3D 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) * wid= th) { > > > + if ((uint64_t) width * cpp > UINT_MAX) > > > + return -ERANGE; > > > + > > = > > iirc that blows up on 32bit because gcc likes to use a compiler built-i= n. > = > 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. Ah right, I've mixed things up. Sorry for the noise. -Daniel -- = Daniel Vetter Mail: daniel@ffwll.ch Mobile: +41 (0)79 365 57 48