Skip to contentSkip to conversation

sd: fix uninitialized variable access in error handling

PATCH In review Arnd Bergmann 4 participants 4 messages Oct 21, 2016 – Oct 24, 2016 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sd: fix uninitialized variable access in error handling

If sd_zbc_report_zones fails, the check for 'zone_blocks == 0' later in the function accesses uninitialized data:

drivers/scsi/sd_zbc.c: In function ‘sd_zbc_read_zones’:
drivers/scsi/sd_zbc.c:520:7: error: ‘zone_blocks’ may be used uninitialized in this function [-Werror=maybe-uninitialized]

This sets it to zero, which has the desired effect of leaving the sd_zbc_read_zones successfully with sdkp->zone_blocks = 0.

Fixes 89d947561077 ("sd: Implement support for ZBC devices")
---
 drivers/scsi/sd_zbc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/scsi/sd_zbc.c +3 -1
index 16d3fa62d8ac..d5b3bd915d9e 100644
@@ -455,8 +455,10 @@ static int sd_zbc_check_zone_size(struct scsi_disk *sdkp)
 
 	/* Do a report zone to get the same field */
 	ret = sd_zbc_report_zones(sdkp, buf, SD_ZBC_BUF_SIZE, 0);
-	if (ret)
+	if (ret) {
+		zone_blocks = 0;
 		goto out;
+	}
 
 	same = buf[4] & 0x0f;
 	if (same > 0) {
Signature · 1 line
2.9.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 32 lines · Arnd Bergmann

If sd_zbc_report_zones fails, the check for 'zone_blocks == 0' later in the function accesses uninitialized data:

drivers/scsi/sd_zbc.c: In function ‘sd_zbc_read_zones’:
drivers/scsi/sd_zbc.c:520:7: error: ‘zone_blocks’ may be used uninitialized in this function [-Werror=maybe-uninitialized]

This sets it to zero, which has the desired effect of leaving the sd_zbc_read_zones successfully with sdkp->zone_blocks = 0.

Fixes 89d947561077 ("sd: Implement support for ZBC devices")
---
 drivers/scsi/sd_zbc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/scsi/sd_zbc.c +3 -2
index 16d3fa62d8ac..d5b3bd915d9e 100644
@@ -455,8 +455,10 @@ static int sd_zbc_check_zone_size(struct scsi_disk *sdkp)
 
        /* Do a report zone to get the same field */
        ret = sd_zbc_report_zones(sdkp, buf, SD_ZBC_BUF_SIZE, 0);
-       if (ret)
+       if (ret) {
+               zone_blocks = 0;
                goto out;
+       }
 
        same = buf[4] & 0x0f;
        if (same > 0) {
--
Quoted 2 lines

2.9.0

Signature · 1 line
Shaun Tancheff
Reviewed-by on v1 1/1
#2 lore raw
In reply to Arnd Bergmann
Quoted 21 lines · Arnd Bergmann

If sd_zbc_report_zones fails, the check for 'zone_blocks == 0' later in the function accesses uninitialized data:

drivers/scsi/sd_zbc.c: In function ‘sd_zbc_read_zones’:
drivers/scsi/sd_zbc.c:520:7: error: ‘zone_blocks’ may be used uninitialized in this function [-Werror=maybe-uninitialized]

This sets it to zero, which has the desired effect of leaving the sd_zbc_read_zones successfully with sdkp->zone_blocks = 0.

Fixes 89d947561077 ("sd: Implement support for ZBC devices")
---
 drivers/scsi/sd_zbc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/scsi/sd_zbc.c +0 -0
index 16d3fa62d8ac..d5b3bd915d9e 100644
@@ -455,8 +455,10 @@ static int sd_zbc_check_zone_size(struct scsi_disk *sdkp)
 

drivers/scsi/sd_zbc.c static int sd_zbc_check_zone_size(struct scsi_disk *sdkp) · line 464

Quoted 10 lines
drivers/scsi/sd_zbc.c +3 -1
 	/* Do a report zone to get the same field */
 	ret = sd_zbc_report_zones(sdkp, buf, SD_ZBC_BUF_SIZE, 0);
-	if (ret)
+	if (ret) {
+		zone_blocks = 0;
 		goto out;
+	}
 
 	same = buf[4] & 0x0f;
 	if (same > 0) {
Signature · 8 lines
Damien Le Moal, Ph.D.
Sr. Manager, System Software Research Group,
Western Digital Corporation
[email protected]
(+81) 0466-98-3593 (ext. 513593)
1 kirihara-cho, Fujisawa,
Kanagawa, 252-0888 Japan
www.wdc.com, www.hgst.com
Reviewed-by on v1 1/1
#3 lore raw
In reply to Arnd Bergmann
Quoted 22 lines · Arnd Bergmann

If sd_zbc_report_zones fails, the check for 'zone_blocks == 0' later in the function accesses uninitialized data:

drivers/scsi/sd_zbc.c: In function ‘sd_zbc_read_zones’:
drivers/scsi/sd_zbc.c:520:7: error: ‘zone_blocks’ may be used uninitialized in this function [-Werror=maybe-uninitialized]

This sets it to zero, which has the desired effect of leaving the sd_zbc_read_zones successfully with sdkp->zone_blocks = 0.

Fixes 89d947561077 ("sd: Implement support for ZBC devices")
---
 drivers/scsi/sd_zbc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/scsi/sd_zbc.c +0 -0
index 16d3fa62d8ac..d5b3bd915d9e 100644
@@ -455,8 +455,10 @@ static int sd_zbc_check_zone_size(struct scsi_disk *sdkp)
 

drivers/scsi/sd_zbc.c static int sd_zbc_check_zone_size(struct scsi_disk *sdkp) · line 464

Quoted 10 lines
drivers/scsi/sd_zbc.c +3 -1
 	/* Do a report zone to get the same field */
 	ret = sd_zbc_report_zones(sdkp, buf, SD_ZBC_BUF_SIZE, 0);
-	if (ret)
+	if (ret) {
+		zone_blocks = 0;
 		goto out;
+	}
 
 	same = buf[4] & 0x0f;
 	if (same > 0) {

Cheers,

Hannes

Signature · 5 lines
Dr. Hannes Reinecke		   Teamlead Storage & Networking
[email protected]			               +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)