Skip to contentSkip to conversation

scsi: core: set result when the command cannot be dispatched

PATCH Applied Jaesoo Lee 4 participants 4 messages Apr 10, 2019 – Apr 16, 2019 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

Jaesoo Lee

author
#1 lore raw

PATCH v2 1/1 scsi: core: set result when the command cannot be dispatched

In reply to a message not in the archive

When SCSI blk-mq is enabled, there is a bug in handling errors in scsi_queue_rq. Specifically, the bug is not setting result field of scsi_request correctly when the dispatch of the command has been failed. Since the upper layer code including the sg_io ioctl expects to receive any error status from result field of scsi_request, the error is silently ignored and this could cause data corruptions for some applications.

---
 drivers/scsi/scsi_lib.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/scsi/scsi_lib.c +0 -0
index 2018967..dc2550c 100644
@@ -1699,8 +1699,12 @@ static blk_status_t scsi_queue_rq(struct

blk_mq_hw_ctx *hctx,

                        ret = BLK_STS_DEV_RESOURCE;
                break;
        default:
+               if (unlikely(!scsi_device_online(sdev)))
+                       scsi_req(req)->result = DID_NO_CONNECT << 16;
+               else
+                       scsi_req(req)->result = DID_ERROR << 16;
                /*

- * Make sure to release all allocated ressources when
+ * Make sure to release all allocated resources when
* we hit an error, as we will never see this command
* again.
*/
--
2.7.4

Reviewed-by on v2 1/1
#2 lore raw
Quoted 31 lines · Jaesoo Lee

When SCSI blk-mq is enabled, there is a bug in handling errors in scsi_queue_rq. Specifically, the bug is not setting result field of scsi_request correctly when the dispatch of the command has been failed. Since the upper layer code including the sg_io ioctl expects to receive any error status from result field of scsi_request, the error is silently ignored and this could cause data corruptions for some applications.

---
  drivers/scsi/scsi_lib.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
drivers/scsi/scsi_lib.c +5 -1
index 2018967..dc2550c 100644
@@ -1699,8 +1699,12 @@ static blk_status_t scsi_queue_rq(struct
 blk_mq_hw_ctx *hctx,
                         ret = BLK_STS_DEV_RESOURCE;
                 break;
         default:
+               if (unlikely(!scsi_device_online(sdev)))
+                       scsi_req(req)->result = DID_NO_CONNECT << 16;
+               else
+                       scsi_req(req)->result = DID_ERROR << 16;
                 /*
-                * Make sure to release all allocated ressources when
+                * Make sure to release all allocated resources when
                  * we hit an error, as we will never see this command
                  * again.
                  */
Quoted 3 lines

--
2.7.4

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: Felix Imendörffer, Mary Higgins, Sri Rasiah
HRB 21284 (AG Nürnberg)
Reviewed-by on v2 1/1
#3 lore raw
In reply to Jaesoo Lee
Quoted 18 lines · Jaesoo Lee

When SCSI blk-mq is enabled, there is a bug in handling errors in scsi_queue_rq. Specifically, the bug is not setting result field of scsi_request correctly when the dispatch of the command has been failed. Since the upper layer code including the sg_io ioctl expects to receive any error status from result field of scsi_request, the error is silently ignored and this could cause data corruptions for some applications.

drivers/scsi/scsi_lib.c |6 +-+-+-+-+--

1 file changed, 5 insertions(+-), 1 deletion(-)
drivers/scsi/scsi_lib.c +1 -1
index 2018967..dc2550c 100644
--- a/drivers/scsi/scsi_lib.c
+-+-+- b/drivers/scsi/scsi_lib.c

@@-1699,8 +-1699,12 @@static blk_status_t scsi_queue_rq(struct blk_mq_hw_ctx *hctx,
ret =BLK_STS_DEV_RESOURCE;> break;> default:

Quoted 7 lines
+-               if (unlikely(!scsi_device_online(sdev)))
+-                       scsi_req(req)->result =DID_NO_CONNECT <<16;>+-               else
+-                       scsi_req(req)->result =DID_ERROR <<16;>                /*>-                *Make sure to release all allocated ressources when
+-                *Make sure to release all allocated resources when
                *we hit an error, as we will never see this command
                *again.
                */

Should "Fixes:"and "Cc: stable"tags be added to this patch?

Anyway:

#4 lore raw
In reply to Jaesoo Lee

Jaesoo,

Quoted 7 lines

When SCSI blk-mq is enabled, there is a bug in handling errors in scsi_queue_rq. Specifically, the bug is not setting result field of scsi_request correctly when the dispatch of the command has been failed. Since the upper layer code including the sg_io ioctl expects to receive any error status from result field of scsi_request, the error is silently ignored and this could cause data corruptions for some applications.

Applied to 5.1/scsi-fixes, thank you!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering