Skip to contentSkip to conversation

tcm_loop: use after free on error

PATCH In review Dan Carpenter 3 participants 3 messages Mar 2, 2016 – Mar 5, 2016

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

PATCH 1/1 tcm_loop: use after free on error

We dereference "tl_nexus" to get the error code.

Fixes 1b418a8fcbc0 ('target: Convert demo-mode only drivers to target_alloc_session')
drivers/target/loopback/tcm_loop.c +3 -1
index 0216c75..e0ffb03 100644
@@ -808,6 +808,7 @@ static int tcm_loop_make_nexus(
 {
 	struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba;
 	struct tcm_loop_nexus *tl_nexus;
+	int ret;
 
 	if (tl_tpg->tl_nexus) {
 		pr_debug("tl_tpg->tl_nexus already exists\n");
@@ -824,8 +825,9 @@ static int tcm_loop_make_nexus(
 					TARGET_PROT_DIN_PASS | TARGET_PROT_DOUT_PASS,
 					name, tl_nexus, NULL);
 	if (IS_ERR(tl_nexus->se_sess)) {
+		ret = PTR_ERR(tl_nexus->se_sess);
 		kfree(tl_nexus);
-		return PTR_ERR(tl_nexus->se_sess);
+		return ret;
 	}
 
 	tl_tpg->tl_nexus = tl_nexus;
#2 lore raw
In reply to Dan Carpenter
Quoted 18 lines · Dan Carpenter

We dereference "tl_nexus" to get the error code.

Fixes 1b418a8fcbc0 ('target: Convert demo-mode only drivers to target_alloc_session')
drivers/target/loopback/tcm_loop.c +1 -0
index 0216c75..e0ffb03 100644
@@ -808,6 +808,7 @@ static int tcm_loop_make_nexus(
 {
 	struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba;
 	struct tcm_loop_nexus *tl_nexus;
+	int ret;
 
 	if (tl_tpg->tl_nexus) {
 		pr_debug("tl_tpg->tl_nexus already exists\n");

drivers/target/loopback/tcm_loop.c static int tcm_loop_make_nexus( · line 833

Quoted 10 lines
drivers/target/loopback/tcm_loop.c +2 -1
@@ -824,8 +825,9 @@ static int tcm_loop_make_nexus(
 					TARGET_PROT_DIN_PASS | TARGET_PROT_DOUT_PASS,
 					name, tl_nexus, NULL);
 	if (IS_ERR(tl_nexus->se_sess)) {
+		ret = PTR_ERR(tl_nexus->se_sess);
 		kfree(tl_nexus);
-		return PTR_ERR(tl_nexus->se_sess);
+		return ret;
 	}
 
 	tl_tpg->tl_nexus = tl_nexus;

Also fixed + squashed into HCH's original patch.