drivers/cdrom/cdrom.c: use kzalloc() for failing hardware
authorJonathan Salwan <jonathan.salwan@gmail.com>
Wed, 3 Jul 2013 22:01:13 +0000 (15:01 -0700)
committerBen Hutchings <ben@decadent.org.uk>
Sat, 27 Jul 2013 04:34:33 +0000 (05:34 +0100)
commit6dfd19d0d4d5dd081e1312a550ffae6acc85d70a
tree6162c4d14d277e4875b358371719920c59a28d28
parent790e332c473eded2396dcf7e2902cbe4429b6a80
drivers/cdrom/cdrom.c: use kzalloc() for failing hardware

commit 542db01579fbb7ea7d1f7bb9ddcef1559df660b2 upstream.

In drivers/cdrom/cdrom.c mmc_ioctl_cdrom_read_data() allocates a memory
area with kmalloc in line 2885.

  2885         cgc->buffer = kmalloc(blocksize, GFP_KERNEL);
  2886         if (cgc->buffer == NULL)
  2887                 return -ENOMEM;

In line 2908 we can find the copy_to_user function:

  2908         if (!ret && copy_to_user(arg, cgc->buffer, blocksize))

The cgc->buffer is never cleaned and initialized before this function.
If ret = 0 with the previous basic block, it's possible to display some
memory bytes in kernel space from userspace.

When we read a block from the disk it normally fills the ->buffer but if
the drive is malfunctioning there is a chance that it would only be
partially filled.  The result is an leak information to userspace.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
drivers/cdrom/cdrom.c