Skip to contentSkip to conversation

target/iscsi: double free in lio_target_tiqn_addtpg()

PATCH In review Dan Carpenter 3 participants 5 messages Dec 13, 2016 – Dec 16, 2016

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

PATCH 1/1 target/iscsi: double free in lio_target_tiqn_addtpg()

This iscsit_tpg_add_portal_group() function is only called from lio_target_tiqn_addtpg(). Both functions free the "tpg" pointer on error so it's a double free bug. The memory is allocated in the caller so it should be freed in the caller and not here.

Fixes e48354ce078c ("iscsi-target: Add iSCSI fabric support for target v4.1")
drivers/target/iscsi/iscsi_target_tpg.c +0 -1
index 0814e5894a96..205a509b0dfb 100644
@@ -260,7 +260,6 @@ int iscsit_tpg_add_portal_group(struct iscsi_tiqn *tiqn, struct iscsi_portal_gro
 		iscsi_release_param_list(tpg->param_list);
 		tpg->param_list = NULL;
 	}
-	kfree(tpg);
 	return -ENOMEM;
 }
 
Reviewed-by on v1 1/1
#1 lore raw
Quoted 13 lines · Dan Carpenter

This iscsit_tpg_add_portal_group() function is only called from lio_target_tiqn_addtpg(). Both functions free the "tpg" pointer on error so it's a double free bug. The memory is allocated in the caller so it should be freed in the caller and not here.

Fixes e48354ce078c ("iscsi-target: Add iSCSI fabric support for target v4.1")
drivers/target/iscsi/iscsi_target_tpg.c +0 -0
index 0814e5894a96..205a509b0dfb 100644

drivers/target/iscsi/iscsi_target_tpg.c int iscsit_tpg_add_portal_group(struct iscsi_tiqn *tiqn, struct iscsi_portal_gro · line 264

Quoted 6 lines
drivers/target/iscsi/iscsi_target_tpg.c +0 -1
@@ -260,7 +260,6 @@ int iscsit_tpg_add_portal_group(struct iscsi_tiqn *tiqn, struct iscsi_portal_gro
 		iscsi_release_param_list(tpg->param_list);
 		tpg->param_list = NULL;
 	}
-	kfree(tpg);
 	return -ENOMEM;
 }

Looks good, and works for me if I manually trigger the error path.

#2 lore raw
In reply to Dan Carpenter
Quoted 7 lines · Dan Carpenter

This iscsit_tpg_add_portal_group() function is only called from lio_target_tiqn_addtpg(). Both functions free the "tpg" pointer on error so it's a double free bug. The memory is allocated in the caller so it should be freed in the caller and not here.

Fixes e48354ce078c ("iscsi-target: Add iSCSI fabric support for target v4.1")

Hello Dan,

Do you think a "Cc: stable" tag should be added to this patch?

Bart.

#3 lore raw
In reply to Dan Carpenter
Quoted 6 lines · Bart Van Assche
Quoted 5 lines · Dan Carpenter

This iscsit_tpg_add_portal_group() function is only called from lio_target_tiqn_addtpg(). Both functions free the "tpg" pointer on error so it's a double free bug. The memory is allocated in the caller so it should be freed in the caller and not here.

Quoted 7 lines
Quoted 2 lines
Fixes e48354ce078c ("iscsi-target: Add iSCSI fabric support for target v4.1")

Hello Dan,

Do you think a "Cc: stable" tag should be added to this patch?

It will basically only fail for allocation errors. It's probably not super likely. These are static checker fixes, not something I encountered in real life.

regards,
dan carpenter

#4 lore raw
In reply to Dan Carpenter
Quoted 7 lines · Dan Carpenter
Quoted 6 lines · Bart Van Assche
Quoted 5 lines · Dan Carpenter

This iscsit_tpg_add_portal_group() function is only called from lio_target_tiqn_addtpg(). Both functions free the "tpg" pointer on error so it's a double free bug. The memory is allocated in the caller so it should be freed in the caller and not here.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Fixes e48354ce078c ("iscsi-target: Add iSCSI fabric support for target v4.1")

Do you think a "Cc: stable" tag should be added to this patch?

It will basically only fail for allocation errors. It's probably not super likely. These are static checker fixes, not something I encountered in real life.

Hello Dan,

Thanks for the patch and for the additional clarification. I have queued your patch for kernel version v4.10.

Bart.