Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: storage: return on error to avoid a null pointer dereference

When us->extra is null the driver is not initialized, however, a
later call to osd200_scsi_to_ata is made that dereferences
us->extra, causing a null pointer dereference. The code
currently detects and reports that the driver is not initialized;
add a return to avoid the subsequent dereference issue in this
check.

Thanks to Alan Stern for pointing out that srb->result needs setting
to DID_ERROR << 16

Detected by CoverityScan, CID#100308 ("Dereference after null check")

Signed-off-by: Colin Ian King <colin.king@canonical.com>
Cc: stable <stable@vger.kernel.org>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Colin Ian King and committed by
Greg Kroah-Hartman
446230f5 86be7f7b

+4 -1
+4 -1
drivers/usb/storage/isd200.c
··· 1529 1529 1530 1530 /* Make sure driver was initialized */ 1531 1531 1532 - if (us->extra == NULL) 1532 + if (us->extra == NULL) { 1533 1533 usb_stor_dbg(us, "ERROR Driver not initialized\n"); 1534 + srb->result = DID_ERROR << 16; 1535 + return; 1536 + } 1534 1537 1535 1538 scsi_set_resid(srb, 0); 1536 1539 /* scsi_bufflen might change in protocol translation to ata */