Linux SCSI subsystem development
 help / color / mirror / Atom feed
* [PATCH] scsi: don't panic host on invalid sgtable count
@ 2020-01-24 15:16 Johannes Thumshirn
  2020-01-24 15:23 ` James Bottomley
  0 siblings, 1 reply; 3+ messages in thread
From: Johannes Thumshirn @ 2020-01-24 15:16 UTC (permalink / raw)
  To: Martin K . Petersen; +Cc: linux-scsi, Johannes Thumshirn

If we have an invalid number of entries mapped an sg table, there's no
need to panic the host, instead we can spit out a warning in dmesg and
gracefully return an I/O error.

While we're at it fix a trailing whitespace in the comment above.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 drivers/scsi/scsi_lib.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 3e7a45d0daca..9bddf54e3def 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -992,12 +992,15 @@ static blk_status_t scsi_init_sgtable(struct request *req,
 			SCSI_INLINE_SG_CNT)))
 		return BLK_STS_RESOURCE;
 
-	/* 
+	/*
 	 * Next, walk the list, and fill in the addresses and sizes of
 	 * each segment.
 	 */
 	count = blk_rq_map_sg(req->q, req, sdb->table.sgl);
-	BUG_ON(count > sdb->table.nents);
+	if (WARN_ON_ONCE(count > sdb->table.nents)) {
+		sg_free_table_chained(&sdb->table, SCSI_INLINE_SG_CNT);
+		return BLK_STS_IOERR;
+	}
 	sdb->table.nents = count;
 	sdb->length = blk_rq_payload_bytes(req);
 	return BLK_STS_OK;
-- 
2.24.1


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

end of thread, other threads:[~2020-01-24 15:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-01-24 15:16 [PATCH] scsi: don't panic host on invalid sgtable count Johannes Thumshirn
2020-01-24 15:23 ` James Bottomley
2020-01-24 15:27   ` Johannes Thumshirn

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