From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Pavel Roskin <proski@gnu.org>, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH] drm: Restrict ioctl size to kernel struct size
Date: Tue, 22 Oct 2013 13:40:04 +0300 [thread overview]
Message-ID: <20131022104004.GE13047@intel.com> (raw)
In-Reply-To: <1382434683-32048-1-git-send-email-chris@chris-wilson.co.uk>
On Tue, Oct 22, 2013 at 10:38:03AM +0100, Chris Wilson wrote:
> Prevent the user from passing in an ioctl command with up to 16,383
> bytes specified for the struct to be allocated and copied, and
> instead only allocate enough space to satisfy the kernel.
>
> Suggested-by: Pavel Roskin <proski@gnu.org>
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Pavel Roskin <proski@gnu.org>
> Cc: dri-devel@lists.freedesktop.org
Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> ---
> drivers/gpu/drm/drm_drv.c | 30 +++++++++++++-----------------
> 1 file changed, 13 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
> index 05ad9ba0a67e..8c5fbc9d41ad 100644
> --- a/drivers/gpu/drm/drm_drv.c
> +++ b/drivers/gpu/drm/drm_drv.c
> @@ -354,6 +354,16 @@ static int drm_version(struct drm_device *dev, void *data,
> return err;
> }
>
> +static unsigned ioctl_size(unsigned kcmd, unsigned ucmd, unsigned *ksize, unsigned *usize)
> +{
> + *ksize = _IOC_SIZE(kcmd);
> + *usize = _IOC_SIZE(ucmd);
> + if (*usize > *ksize)
> + *usize = *ksize;
> +
> + return kcmd;
> +}
> +
> /**
> * Called whenever a process performs an ioctl on /dev/drm.
> *
> @@ -393,25 +403,11 @@ long drm_ioctl(struct file *filp,
> goto err_i1;
> if ((nr >= DRM_COMMAND_BASE) && (nr < DRM_COMMAND_END) &&
> (nr < DRM_COMMAND_BASE + dev->driver->num_ioctls)) {
> - u32 drv_size;
> ioctl = &dev->driver->ioctls[nr - DRM_COMMAND_BASE];
> - drv_size = _IOC_SIZE(ioctl->cmd_drv);
> - usize = asize = _IOC_SIZE(cmd);
> - if (drv_size > asize)
> - asize = drv_size;
> - cmd = ioctl->cmd_drv;
> - }
> - else if ((nr >= DRM_COMMAND_END) || (nr < DRM_COMMAND_BASE)) {
> - u32 drv_size;
> -
> + cmd = ioctl_size(ioctl->cmd_drv, cmd, &asize, &usize);
> + } else if ((nr >= DRM_COMMAND_END) || (nr < DRM_COMMAND_BASE)) {
> ioctl = &drm_ioctls[nr];
> -
> - drv_size = _IOC_SIZE(ioctl->cmd);
> - usize = asize = _IOC_SIZE(cmd);
> - if (drv_size > asize)
> - asize = drv_size;
> -
> - cmd = ioctl->cmd;
> + cmd = ioctl_size(ioctl->cmd, cmd, &asize, &usize);
> } else
> goto err_i1;
>
> --
> 1.8.4.rc3
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel
--
Ville Syrjälä
Intel OTC
next prev parent reply other threads:[~2013-10-22 10:40 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-17 0:12 [PATCH] drm: never write to the userspace more data than the caller wants Pavel Roskin
2013-10-17 12:26 ` Chris Wilson
2013-10-17 14:58 ` Pavel Roskin
2013-10-22 9:38 ` [PATCH] drm: Restrict ioctl size to kernel struct size Chris Wilson
2013-10-22 10:40 ` Ville Syrjälä [this message]
2013-10-22 15:57 ` Pavel Roskin
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=20131022104004.GE13047@intel.com \
--to=ville.syrjala@linux.intel.com \
--cc=chris@chris-wilson.co.uk \
--cc=dri-devel@lists.freedesktop.org \
--cc=proski@gnu.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.