Skip to contentSkip to conversation

scsi: stex: properly zero out the passthrough command structure

PATCH Superseded Greg Kroah-Hartman 3 participants 5 messages Sep 8, 2022 – Sep 26, 2022 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: stex: properly zero out the passthrough command structure

The passthrough structure is declared off of the stack, so it needs to be zeroed out before copied back to userspace to prevent any unintentional data leakage.

Cc stable <[email protected]>
Cc "James E.J. Bottomley" <[email protected]>
Cc "Martin K. Petersen" <[email protected]>
---
 drivers/scsi/stex.c | 1 +
 1 file changed, 1 insertion(+)
drivers/scsi/stex.c +1 -0
index e6420f2127ce..fc5880a35723 100644
@@ -668,6 +668,7 @@ static int stex_queuecommand_lck(struct scsi_cmnd *cmd)
 			struct st_drvver ver;
 			size_t cp_len = sizeof(ver);
 
+			memset(&ver, 0x00, sizeof(ver));
 			ver.major = ST_VER_MAJOR;
 			ver.minor = ST_VER_MINOR;
 			ver.oem = ST_OEM;
Signature · 1 line
2.37.3
#1 lore raw

PATCH v2 1/1 scsi: stex: properly zero out the passthrough command structure

From: Linus Torvalds <[email protected]>

The passthrough structure is declared off of the stack, so it needs to be set to zero before copied back to userspace to prevent any unintentional data leakage. Switch things to be statically allocated which will fill the unused fields with 0 automatically.

Cc stable <[email protected]>
Cc "James E.J. Bottomley" <[email protected]>
Cc "Martin K. Petersen" <[email protected]>
Cc Dan Carpenter <[email protected]>

---
v2: Linus's updated version that moves the initialization to be
statically defined and changes the function prototype and structure to be const.

 drivers/scsi/stex.c      | 17 +++++++++--------
 include/scsi/scsi_cmnd.h |  2 +-
 2 files changed, 10 insertions(+), 9 deletions(-)
drivers/scsi/stex.c +9 -8
index e6420f2127ce..8def242675ef 100644
@@ -665,16 +665,17 @@ static int stex_queuecommand_lck(struct scsi_cmnd *cmd)
 		return 0;
 	case PASSTHRU_CMD:
 		if (cmd->cmnd[1] == PASSTHRU_GET_DRVVER) {
-			struct st_drvver ver;
+			const struct st_drvver ver = {
+				.major = ST_VER_MAJOR,
+				.minor = ST_VER_MINOR,
+				.oem = ST_OEM,
+				.build = ST_BUILD_VER,
+				.signature[0] = PASSTHRU_SIGNATURE,
+				.console_id = host->max_id - 1,
+				.host_no = hba->host->host_no,
+			};
 			size_t cp_len = sizeof(ver);
 
-			ver.major = ST_VER_MAJOR;
-			ver.minor = ST_VER_MINOR;
-			ver.oem = ST_OEM;
-			ver.build = ST_BUILD_VER;
-			ver.signature[0] = PASSTHRU_SIGNATURE;
-			ver.console_id = host->max_id - 1;
-			ver.host_no = hba->host->host_no;
 			cp_len = scsi_sg_copy_from_buffer(cmd, &ver, cp_len);
 			if (sizeof(ver) == cp_len)
 				cmd->result = DID_OK << 16;
include/scsi/scsi_cmnd.h +1 -1
index bac55decf900..7d3622db38ed 100644
@@ -201,7 +201,7 @@ static inline unsigned int scsi_get_resid(struct scsi_cmnd *cmd)
 	for_each_sg(scsi_sglist(cmd), sg, nseg, __i)
 
 static inline int scsi_sg_copy_from_buffer(struct scsi_cmnd *cmd,
-					   void *buf, int buflen)
+					   const void *buf, int buflen)
 {
 	return sg_copy_from_buffer(scsi_sglist(cmd), scsi_sg_count(cmd),
 				   buf, buflen);
Signature · 1 line
2.37.3
#2 lore raw
Quoted 57 lines · Greg Kroah-Hartman

From: Linus Torvalds <[email protected]>

The passthrough structure is declared off of the stack, so it needs to be set to zero before copied back to userspace to prevent any unintentional data leakage. Switch things to be statically allocated which will fill the unused fields with 0 automatically.

Cc stable <[email protected]>
Cc "James E.J. Bottomley" <[email protected]>
Cc "Martin K. Petersen" <[email protected]>
Cc Dan Carpenter <[email protected]>

---
v2: Linus's updated version that moves the initialization to be
statically defined and changes the function prototype and structure to be const.

  drivers/scsi/stex.c      | 17 +++++++++--------
  include/scsi/scsi_cmnd.h |  2 +-
  2 files changed, 10 insertions(+), 9 deletions(-)
drivers/scsi/stex.c +9 -8
index e6420f2127ce..8def242675ef 100644
@@ -665,16 +665,17 @@ static int stex_queuecommand_lck(struct scsi_cmnd *cmd)
  		return 0;
  	case PASSTHRU_CMD:
  		if (cmd->cmnd[1] == PASSTHRU_GET_DRVVER) {
-			struct st_drvver ver;
+			const struct st_drvver ver = {
+				.major = ST_VER_MAJOR,
+				.minor = ST_VER_MINOR,
+				.oem = ST_OEM,
+				.build = ST_BUILD_VER,
+				.signature[0] = PASSTHRU_SIGNATURE,
+				.console_id = host->max_id - 1,
+				.host_no = hba->host->host_no,
+			};
  			size_t cp_len = sizeof(ver);
 
-			ver.major = ST_VER_MAJOR;
-			ver.minor = ST_VER_MINOR;
-			ver.oem = ST_OEM;
-			ver.build = ST_BUILD_VER;
-			ver.signature[0] = PASSTHRU_SIGNATURE;
-			ver.console_id = host->max_id - 1;
-			ver.host_no = hba->host->host_no;
  			cp_len = scsi_sg_copy_from_buffer(cmd, &ver, cp_len);
  			if (sizeof(ver) == cp_len)
  				cmd->result = DID_OK << 16;
include/scsi/scsi_cmnd.h +0 -0
index bac55decf900..7d3622db38ed 100644

include/scsi/scsi_cmnd.h static inline unsigned int scsi_get_resid(struct scsi_cmnd *cmd) · line 207

Quoted 8 lines
include/scsi/scsi_cmnd.h +1 -1
@@ -201,7 +201,7 @@ static inline unsigned int scsi_get_resid(struct scsi_cmnd *cmd)
  	for_each_sg(scsi_sglist(cmd), sg, nseg, __i)
 
  static inline int scsi_sg_copy_from_buffer(struct scsi_cmnd *cmd,
-					   void *buf, int buflen)
+					   const void *buf, int buflen)
  {
  	return sg_copy_from_buffer(scsi_sglist(cmd), scsi_sg_count(cmd),
  				   buf, buflen);

Please split this patch into one patch for the SCSI core and another patch for the STEX driver.

Thanks,

Bart.

#3 lore raw
Quoted 70 lines · Bart Van Assche
Quoted 57 lines · Greg Kroah-Hartman

From: Linus Torvalds <[email protected]>

The passthrough structure is declared off of the stack, so it needs to be set to zero before copied back to userspace to prevent any unintentional data leakage.  Switch things to be statically allocated which will fill the unused fields with 0 automatically.

Cc stable <[email protected]>
Cc "James E.J. Bottomley" <[email protected]>
Cc "Martin K. Petersen" <[email protected]>
Cc Dan Carpenter <[email protected]>

---
  v2: Linus's updated version that moves the initialization to be statically defined and changes the function prototype and structure to be const.

  drivers/scsi/stex.c      | 17 +++++++++--------
  include/scsi/scsi_cmnd.h |  2 +-

  2 files changed, 10 insertions(+), 9 deletions(-)
drivers/scsi/stex.c +0 -0
index e6420f2127ce..8def242675ef 100644
@@ -665,16 +665,17 @@ static int stex_queuecommand_lck(struct 
 scsi_cmnd *cmd)
           return 0;

      case PASSTHRU_CMD:
          if (cmd->cmnd[1] == PASSTHRU_GET_DRVVER) {
-            struct st_drvver ver;
+            const struct st_drvver ver = {
+                .major = ST_VER_MAJOR,
+                .minor = ST_VER_MINOR,
+                .oem = ST_OEM,
+                .build = ST_BUILD_VER,
+                .signature[0] = PASSTHRU_SIGNATURE,
+                .console_id = host->max_id - 1,
+                .host_no = hba->host->host_no,
+            };
              size_t cp_len = sizeof(ver);
-            ver.major = ST_VER_MAJOR;
-            ver.minor = ST_VER_MINOR;
-            ver.oem = ST_OEM;
-            ver.build = ST_BUILD_VER;
-            ver.signature[0] = PASSTHRU_SIGNATURE;
-            ver.console_id = host->max_id - 1;
-            ver.host_no = hba->host->host_no;
              cp_len = scsi_sg_copy_from_buffer(cmd, &ver, cp_len); if (sizeof(ver) == cp_len)
                  cmd->result = DID_OK << 16;

include/scsi/scsi_cmnd.h +0 -0
index bac55decf900..7d3622db38ed 100644

include/scsi/scsi_cmnd.h static inline unsigned int scsi_get_resid(struct · line 207

Quoted 8 lines
include/scsi/scsi_cmnd.h +1 -1
@@ -201,7 +201,7 @@ static inline unsigned int scsi_get_resid(struct 
 scsi_cmnd *cmd)
       for_each_sg(scsi_sglist(cmd), sg, nseg, __i)
   static inline int scsi_sg_copy_from_buffer(struct scsi_cmnd *cmd,
-                       void *buf, int buflen)
+                       const void *buf, int buflen)
   {
       return sg_copy_from_buffer(scsi_sglist(cmd), scsi_sg_count(cmd),
                      buf, buflen);

Please split this patch into one patch for the SCSI core and another patch for the STEX driver.

Quoted 3 lines

Thanks,

Bart.

Ping? Is this patch going to stand as is, or are we going to get a V3 that addresses Bart's request?

I'd like to know so I can backport the proper patch(es) to address this issue.

Signature · 1 line
Lee Duncan
#4 lore raw
Quoted 71 lines · Lee Duncan
Quoted 70 lines · Bart Van Assche
Quoted 57 lines · Greg Kroah-Hartman

From: Linus Torvalds <[email protected]>

The passthrough structure is declared off of the stack, so it needs to be set to zero before copied back to userspace to prevent any unintentional data leakage.  Switch things to be statically allocated which will fill the unused fields with 0 automatically.

Cc stable <[email protected]>
Cc "James E.J. Bottomley" <[email protected]>
Cc "Martin K. Petersen" <[email protected]>
Cc Dan Carpenter <[email protected]>

---
  v2: Linus's updated version that moves the initialization to be statically defined and changes the function prototype and structure to be const.

  drivers/scsi/stex.c      | 17 +++++++++--------
  include/scsi/scsi_cmnd.h |  2 +-

  2 files changed, 10 insertions(+), 9 deletions(-)
drivers/scsi/stex.c +0 -0
index e6420f2127ce..8def242675ef 100644
@@ -665,16 +665,17 @@ static int stex_queuecommand_lck(struct
 scsi_cmnd *cmd)
           return 0;

      case PASSTHRU_CMD:
          if (cmd->cmnd[1] == PASSTHRU_GET_DRVVER) {
-            struct st_drvver ver;
+            const struct st_drvver ver = {
+                .major = ST_VER_MAJOR,
+                .minor = ST_VER_MINOR,
+                .oem = ST_OEM,
+                .build = ST_BUILD_VER,
+                .signature[0] = PASSTHRU_SIGNATURE,
+                .console_id = host->max_id - 1,
+                .host_no = hba->host->host_no,
+            };
              size_t cp_len = sizeof(ver);
-            ver.major = ST_VER_MAJOR;
-            ver.minor = ST_VER_MINOR;
-            ver.oem = ST_OEM;
-            ver.build = ST_BUILD_VER;
-            ver.signature[0] = PASSTHRU_SIGNATURE;
-            ver.console_id = host->max_id - 1;
-            ver.host_no = hba->host->host_no;
              cp_len = scsi_sg_copy_from_buffer(cmd, &ver, cp_len); if (sizeof(ver) == cp_len)
                  cmd->result = DID_OK << 16;

include/scsi/scsi_cmnd.h +0 -0
index bac55decf900..7d3622db38ed 100644

include/scsi/scsi_cmnd.h static inline unsigned int scsi_get_resid(struct · line 207

Quoted 8 lines
include/scsi/scsi_cmnd.h +1 -1
@@ -201,7 +201,7 @@ static inline unsigned int scsi_get_resid(struct
 scsi_cmnd *cmd)
       for_each_sg(scsi_sglist(cmd), sg, nseg, __i)
   static inline int scsi_sg_copy_from_buffer(struct scsi_cmnd *cmd,
-                       void *buf, int buflen)
+                       const void *buf, int buflen)
   {
       return sg_copy_from_buffer(scsi_sglist(cmd), scsi_sg_count(cmd),
                      buf, buflen);

Please split this patch into one patch for the SCSI core and another patch for the STEX driver.

Quoted 6 lines
Quoted 3 lines

Thanks,

Bart.

Ping? Is this patch going to stand as is, or are we going to get a V3 that addresses Bart's request?

I'll try to do a v3 when I get a chance later this week.

thanks,

greg k-h