Skip to contentSkip to conversation

qxl: use kmalloc_array to alloc reloc_info in qxl_process_single_command

PATCH In review Gerd Hoffmann 2 participants 2 messages Feb 16, 2016

Subsystems (4)
lore
Share & tools
lore

Gerd Hoffmann

author maintainer
#0 lore raw

PATCH v2 1/1 qxl: use kmalloc_array to alloc reloc_info in qxl_process_single_command

This avoids integer overflows on 32bit machines when calculating reloc_info size, as reported by Alan Cox.

---
 drivers/gpu/drm/qxl/qxl_ioctl.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/qxl/qxl_ioctl.c +2 -1
index 2ae8577..7c2e782 100644
@@ -168,7 +168,8 @@ static int qxl_process_single_command(struct qxl_device *qdev,
 		       cmd->command_size))
 		return -EFAULT;
 
-	reloc_info = kmalloc(sizeof(struct qxl_reloc_info) * cmd->relocs_num, GFP_KERNEL);
+	reloc_info = kmalloc_array(cmd->relocs_num,
+				   sizeof(struct qxl_reloc_info), GFP_KERNEL);
 	if (!reloc_info)
 		return -ENOMEM;
 
Signature · 1 line
1.8.3.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 6 lines · Gerd Hoffmann

This avoids integer overflows on 32bit machines when calculating reloc_info size, as reported by Alan Cox.

Quoted 21 lines
---
 drivers/gpu/drm/qxl/qxl_ioctl.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/qxl/qxl_ioctl.c +2 -1
index 2ae8577..7c2e782 100644
@@ -168,7 +168,8 @@ static int qxl_process_single_command(struct qxl_device *qdev,
 		       cmd->command_size))
 		return -EFAULT;
 
-	reloc_info = kmalloc(sizeof(struct qxl_reloc_info) * cmd->relocs_num, GFP_KERNEL);
+	reloc_info = kmalloc_array(cmd->relocs_num,
+				   sizeof(struct qxl_reloc_info), GFP_KERNEL);
 	if (!reloc_info)
 		return -ENOMEM;
 
Signature · 1 line
1.8.3.1
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch