scsi: fix random memory corruption with scsi-mq + T10 PI
PATCH 1/1 scsi: fix random memory corruption with scsi-mq + T10 PI
This fixes random memory corruption triggered when all three of the following are true:
* scsi-mq enabled
* T10 Protection Information (DIF) enabled
* SCSI host with sg_tablesize > SCSI_MAX_SG_SEGMENTS (128)
The symptoms of this bug are unpredictable memory corruption, BUG()s, oopses, lockups, etc., any of which may appear to be completely unrelated to the root cause.
---
I encountered this problem with a QLogic QLE2672 FC HBA using qla2xxx. On my system, this would trigger BUG_ON(atomic_read(&bio->bi_remaining) <= 0) in bio_endio(), or a general protection fault in __sg_free_table() trying to free prot_sdb, or any number of other weird random problems. All of this was caused by cmd->prot_sdb pointing to the wrong memory. To see how the memory is allocated, refer to scsi_mq_setup_tags() in scsi_lib.c.
For inclusion in 3.19, 3.18.x, and 3.17.x.
drivers/scsi/scsi_lib.c renamed from drivers/scsi/scsi_lib.c.orig +3 -1
@@ -1829,7 +1829,9 @@ static int scsi_mq_prep_fn(struct requesif (scsi_host_get_prot (shost)) { cmd->prot_sdb = (void *)sg + - shost->sg_tablesize *sizeof (struct scatterlist ); + min_t(unsigned int, + shost->sg_tablesize,SCSI_MAX_SG_SEGMENTS ) * +sizeof (struct scatterlist );memset (cmd->prot_sdb,0 ,sizeof (struct scsi_data_buffer )); cmd->prot_sdb->table.sgl =
Hi Tony,
Quoted 30 lines · Tony Battersby
This fixes random memory corruption triggered when all three of the following are true:
* scsi-mq enabled
* T10 Protection Information (DIF) enabled
* SCSI host withsg_tablesize>SCSI_MAX_SG_SEGMENTS(128)The symptoms of this bug are unpredictable memory corruption, BUG()s, oopses, lockups, etc., any of which may appear to be completely unrelated to the root cause.
Cc <[email protected]> # 3.17.x, 3.18.xSigned-off-by Tony Battersby <[email protected]>---
I encountered this problem with a QLogic QLE2672 FC HBA using qla2xxx. On my system, this would trigger
BUG_ON(atomic_read(&bio->bi_remaining) <= 0)inbio_endio(), or a general protection fault in__sg_free_table()trying to freeprot_sdb, or any number of other weird random problems. All of this was caused bycmd->prot_sdbpointing to the wrong memory. To see how the memory is allocated, refer toscsi_mq_setup_tags()inscsi_lib.c.For inclusion in 3.19, 3.18.x, and 3.17.x.
drivers/scsi/scsi_lib.c static int scsi_mq_prep_fn(struct reques · line 1837
Quoted 10 lines
drivers/scsi/scsi_lib.c renamed from drivers/scsi/scsi_lib.c.orig +3
-1@@ -1829,7 +1829,9 @@ static int scsi_mq_prep_fn(struct requesif (scsi_host_get_prot (shost)) { cmd->prot_sdb = (void *)sg + - shost->sg_tablesize *sizeof (struct scatterlist ); + min_t(unsigned int, + shost->sg_tablesize,SCSI_MAX_SG_SEGMENTS ) * +sizeof (struct scatterlist );memset (cmd->prot_sdb,0 ,sizeof (struct scsi_data_buffer )); cmd->prot_sdb->table.sgl =
Nice catch.
Adding a CC' to MKP, and HCH so he can pick it up.
--nab
Christoph Hellwig
AppliedThanks,
applied to drivers-for-3.19.