From: Frediano Ziglio <fziglio@redhat.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Dave Airlie <airlied@redhat.com>,
security@kernel.org,
Ilja Van Sprundel <ivansprundel@ioactive.com>,
dri-devel@lists.freedesktop.org
Subject: Re: [patch 4/4] drm/qxl: integer overflow in qxl_alloc_surf_ioctl()
Date: Fri, 18 Sep 2015 05:46:04 -0400 (EDT) [thread overview]
Message-ID: <421515033.28673933.1442569564307.JavaMail.zimbra@redhat.com> (raw)
In-Reply-To: <20150917112442.GD4882@mwanda>
> The size calculation can overflow.
>
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>
> diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c
> b/drivers/gpu/drm/qxl/qxl_ioctl.c
> index 552dc06..5da9a60 100644
> --- a/drivers/gpu/drm/qxl/qxl_ioctl.c
> +++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
> @@ -401,6 +401,8 @@ static int qxl_alloc_surf_ioctl(struct drm_device *dev,
> void *data,
>
> /* work out size allocate bo with handle */
> actual_stride = param->stride < 0 ? -param->stride : param->stride;
> + if (actual_stride > (INT_MAX - actual_stride) / param->height)
> + return -EINVAL;
> size = actual_stride * param->height + actual_stride;
>
> surf.format = param->format;
>
There are some issues here. param->stride can be -2^31 so actual_stride will
be probably -2^31. You introduced a possible division by zero (param->height == 0).
Do you know who validate the structure size? I don't see any check on the code.
Looks like the data pointer is coming from userspace untested.
An easiest way to do these check is use 64 bit arithmetic so something like
u64 actual_stride, size;
actual_stride = param->stride < 0 ? -param->stride : param->stride;
size = actual_stride * param->height + actual_stride;
if (size > INT_MAX)
return -EINVAL;
take into account that usually division is quite slow so on many system even if 32 bit
the multiplication is faster. And if is not faster you are creating a surface so
is not really a fast path.
You should also check if the stride computed from width and format fit into the stride
provided.
Do you know why actual_stride * param->height is not enough? Why an extra line?
Regards,
Frediano
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2015-09-18 9:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-17 11:24 [patch 4/4] drm/qxl: integer overflow in qxl_alloc_surf_ioctl() Dan Carpenter
2015-09-18 9:46 ` Frediano Ziglio [this message]
2015-09-22 14:32 ` [patch 4/4 v2] " Dan Carpenter
2015-09-22 14:32 ` Dan Carpenter
2015-09-23 10:45 ` Frediano Ziglio
2015-09-23 10:45 ` Frediano Ziglio
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=421515033.28673933.1442569564307.JavaMail.zimbra@redhat.com \
--to=fziglio@redhat.com \
--cc=airlied@redhat.com \
--cc=dan.carpenter@oracle.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=ivansprundel@ioactive.com \
--cc=security@kernel.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.