public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scsi: Let scsi_execute_cmd() mark args->sshdr as invalid
@ 2023-05-11 12:34 Juergen Gross
  2023-05-11 12:49 ` Bart Van Assche
                   ` (3 more replies)
  0 siblings, 4 replies; 28+ messages in thread
From: Juergen Gross @ 2023-05-11 12:34 UTC (permalink / raw)
  To: linux-kernel, linux-scsi
  Cc: Juergen Gross, James E.J. Bottomley, Martin K. Petersen, stable

Some callers of scsi_execute_cmd() (like e.g. sd_spinup_disk()) are
passing an uninitialized struct sshdr and don't look at the return
value of scsi_execute_cmd() before looking at the contents of that
struct.

This can result in false positives when looking for specific error
conditions.

In order to fix that let scsi_execute_cmd() zero sshdr->response_code,
resulting in scsi_sense_valid() returning false.

Cc: stable@vger.kernel.org
Fixes: 3949e2f04262 ("scsi: simplify scsi_execute_req_flags")
Signed-off-by: Juergen Gross <jgross@suse.com>
---
I'm not aware of any real error having happened due to this problem,
but I thought it should be fixed anyway.
I _think_ 3949e2f04262 was introducing the problem, but I'm not 100%
sure it is really the commit to be blamed.
---
 drivers/scsi/scsi_lib.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index b7c569a42aa4..923336620bff 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -209,11 +209,17 @@ int scsi_execute_cmd(struct scsi_device *sdev, const unsigned char *cmd,
 	struct scsi_cmnd *scmd;
 	int ret;
 
-	if (!args)
+	if (!args) {
 		args = &default_args;
-	else if (WARN_ON_ONCE(args->sense &&
-			      args->sense_len != SCSI_SENSE_BUFFERSIZE))
-		return -EINVAL;
+	} else {
+		/* Mark sense data to be invalid. */
+		if (args->sshdr)
+			args->sshdr->response_code = 0;
+
+		if (WARN_ON_ONCE(args->sense &&
+				 args->sense_len != SCSI_SENSE_BUFFERSIZE))
+			return -EINVAL;
+	}
 
 	req = scsi_alloc_request(sdev->request_queue, opf, args->req_flags);
 	if (IS_ERR(req))
-- 
2.35.3


^ permalink raw reply related	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2023-05-23 15:05 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-11 12:34 [PATCH] scsi: Let scsi_execute_cmd() mark args->sshdr as invalid Juergen Gross
2023-05-11 12:49 ` Bart Van Assche
2023-05-11 12:54   ` Juergen Gross
2023-05-11 13:10 ` Martin Wilck
2023-05-11 13:17   ` Juergen Gross
2023-05-11 13:23     ` Martin Wilck
2023-05-11 13:32       ` Juergen Gross
2023-05-11 15:59         ` Martin Wilck
2023-05-11 16:00 ` Martin Wilck
2023-05-17  2:06 ` Martin K. Petersen
2023-05-17  4:54   ` Juergen Gross
2023-05-17 15:05     ` John Garry
2023-05-18  4:53       ` Juergen Gross
2023-05-18 10:57         ` John Garry
2023-05-18 19:54           ` Bart Van Assche
2023-05-19 16:06             ` John Garry
2023-05-19 16:54               ` Bart Van Assche
2023-05-19 17:12                 ` John Garry
2023-05-19 17:39                   ` Bart Van Assche
2023-05-22  9:55                     ` John Garry
2023-05-22 13:31                       ` Bart Van Assche
2023-05-22 15:54                         ` John Garry
2023-05-22 22:48                           ` michael.christie
2023-05-21  1:19           ` Martin K. Petersen
2023-05-21  5:23             ` Juergen Gross
2023-05-22 22:26               ` Martin K. Petersen
2023-05-23 15:04             ` Mike Christie
2023-05-21  0:46     ` Martin K. Petersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox