Skip to contentSkip to conversation

tcm_loop: off by one in tcm_loop_make_naa_tpg()

PATCH In review Dan Carpenter 2 participants 2 messages Mar 29, 2011 – Apr 2, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tcm_loop: off by one in tcm_loop_make_naa_tpg()

This is an off by one that could result in memory corruption.

drivers/target/loopback/tcm_loop.c +1 -1
index aed4e46..2bb5062 100644
@@ -1239,7 +1239,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 4 lines · Dan Carpenter

This is an off by one that could result in memory corruption.

Hi Dan,

Apologies for the delayed response on here..

This has been included as commit fb9b35be into lio-core-2.6.git/lio-4.1 @ .39-rc1, and will get this queued to James as a 'for-39' mainline bugfix item.

Thank you!

--nab

Quoted 13 lines
drivers/target/loopback/tcm_loop.c +1 -1
index aed4e46..2bb5062 100644
@@ -1239,7 +1239,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);