2bd4b14
From 050e4b8fb7cdd7096c987a9cd556029c622c7fe2 Mon Sep 17 00:00:00 2001
2bd4b14
From: Jonathan Salwan <jonathan.salwan@gmail.com>
2bd4b14
Date: Thu, 06 Jun 2013 00:39:39 +0000
2bd4b14
Subject: drivers/cdrom/cdrom.c: use kzalloc() for failing hardware
2bd4b14
2bd4b14
In drivers/cdrom/cdrom.c mmc_ioctl_cdrom_read_data() allocates a memory
2bd4b14
area with kmalloc in line 2885.
2bd4b14
2bd4b14
2885         cgc->buffer = kmalloc(blocksize, GFP_KERNEL);
2bd4b14
2886         if (cgc->buffer == NULL)
2bd4b14
2887                 return -ENOMEM;
2bd4b14
2bd4b14
In line 2908 we can find the copy_to_user function:
2bd4b14
2bd4b14
2908         if (!ret && copy_to_user(arg, cgc->buffer, blocksize))
2bd4b14
2bd4b14
The cgc->buffer is never cleaned and initialized before this function.  If
2bd4b14
ret = 0 with the previous basic block, it's possible to display some
2bd4b14
memory bytes in kernel space from userspace.
2bd4b14
2bd4b14
When we read a block from the disk it normally fills the ->buffer but if
2bd4b14
the drive is malfunctioning there is a chance that it would only be
2bd4b14
partially filled.  The result is an leak information to userspace.
2bd4b14
2bd4b14
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
2bd4b14
Cc: Jens Axboe <axboe@kernel.dk>
2bd4b14
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2bd4b14
---
2bd4b14
(limited to 'drivers/cdrom/cdrom.c')
2bd4b14
2bd4b14
diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
2bd4b14
index d620b44..8a3aff7 100644
2bd4b14
--- a/drivers/cdrom/cdrom.c
2bd4b14
+++ b/drivers/cdrom/cdrom.c
2bd4b14
@@ -2882,7 +2882,7 @@ static noinline int mmc_ioctl_cdrom_read_data(struct cdrom_device_info *cdi,
2bd4b14
 	if (lba < 0)
2bd4b14
 		return -EINVAL;
2bd4b14
 
2bd4b14
-	cgc->buffer = kmalloc(blocksize, GFP_KERNEL);
2bd4b14
+	cgc->buffer = kzalloc(blocksize, GFP_KERNEL);
2bd4b14
 	if (cgc->buffer == NULL)
2bd4b14
 		return -ENOMEM;
2bd4b14
 
2bd4b14
--
2bd4b14
cgit v0.9.2