Skip to content

Commit 014bcf4

Browse files
AlanSterngregkh
authored andcommitted
USB: usb-storage: Prevent divide-by-0 error in isd200_ata_command
The isd200 sub-driver in usb-storage uses the HEADS and SECTORS values in the ATA ID information to calculate cylinder and head values when creating a CDB for READ or WRITE commands. The calculation involves division and modulus operations, which will cause a crash if either of these values is 0. While this never happens with a genuine device, it could happen with a flawed or subversive emulation, as reported by the syzbot fuzzer. Protect against this possibility by refusing to bind to the device if either the ATA_ID_HEADS or ATA_ID_SECTORS value in the device's ID information is 0. This requires isd200_Initialization() to return a negative error code when initialization fails; currently it always returns 0 (even when there is an error). Signed-off-by: Alan Stern <stern@rowland.harvard.edu> Reported-and-tested-by: syzbot+28748250ab47a8f04100@syzkaller.appspotmail.com Link: https://lore.kernel.org/linux-usb/0000000000003eb868061245ba7f@google.com/ Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Reviewed-by: PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com> Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com> Link: https://lore.kernel.org/r/b1e605ea-333f-4ac0-9511-da04f411763e@rowland.harvard.edu Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 3c4a311 commit 014bcf4

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

drivers/usb/storage/isd200.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,7 @@ static void isd200_dump_driveid(struct us_data *us, u16 *id)
11051105
static int isd200_get_inquiry_data( struct us_data *us )
11061106
{
11071107
struct isd200_info *info = (struct isd200_info *)us->extra;
1108-
int retStatus = ISD200_GOOD;
1108+
int retStatus;
11091109
u16 *id = info->id;
11101110

11111111
usb_stor_dbg(us, "Entering isd200_get_inquiry_data\n");
@@ -1137,6 +1137,13 @@ static int isd200_get_inquiry_data( struct us_data *us )
11371137
isd200_fix_driveid(id);
11381138
isd200_dump_driveid(us, id);
11391139

1140+
/* Prevent division by 0 in isd200_scsi_to_ata() */
1141+
if (id[ATA_ID_HEADS] == 0 || id[ATA_ID_SECTORS] == 0) {
1142+
usb_stor_dbg(us, " Invalid ATA Identify data\n");
1143+
retStatus = ISD200_ERROR;
1144+
goto Done;
1145+
}
1146+
11401147
memset(&info->InquiryData, 0, sizeof(info->InquiryData));
11411148

11421149
/* Standard IDE interface only supports disks */
@@ -1202,6 +1209,7 @@ static int isd200_get_inquiry_data( struct us_data *us )
12021209
}
12031210
}
12041211

1212+
Done:
12051213
usb_stor_dbg(us, "Leaving isd200_get_inquiry_data %08X\n", retStatus);
12061214

12071215
return(retStatus);
@@ -1481,22 +1489,27 @@ static int isd200_init_info(struct us_data *us)
14811489

14821490
static int isd200_Initialization(struct us_data *us)
14831491
{
1492+
int rc = 0;
1493+
14841494
usb_stor_dbg(us, "ISD200 Initialization...\n");
14851495

14861496
/* Initialize ISD200 info struct */
14871497

1488-
if (isd200_init_info(us) == ISD200_ERROR) {
1498+
if (isd200_init_info(us) < 0) {
14891499
usb_stor_dbg(us, "ERROR Initializing ISD200 Info struct\n");
1500+
rc = -ENOMEM;
14901501
} else {
14911502
/* Get device specific data */
14921503

1493-
if (isd200_get_inquiry_data(us) != ISD200_GOOD)
1504+
if (isd200_get_inquiry_data(us) != ISD200_GOOD) {
14941505
usb_stor_dbg(us, "ISD200 Initialization Failure\n");
1495-
else
1506+
rc = -EINVAL;
1507+
} else {
14961508
usb_stor_dbg(us, "ISD200 Initialization complete\n");
1509+
}
14971510
}
14981511

1499-
return 0;
1512+
return rc;
15001513
}
15011514

15021515

0 commit comments

Comments
 (0)