linux/drivers/usb/storage
Lukas Bulwahn 6a6516c024 USB: storage: avoid use of uninitialized values in error path
When usb_stor_bulk_transfer_sglist() returns with USB_STOR_XFER_ERROR, it
returns without writing to its parameter *act_len.

Further, the two callers of usb_stor_bulk_transfer_sglist():

    usb_stor_bulk_srb() and
    usb_stor_bulk_transfer_sg(),

use the passed variable partial without checking the return value. Hence,
the uninitialized value of partial is then used in the further execution
of those two functions.

Clang-analyzer detects this potential control and data flow and warns:

  drivers/usb/storage/transport.c:469:40:
    warning: The right operand of '-' is a garbage value
    [clang-analyzer-core.UndefinedBinaryOperatorResult]
          scsi_set_resid(srb, scsi_bufflen(srb) - partial);
                                                ^

  drivers/usb/storage/transport.c:495:15:
    warning: Assigned value is garbage or undefined
    [clang-analyzer-core.uninitialized.Assign]
                  length_left -= partial;
                              ^

When a transfer error occurs, the *act_len value is probably ignored by the
higher layers. But it won't hurt to set it to a valid number, just in case.

For the two early-return paths in usb_stor_bulk_transfer_sglist(), the
amount of data transferred is 0.  So if act_len is not NULL, set *act_len
to 0 in those paths. That makes clang-analyzer happy.

Proposal was discussed in this mail thread:
	https://lore.kernel.org/linux-usb/alpine.DEB.2.21.2011112146110.13119@felia/

Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Lukas Bulwahn <lukas.bulwahn@gmail.com>
Link: https://lore.kernel.org/r/20201112191255.13372-1-lukas.bulwahn@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-11-13 15:21:53 +01:00
..
alauda.c usb: storage: alauda: Remove set but unchecked variable 2020-07-09 16:46:59 +02:00
cypress_atacb.c usb-storage: export symbols in USB_STORAGE namespace 2019-09-10 10:30:57 +02:00
datafab.c usb-storage: export symbols in USB_STORAGE namespace 2019-09-10 10:30:57 +02:00
debug.c USB: storage: remove invalid URL from drivers 2018-01-23 10:22:34 +01:00
debug.h USB: Storage: Use the correct style for SPDX License Identifier 2020-04-23 15:28:14 +02:00
ene_ub6250.c scsi: core: Fix scsi_get/set_resid() interface 2019-11-08 21:34:49 -05:00
freecom.c usb: storage: freecom: remove unneeded break 2020-10-28 12:22:50 +01:00
initializers.c USB: storage: remove invalid URL from drivers 2018-01-23 10:22:34 +01:00
initializers.h USB: Storage: Use the correct style for SPDX License Identifier 2020-04-23 15:28:14 +02:00
isd200.c USB: storage: isd200: fix spelling mistake "removeable" -> "removable" 2020-08-18 12:12:54 +02:00
jumpshot.c usb-storage: export symbols in USB_STORAGE namespace 2019-09-10 10:30:57 +02:00
karma.c usb-storage: export symbols in USB_STORAGE namespace 2019-09-10 10:30:57 +02:00
Kconfig USB: storage: replace HTTP links with HTTPS ones 2020-07-09 18:06:12 +02:00
Makefile usb-storage: export symbols in USB_STORAGE namespace 2019-09-10 10:30:57 +02:00
onetouch.c usb-storage: export symbols in USB_STORAGE namespace 2019-09-10 10:30:57 +02:00
option_ms.c USB: storage: Remove redundant license text 2017-11-04 11:55:38 +01:00
option_ms.h
protocol.c USB: storage: remove invalid URL from drivers 2018-01-23 10:22:34 +01:00
protocol.h USB: Storage: Use the correct style for SPDX License Identifier 2020-04-23 15:28:14 +02:00
realtek_cr.c usb-storage: export symbols in USB_STORAGE namespace 2019-09-10 10:30:57 +02:00
scsiglue.c usb-storage: fix sdev->host->dma_dev 2020-09-04 17:00:38 +02:00
scsiglue.h USB: Storage: Use the correct style for SPDX License Identifier 2020-04-23 15:28:14 +02:00
sddr09.c usb-storage: export symbols in USB_STORAGE namespace 2019-09-10 10:30:57 +02:00
sddr55.c treewide: Use fallthrough pseudo-keyword 2020-08-23 17:36:59 -05:00
shuttle_usbat.c usb-storage: export symbols in USB_STORAGE namespace 2019-09-10 10:30:57 +02:00
sierra_ms.c sierra-ms: do not call scsi_get_host_dev() 2020-05-13 14:20:00 +02:00
sierra_ms.h
transport.c USB: storage: avoid use of uninitialized values in error path 2020-11-13 15:21:53 +01:00
transport.h USB: Storage: Use the correct style for SPDX License Identifier 2020-04-23 15:28:14 +02:00
uas-detect.h USB: storage: fix wording in error message 2020-06-19 08:58:51 +02:00
uas.c USB: UAS: use macro for reporting results 2020-09-16 12:43:35 +02:00
unusual_alauda.h USB: Storage: Use the correct style for SPDX License Identifier 2020-04-23 15:28:14 +02:00
unusual_cypress.h USB: Storage: Use the correct style for SPDX License Identifier 2020-04-23 15:28:14 +02:00
unusual_datafab.h USB: Storage: Use the correct style for SPDX License Identifier 2020-04-23 15:28:14 +02:00
unusual_devs.h USB: Ignore UAS for JMicron JMS567 ATA/ATAPI Bridge 2020-08-27 09:26:00 +02:00
unusual_ene_ub6250.h USB: Storage: Use the correct style for SPDX License Identifier 2020-04-23 15:28:14 +02:00
unusual_freecom.h USB: Storage: Use the correct style for SPDX License Identifier 2020-04-23 15:28:14 +02:00
unusual_isd200.h USB: Storage: Use the correct style for SPDX License Identifier 2020-04-23 15:28:14 +02:00
unusual_jumpshot.h USB: Storage: Use the correct style for SPDX License Identifier 2020-04-23 15:28:14 +02:00
unusual_karma.h USB: Storage: Use the correct style for SPDX License Identifier 2020-04-23 15:28:14 +02:00
unusual_onetouch.h USB: Storage: Use the correct style for SPDX License Identifier 2020-04-23 15:28:14 +02:00
unusual_realtek.h USB: Storage: Use the correct style for SPDX License Identifier 2020-04-23 15:28:14 +02:00
unusual_sddr09.h USB: Storage: Use the correct style for SPDX License Identifier 2020-04-23 15:28:14 +02:00
unusual_sddr55.h USB: Storage: Use the correct style for SPDX License Identifier 2020-04-23 15:28:14 +02:00
unusual_uas.h usb: storage: Add unusual_uas entry for Sony PSZ drives 2020-08-28 09:23:16 +02:00
unusual_usbat.h USB: Storage: Use the correct style for SPDX License Identifier 2020-04-23 15:28:14 +02:00
usb.c usb-storage: fix sdev->host->dma_dev 2020-09-04 17:00:38 +02:00
usb.h USB: Storage: Use the correct style for SPDX License Identifier 2020-04-23 15:28:14 +02:00
usual-tables.c usb-storage: Use const to reduce object data size 2020-02-19 11:08:52 +01:00