Skip to contentSkip to conversation

SCSI: target: off by one in tcm_loop_make_naa_tpg()

PATCH Superseded Dan Carpenter 2 participants 2 messages Jun 13, 2011 – Jun 15, 2011

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 4/4 SCSI: target: off by one in tcm_loop_make_naa_tpg()

There are TL_TPGS_PER_HBA elements in the ->tl_hba_tpgs[] array so this test is off by one. Later when we take the pointer, it would be one past the end and we'd crash:

	tl_tpg = &tl_hba->tl_hba_tpgs[tpgt];
	tl_tpg->tl_hba = tl_hba;

I think this can only be triggered by root.

drivers/target/loopback/tcm_loop.c +1 -1
index 7329d0e..4fedb58 100644
@@ -1227,7 +1227,7 @@ struct se_portal_group *tcm_loop_make_naa_tpg(
 	tpgt_str += 5; /* Skip ahead of "tpgt_" */
 	tpgt = (unsigned short int) simple_strtoul(tpgt_str, &end_ptr, 0);
 
-	if (tpgt > TL_TPGS_PER_HBA) {
+	if (tpgt >= TL_TPGS_PER_HBA) {
 		printk(KERN_ERR "Passed tpgt: %hu exceeds TL_TPGS_PER_HBA:"
 				" %u\n", tpgt, TL_TPGS_PER_HBA);
 		return ERR_PTR(-EINVAL);
#1 lore raw
Quoted 11 lines · Dan Carpenter

There are TL_TPGS_PER_HBA elements in the ->tl_hba_tpgs[] array so this test is off by one. Later when we take the pointer, it would be one past the end and we'd crash:

	tl_tpg = &tl_hba->tl_hba_tpgs[tpgt];
	tl_tpg->tl_hba = tl_hba;

I think this can only be triggered by root.

Ok, so I had merged this patch some time ago into lio-core-2.6.git, but did not make it to mainline.

I will include this patch along with your other bugfixes in a pull to Linus for v3.0-rc4 soon.

Thanks Dan!

--nab

Quoted 13 lines
drivers/target/loopback/tcm_loop.c +1 -1
index 7329d0e..4fedb58 100644
@@ -1227,7 +1227,7 @@ struct se_portal_group *tcm_loop_make_naa_tpg(
 	tpgt_str += 5; /* Skip ahead of "tpgt_" */
 	tpgt = (unsigned short int) simple_strtoul(tpgt_str, &end_ptr, 0);
 
-	if (tpgt > TL_TPGS_PER_HBA) {
+	if (tpgt >= TL_TPGS_PER_HBA) {
 		printk(KERN_ERR "Passed tpgt: %hu exceeds TL_TPGS_PER_HBA:"
 				" %u\n", tpgt, TL_TPGS_PER_HBA);
 		return ERR_PTR(-EINVAL);