diff mbox

qxl: apply limit to relocs_num in qxl_process_single_command

Message ID 1455623363-9224-1-git-send-email-kraxel@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Gerd Hoffmann Feb. 16, 2016, 11:49 a.m. UTC
Limit relocs_num to 65536.  That limit is small enougth to avoid integer
overflow on 32bit machines when calculating reloc_info size (as reported
by Alan Cox), and is big enougth to not block normal usage (kmalloc
would ENOMEM on requests larger than that anyway).

Cc: stable@vger.kernel.org
Cc: gnomes@lxorguk.ukuu.org.uk
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 drivers/gpu/drm/qxl/qxl_ioctl.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Daniel Vetter Feb. 16, 2016, 12:45 p.m. UTC | #1
On Tue, Feb 16, 2016 at 12:49 PM, Gerd Hoffmann <kraxel@redhat.com> wrote:
> +       if (cmd->relocs_num > 65536)
> +               return -EINVAL;
>         reloc_info = kmalloc(sizeof(struct qxl_reloc_info) * cmd->relocs_num, GFP_KERNEL);
>         if (!reloc_info)
>                 return -ENOMEM;

Why not just use one of the array alloc functions like kcalloc?
-Daniel
diff mbox

Patch

diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
index 2ae8577..970cb83 100644
--- a/drivers/gpu/drm/qxl/qxl_ioctl.c
+++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
@@ -168,6 +168,8 @@  static int qxl_process_single_command(struct qxl_device *qdev,
 		       cmd->command_size))
 		return -EFAULT;
 
+	if (cmd->relocs_num > 65536)
+		return -EINVAL;
 	reloc_info = kmalloc(sizeof(struct qxl_reloc_info) * cmd->relocs_num, GFP_KERNEL);
 	if (!reloc_info)
 		return -ENOMEM;