2019-10-04 10:40:43

by Dan Carpenter

[permalink] [raw]
Subject: [PATCH] drm/i810: Prevent underflow in ioctl

The "used" variables here come from the user in the ioctl and it can be
negative. It could result in an out of bounds write.

Signed-off-by: Dan Carpenter <[email protected]>
---
drivers/gpu/drm/i810/i810_dma.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
index 2a77823b8e9a..e66c38332df4 100644
--- a/drivers/gpu/drm/i810/i810_dma.c
+++ b/drivers/gpu/drm/i810/i810_dma.c
@@ -728,7 +728,7 @@ static void i810_dma_dispatch_vertex(struct drm_device *dev,
if (nbox > I810_NR_SAREA_CLIPRECTS)
nbox = I810_NR_SAREA_CLIPRECTS;

- if (used > 4 * 1024)
+ if (used < 0 || used > 4 * 1024)
used = 0;

if (sarea_priv->dirty)
@@ -1048,7 +1048,7 @@ static void i810_dma_dispatch_mc(struct drm_device *dev, struct drm_buf *buf, in
if (u != I810_BUF_CLIENT)
DRM_DEBUG("MC found buffer that isn't mine!\n");

- if (used > 4 * 1024)
+ if (used < 0 || used > 4 * 1024)
used = 0;

sarea_priv->dirty = 0x7f;
--
2.20.1


2019-10-04 14:10:57

by Chris Wilson

[permalink] [raw]
Subject: Re: [PATCH] drm/i810: Prevent underflow in ioctl

Quoting Dan Carpenter (2019-10-04 11:22:51)
> The "used" variables here come from the user in the ioctl and it can be
> negative. It could result in an out of bounds write.
>
> Signed-off-by: Dan Carpenter <[email protected]>
> ---
> drivers/gpu/drm/i810/i810_dma.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
> index 2a77823b8e9a..e66c38332df4 100644
> --- a/drivers/gpu/drm/i810/i810_dma.c
> +++ b/drivers/gpu/drm/i810/i810_dma.c
> @@ -728,7 +728,7 @@ static void i810_dma_dispatch_vertex(struct drm_device *dev,
> if (nbox > I810_NR_SAREA_CLIPRECTS)
> nbox = I810_NR_SAREA_CLIPRECTS;
>
> - if (used > 4 * 1024)
> + if (used < 0 || used > 4 * 1024)
> used = 0;

Yes, as passed to the GPU instruction, negative used is invalid.

Then it is used as an offset into a memblock, where a negative offset
would be very bad.

Reviewed-by: Chris Wilson <[email protected]>
-Chris

2019-10-04 16:06:43

by Chris Wilson

[permalink] [raw]
Subject: Re: [PATCH] drm/i810: Prevent underflow in ioctl

Quoting Chris Wilson (2019-10-04 15:08:57)
> Quoting Dan Carpenter (2019-10-04 11:22:51)
> > The "used" variables here come from the user in the ioctl and it can be
> > negative. It could result in an out of bounds write.
> >
> > Signed-off-by: Dan Carpenter <[email protected]>
> > ---
> > drivers/gpu/drm/i810/i810_dma.c | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
> > index 2a77823b8e9a..e66c38332df4 100644
> > --- a/drivers/gpu/drm/i810/i810_dma.c
> > +++ b/drivers/gpu/drm/i810/i810_dma.c
> > @@ -728,7 +728,7 @@ static void i810_dma_dispatch_vertex(struct drm_device *dev,
> > if (nbox > I810_NR_SAREA_CLIPRECTS)
> > nbox = I810_NR_SAREA_CLIPRECTS;
> >
> > - if (used > 4 * 1024)
> > + if (used < 0 || used > 4 * 1024)
> > used = 0;
>
> Yes, as passed to the GPU instruction, negative used is invalid.
>
> Then it is used as an offset into a memblock, where a negative offset
> would be very bad.
>
> Reviewed-by: Chris Wilson <[email protected]>

Applied to drm-misc-next with cc'ed stable.
-Chris