Skip to contentSkip to conversation

target/tcm_fc: Fix use-after-free of ft_tpg

PATCH In review Andy Grover 3 participants 3 messages Apr 4, 2014 – Apr 7, 2014

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

PATCH 1/1 target/tcm_fc: Fix use-after-free of ft_tpg

ft_del_tpg checks tpg->tport is set before unlinking the tpg from the tport when the tpg is being removed. Set this pointer in ft_tport_create, or the unlinking won't happen in ft_del_tpg and tport->tpg will reference a deleted object.

see https://bugzilla.redhat.com/show_bug.cgi?id=1071340

---
 drivers/target/tcm_fc/tfc_sess.c | 1 +
 1 file changed, 1 insertion(+)
drivers/target/tcm_fc/tfc_sess.c +1 -0
index 0475142..1329726 100644
@@ -68,6 +68,7 @@ static struct ft_tport *ft_tport_create(struct fc_lport *lport)
 
 	if (tport) {
 		tport->tpg = tpg;
+		tpg->tport = tport;
 		return tport;
 	}
 
Signature · 1 line
1.9.0
#1 lore raw

Hi Andy,

Quoted 18 lines · Andy Grover

ft_del_tpg checks tpg->tport is set before unlinking the tpg from the tport when the tpg is being removed. Set this pointer in ft_tport_create, or the unlinking won't happen in ft_del_tpg and tport->tpg will reference a deleted object.

see https://bugzilla.redhat.com/show_bug.cgi?id=1071340

---
 drivers/target/tcm_fc/tfc_sess.c | 1 +
 1 file changed, 1 insertion(+)
drivers/target/tcm_fc/tfc_sess.c +0 -0
index 0475142..1329726 100644

drivers/target/tcm_fc/tfc_sess.c static struct ft_tport *ft_tport_create(struct fc_lport *lport) · line 74

Quoted 7 lines
drivers/target/tcm_fc/tfc_sess.c +1 -0
@@ -68,6 +68,7 @@ static struct ft_tport *ft_tport_create(struct fc_lport *lport)
 
 	if (tport) {
 		tport->tpg = tpg;
+		tpg->tport = tport;
 		return tport;
 	}
 

I'm confused how this addresses the bug above..?

Does this mean the bug is only triggered when a previously configured /sys/kernel/config/target/fc/$FCOE_WWPN/$TPGT has been removed, and then a new PLOGI picks up a left-over pointer to an endpoint that previously had been released..?

Care to add a more detailed commit explaining the exact details..?

--nab

#2 lore raw

PATCH 1/1 target/tcm_fc: Fix use-after-free of ft_tpg

This can happen:

- lport created, tport (our per-lport, per-provider context) is allocated. tport->tpg = NULL
- tpg created
- a PRLI is received. ft_tport_create is called, tpg is found and tport->tpg is set
- tpg removed. ft_tpg is freed in ft_del_tpg. Since tpg->tport was not set, tport->tpg is not cleared and points at freed memory
- Future calls to ft_tport_create return tport via first conditional, instead of searching for new tpg by calling ft_lport_find_tpg. tport->tpg is still invalid, and will access freed memory.

This patch sets tpg->tport in ft_tport_create, because that's what ft_del_tpg checks, and is the only way to get back to the tport to clear tport->tpg.

see https://bugzilla.redhat.com/show_bug.cgi?id=1071340

---
 drivers/target/tcm_fc/tfc_sess.c | 1 +
 1 file changed, 1 insertion(+)
drivers/target/tcm_fc/tfc_sess.c +1 -0
index 0475142..1329726 100644
@@ -68,6 +68,7 @@ static struct ft_tport *ft_tport_create(struct fc_lport *lport)
 
 	if (tport) {
 		tport->tpg = tpg;
+		tpg->tport = tport;
 		return tport;
 	}
 
Signature · 1 line
1.9.0