Skip to content

Commit 542db01

Browse files
JonathanSalwantorvalds
authored andcommitted
drivers/cdrom/cdrom.c: use kzalloc() for failing hardware
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>
1 parent 8b0d77f commit 542db01

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

‎drivers/cdrom/cdrom.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2882,7 +2882,7 @@ static noinline int mmc_ioctl_cdrom_read_data(struct cdrom_device_info *cdi,
28822882
if (lba < 0)
28832883
return -EINVAL;
28842884

2885-
cgc->buffer = kmalloc(blocksize, GFP_KERNEL);
2885+
cgc->buffer = kzalloc(blocksize, GFP_KERNEL);
28862886
if (cgc->buffer == NULL)
28872887
return -ENOMEM;
28882888

0 commit comments

Comments
 (0)