Skip to contentSkip to conversation

scsi: zero per-cmd driver data for each MQ I/O

PATCH Superseded Long Li 5 participants 5 messages May 10, 2017 – May 18, 2017 SCSI

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Long Li

author
#0 lore raw

PATCH 1/1 scsi: zero per-cmd driver data for each MQ I/O

From: Long Li <[email protected]>

Lower layer driver may not initialize private data before use. Zero them out to prevent use of stale data.

---
 drivers/scsi/scsi_lib.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/scsi_lib.c +1 -1
index 19125d7..a821593 100644
@@ -1850,7 +1850,7 @@ static int scsi_mq_prep_fn(struct request *req)
 
 	/* zero out the cmd, except for the embedded scsi_request */
 	memset((char *)cmd + sizeof(cmd->req), 0,
-		sizeof(*cmd) - sizeof(cmd->req));
+		sizeof(*cmd) - sizeof(cmd->req) + shost->hostt->cmd_size);
 
 	req->special = cmd;
 
Signature · 1 line
2.7.4
#1 lore raw
Quoted 9 lines

-----Original Message-----
From: Long Li [mailto:[email protected]]
Sent: Wednesday, May 10, 2017 2:07 PM
To: James E.J. Bottomley <[email protected]>; Martin K. Petersen <[email protected]>; [email protected]; linux- [email protected]
Cc: Long Li <[email protected]>
Subject: [PATCH] scsi: zero per-cmd driver data for each MQ I/O

Quoted 6 lines

From: Long Li <[email protected]>

Lower layer driver may not initialize private data before use. Zero them out to prevent use of stale data.

Can someone help review this patch?

Quoted 20 lines
---
 drivers/scsi/scsi_lib.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/scsi_lib.c index renamed from drivers/scsi/scsi_lib.c +0 -0

19125d7..a821593 100644

drivers/scsi/scsi_lib.c +2 -2
@@ -1850,7 +1850,7 @@ static int scsi_mq_prep_fn(struct request *req)
 
        /* zero out the cmd, except for the embedded scsi_request */
        memset((char *)cmd + sizeof(cmd->req), 0,
-               sizeof(*cmd) - sizeof(cmd->req));
+               sizeof(*cmd) - sizeof(cmd->req) +
+ shost->hostt->cmd_size);
 
        req->special = cmd;
 
--

2.7.4

#3 lore raw
In reply to Long Li
Quoted 15 lines · Long Li

From: Long Li <[email protected]>

Lower layer driver may not initialize private data before use. Zero them out to prevent use of stale data.

---
 drivers/scsi/scsi_lib.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/scsi_lib.c +0 -0
index 19125d7..a821593 100644

drivers/scsi/scsi_lib.c static int scsi_mq_prep_fn(struct request *req) · line 1855

Quoted 7 lines
drivers/scsi/scsi_lib.c +1 -1
@@ -1850,7 +1850,7 @@ static int scsi_mq_prep_fn(struct request *req)
 
 	/* zero out the cmd, except for the embedded scsi_request */
 	memset((char *)cmd + sizeof(cmd->req), 0,
-		sizeof(*cmd) - sizeof(cmd->req));
+		sizeof(*cmd) - sizeof(cmd->req) + shost->hostt->cmd_size);
 
 	req->special = cmd;

Hello Long,

Sorry but this patch looks wrong to me. Since scsi_mq_prep_fn() is called after scsi_req_init(), erasing struct scsi_request from scsi_mq_prep_fn() will erase the values that were set by scsi_req_init(). That includes information like the pointer to the SCSI CDB and the CDB itself. See e.g. scsi_execute().

Did you come up with this patch after source reading or did you come up with this patch while chasing a bug?

Thanks,

Bart.

Reviewed-by
#2 lore raw
In reply to Long Li
Quoted 22 lines

-----Original Message-----
From: Long Li
Sent: Monday, May 15, 2017 3:48 PM
To: Long Li <[email protected]>; James E.J. Bottomley <[email protected]>; Martin K. Petersen <[email protected]>; [email protected]; linux- [email protected]
Cc: KY Srinivasan <[email protected]>; Stephen Hemminger <[email protected]>
Subject: RE: [PATCH] scsi: zero per-cmd driver data for each MQ I/O

Quoted 9 lines

-----Original Message-----
From: Long Li [mailto:[email protected]]
Sent: Wednesday, May 10, 2017 2:07 PM
To: James E.J. Bottomley <[email protected]>; Martin K. Petersen <[email protected]>; [email protected]; linux- [email protected]
Cc: Long Li <[email protected]>
Subject: [PATCH] scsi: zero per-cmd driver data for each MQ I/O

Quoted 8 lines
Quoted 6 lines

From: Long Li <[email protected]>

Lower layer driver may not initialize private data before use. Zero them out to prevent use of stale data.

Can someone help review this patch?

Quoted 21 lines
Quoted 21 lines
---
 drivers/scsi/scsi_lib.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/scsi_lib.c index renamed from drivers/scsi/scsi_lib.c +0 -0

19125d7..a821593 100644

drivers/scsi/scsi_lib.c +2 -2
@@ -1850,7 +1850,7 @@ static int scsi_mq_prep_fn(struct request *req)
 
        /* zero out the cmd, except for the embedded scsi_request */
        memset((char *)cmd + sizeof(cmd->req), 0,
-               sizeof(*cmd) - sizeof(cmd->req));
+               sizeof(*cmd) - sizeof(cmd->req) +
+ shost->hostt->cmd_size);
 
        req->special = cmd;
 
--

2.7.4