Skip to content

Commit 6fc2586

Browse files
committed
Merge tag 'scsi-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi
Pull SCSI fix from James Bottomley: "One fix for an information leak caused by copying a buffer to userspace without checking for error first in the sr driver" * tag 'scsi-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi: scsi: sr: Do not leak information in ioctl
2 parents b51bd23 + faad6ce commit 6fc2586

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

drivers/scsi/sr_ioctl.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static int sr_read_tochdr(struct cdrom_device_info *cdi,
4141
int result;
4242
unsigned char *buffer;
4343

44-
buffer = kmalloc(32, GFP_KERNEL);
44+
buffer = kzalloc(32, GFP_KERNEL);
4545
if (!buffer)
4646
return -ENOMEM;
4747

@@ -55,10 +55,13 @@ static int sr_read_tochdr(struct cdrom_device_info *cdi,
5555
cgc.data_direction = DMA_FROM_DEVICE;
5656

5757
result = sr_do_ioctl(cd, &cgc);
58+
if (result)
59+
goto err;
5860

5961
tochdr->cdth_trk0 = buffer[2];
6062
tochdr->cdth_trk1 = buffer[3];
6163

64+
err:
6265
kfree(buffer);
6366
return result;
6467
}
@@ -71,7 +74,7 @@ static int sr_read_tocentry(struct cdrom_device_info *cdi,
7174
int result;
7275
unsigned char *buffer;
7376

74-
buffer = kmalloc(32, GFP_KERNEL);
77+
buffer = kzalloc(32, GFP_KERNEL);
7578
if (!buffer)
7679
return -ENOMEM;
7780

@@ -86,6 +89,8 @@ static int sr_read_tocentry(struct cdrom_device_info *cdi,
8689
cgc.data_direction = DMA_FROM_DEVICE;
8790

8891
result = sr_do_ioctl(cd, &cgc);
92+
if (result)
93+
goto err;
8994

9095
tocentry->cdte_ctrl = buffer[5] & 0xf;
9196
tocentry->cdte_adr = buffer[5] >> 4;
@@ -98,6 +103,7 @@ static int sr_read_tocentry(struct cdrom_device_info *cdi,
98103
tocentry->cdte_addr.lba = (((((buffer[8] << 8) + buffer[9]) << 8)
99104
+ buffer[10]) << 8) + buffer[11];
100105

106+
err:
101107
kfree(buffer);
102108
return result;
103109
}
@@ -384,7 +390,7 @@ int sr_get_mcn(struct cdrom_device_info *cdi, struct cdrom_mcn *mcn)
384390
{
385391
Scsi_CD *cd = cdi->handle;
386392
struct packet_command cgc;
387-
char *buffer = kmalloc(32, GFP_KERNEL);
393+
char *buffer = kzalloc(32, GFP_KERNEL);
388394
int result;
389395

390396
if (!buffer)
@@ -400,10 +406,13 @@ int sr_get_mcn(struct cdrom_device_info *cdi, struct cdrom_mcn *mcn)
400406
cgc.data_direction = DMA_FROM_DEVICE;
401407
cgc.timeout = IOCTL_TIMEOUT;
402408
result = sr_do_ioctl(cd, &cgc);
409+
if (result)
410+
goto err;
403411

404412
memcpy(mcn->medium_catalog_number, buffer + 9, 13);
405413
mcn->medium_catalog_number[13] = 0;
406414

415+
err:
407416
kfree(buffer);
408417
return result;
409418
}

0 commit comments

Comments
 (0)