libiscsi: Fix use-after-free race during iscsi_session_teardown
PATCH v2 1/2 libiscsi: Fix use-after-free race during iscsi_session_teardown
Session attributes exposed through sysfs were freed before the device was destroyed, resulting in a potential use-after-free. Free these attributes after removing the device.
--- drivers/scsi/libiscsi.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/scsi/libiscsi.c +4 -4
@@ -2851,9 +2851,6 @@ EXPORT_SYMBOL_GPL(iscsi_session_setup);/** * iscsi_session_teardown - destroy session, host, and cls_session * @cls_session: iscsi session -* -* The driver must have called iscsi_remove_session before -* calling this. */ void iscsi_session_teardown (struct iscsi_cls_session *cls_session) {
@@ -2863,6 +2860,8 @@ void iscsi_session_teardown(struct iscsi_cls_session *cls_session)iscsi_pool_free (&session->cmdpool); +iscsi_remove_session (cls_session); +kfree (session->password);kfree (session->password_in);kfree (session->username);
@@ -2877,7 +2876,8 @@ void iscsi_session_teardown(struct iscsi_cls_session *cls_session)kfree (session->portal_type);kfree (session->discovery_parent_type); -iscsi_destroy_session (cls_session); +iscsi_free_session (cls_session); +iscsi_host_dec_session_cnt (shost);module_put (owner); }
Signature · 1 line
2.13.2.932.g7449e964c-goog
PATCH v2 2/2 libiscsi: Remove iscsi_destroy_session
iscsi_session_teardown was the only user of this function. Function currently is just short for iscsi_remove_session + iscsi_free_session.
--- drivers/scsi/scsi_transport_iscsi.c | 16 ---------------- include/scsi/scsi_transport_iscsi.h | 1 - 2 files changed, 17 deletions(-)
drivers/scsi/scsi_transport_iscsi.c +0 -16
@@ -2210,22 +2210,6 @@ void iscsi_free_session(struct iscsi_cls_session *session) }EXPORT_SYMBOL_GPL (iscsi_free_session); -/** -* iscsi_destroy_session - destroy iscsi session -* @session: iscsi_session -* -* Can be called by a LLD or iscsi_transport. There must not be -* any running connections. -*/ -int iscsi_destroy_session (struct iscsi_cls_session *session) -{ -iscsi_remove_session (session); -ISCSI_DBG_TRANS_SESSION (session,"Completing session destruction\n" ); -iscsi_free_session (session); -return 0 ; -} -EXPORT_SYMBOL_GPL (iscsi_destroy_session); -/** * iscsi_create_conn - create iscsi class connection * @session: iscsi cls session
include/scsi/scsi_transport_iscsi.h +0 -1
@@ -434,7 +434,6 @@ extern struct iscsi_cls_session *iscsi_create_session(struct Scsi_Host *shost, unsigned int target_id);extern void iscsi_remove_session (struct iscsi_cls_session *session);extern void iscsi_free_session (struct iscsi_cls_session *session); -extern int iscsi_destroy_session (struct iscsi_cls_session *session);extern struct iscsi_cls_conn *iscsi_create_conn (struct iscsi_cls_session *sess,int dd_size,uint32_t cid);extern int iscsi_destroy_conn (struct iscsi_cls_conn *conn);
Signature · 8 lines
2.13.2.932.g7449e964c-goog -- You received this message because you are subscribed to the Google Groups "open-iscsi" group. To unsubscribe from this group and stop receiving emails from it, send an email to open-iscsi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected] To post to this group, send email to open-iscsi-/JYPxA39Uh5TLH3MbocFF+G/[email protected] Visit this group at https://groups.google.com/group/open-iscsi. For more options, visit https://groups.google.com/d/optout.
Re: [Patch v2 2/2] libiscsi: Remove iscsi_destroy_session
Thanks.
Quoted 57 lines · Khazhismel Kumykov' via open-iscsi
iscsi_session_teardownwas the only user of this function. Function currently is just short foriscsi_remove_session+iscsi_free_session.Signed-off-by Khazhismel Kumykov <[email protected]>--- drivers/scsi/scsi_transport_iscsi.c | 16 ---------------- include/scsi/scsi_transport_iscsi.h | 1 - 2 files changed, 17 deletions(-)drivers/scsi/scsi_transport_iscsi.c +0
-16@@ -2210,22 +2210,6 @@ void iscsi_free_session(struct iscsi_cls_session *session) }EXPORT_SYMBOL_GPL (iscsi_free_session); -/** -* iscsi_destroy_session - destroy iscsi session -* @session: iscsi_session -* -* Can be called by a LLD or iscsi_transport. There must not be -* any running connections. -*/ -int iscsi_destroy_session (struct iscsi_cls_session *session) -{ -iscsi_remove_session (session); -ISCSI_DBG_TRANS_SESSION (session,"Completing session destruction\n" ); -iscsi_free_session (session); -return 0 ; -} -EXPORT_SYMBOL_GPL (iscsi_destroy_session); -/** * iscsi_create_conn - create iscsi class connection * @session: iscsi cls session include/scsi/scsi_transport_iscsi.h +0
-1@@ -434,7 +434,6 @@ extern struct iscsi_cls_session *iscsi_create_session(struct Scsi_Host *shost, unsigned int target_id);extern void iscsi_remove_session (struct iscsi_cls_session *session);extern void iscsi_free_session (struct iscsi_cls_session *session); -extern int iscsi_destroy_session (struct iscsi_cls_session *session);extern struct iscsi_cls_conn *iscsi_create_conn (struct iscsi_cls_session *sess,int dd_size,uint32_t cid);extern int iscsi_destroy_conn (struct iscsi_cls_conn *conn);Signature · 8 lines
2.13.2.932.g7449e964c-goog -- You received this message because you are subscribed to the Google Groups "open-iscsi" group. To unsubscribe from this group and stop receiving emails from it, send an email to open-iscsi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected] To post to this group, send email to open-iscsi-/JYPxA39Uh5TLH3MbocFF+G/[email protected] Visit this group at https://groups.google.com/group/open-iscsi. For more options, visit https://groups.google.com/d/optout.
Signature · 5 lines
You received this message because you are subscribed to the Google Groups "open-iscsi" group. To unsubscribe from this group and stop receiving emails from it, send an email to open-iscsi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected] To post to this group, send email to open-iscsi-/JYPxA39Uh5TLH3MbocFF+G/[email protected] Visit this group at https://groups.google.com/group/open-iscsi. For more options, visit https://groups.google.com/d/optout.
Lee Duncan
maintainerRe: [Patch v2 2/2] libiscsi: Remove iscsi_destroy_session
In reply to Khazhismel KumykovQuoted 4 lines · Khazhismel Kumykov
iscsi_session_teardownwas the only user of this function. Function currently is just short foriscsi_remove_session+iscsi_free_session.Signed-off-by Khazhismel Kumykov <[email protected]>
Why is this needed? I dislike changes that don't fix anything.
Quoted 45 lines
--- drivers/scsi/scsi_transport_iscsi.c | 16 ---------------- include/scsi/scsi_transport_iscsi.h | 1 - 2 files changed, 17 deletions(-)drivers/scsi/scsi_transport_iscsi.c +0
-16@@ -2210,22 +2210,6 @@ void iscsi_free_session(struct iscsi_cls_session *session) }EXPORT_SYMBOL_GPL (iscsi_free_session); -/** -* iscsi_destroy_session - destroy iscsi session -* @session: iscsi_session -* -* Can be called by a LLD or iscsi_transport. There must not be -* any running connections. -*/ -int iscsi_destroy_session (struct iscsi_cls_session *session) -{ -iscsi_remove_session (session); -ISCSI_DBG_TRANS_SESSION (session,"Completing session destruction\n" ); -iscsi_free_session (session); -return 0 ; -} -EXPORT_SYMBOL_GPL (iscsi_destroy_session); -/** * iscsi_create_conn - create iscsi class connection * @session: iscsi cls session include/scsi/scsi_transport_iscsi.h +0
-1@@ -434,7 +434,6 @@ extern struct iscsi_cls_session *iscsi_create_session(struct Scsi_Host *shost, unsigned int target_id);extern void iscsi_remove_session (struct iscsi_cls_session *session);extern void iscsi_free_session (struct iscsi_cls_session *session); -extern int iscsi_destroy_session (struct iscsi_cls_session *session);extern struct iscsi_cls_conn *iscsi_create_conn (struct iscsi_cls_session *sess,int dd_size,uint32_t cid);extern int iscsi_destroy_conn (struct iscsi_cls_conn *conn);
Signature · 2 lines
Lee Duncan SUSE Labs
Re: [Patch v2 2/2] libiscsi: Remove iscsi_destroy_session
Quoted 7 lines · Lee Duncan
Quoted 4 lines · Khazhismel Kumykov
iscsi_session_teardownwas the only user of this function. Function currently is just short foriscsi_remove_session+iscsi_free_session.Signed-off-by Khazhismel Kumykov <[email protected]>Why is this needed? I dislike changes that don't fix anything.
The function has no more users left after patch 1, so why keep it bitrotting?
Signature · 13 lines
Johannes Thumshirn Storage [email protected] +49 911 74053 689 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: Felix Imendörffer, Jane Smithard, Graham Norton HRB 21284 (AG Nürnberg) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850 -- You received this message because you are subscribed to the Google Groups "open-iscsi" group. To unsubscribe from this group and stop receiving emails from it, send an email to open-iscsi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected] To post to this group, send email to open-iscsi-/JYPxA39Uh5TLH3MbocFF+G/[email protected] Visit this group at https://groups.google.com/group/open-iscsi. For more options, visit https://groups.google.com/d/optout.
On Thu, Jul 13, 2017 at 9:11 AM, Khazhismel Kumykov <[email protected]> wrote:
Ping in case this was missed
Signature · 5 lines
You received this message because you are subscribed to the Google Groups "open-iscsi" group. To unsubscribe from this group and stop receiving emails from it, send an email to open-iscsi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected] To post to this group, send email to open-iscsi-/JYPxA39Uh5TLH3MbocFF+G/[email protected] Visit this group at https://groups.google.com/group/open-iscsi. For more options, visit https://groups.google.com/d/optout.
Looks good to me, fixes up the code given that the comment there about calling iscsi_remove_session wasn't being followed.
Thanks
Quoted 51 lines · Khazhismel Kumykov' via open-iscsi
Session attributes exposed through sysfs were freed before the device was destroyed, resulting in a potential use-after-free. Free these attributes after removing the device.
Signed-off-by Khazhismel Kumykov <[email protected]>--- drivers/scsi/libiscsi.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/scsi/libiscsi.c +4
-4@@ -2851,9 +2851,6 @@ EXPORT_SYMBOL_GPL(iscsi_session_setup);/** * iscsi_session_teardown - destroy session, host, and cls_session * @cls_session: iscsi session -* -* The driver must have called iscsi_remove_session before -* calling this. */ void iscsi_session_teardown (struct iscsi_cls_session *cls_session) {@@ -2863,6 +2860,8 @@ void iscsi_session_teardown(struct iscsi_cls_session *cls_session)iscsi_pool_free (&session->cmdpool); +iscsi_remove_session (cls_session); +kfree (session->password);kfree (session->password_in);kfree (session->username);@@ -2877,7 +2876,8 @@ void iscsi_session_teardown(struct iscsi_cls_session *cls_session)kfree (session->portal_type);kfree (session->discovery_parent_type); -iscsi_destroy_session (cls_session); +iscsi_free_session (cls_session); +iscsi_host_dec_session_cnt (shost);module_put (owner); }Signature · 8 lines
2.13.2.932.g7449e964c-goog -- You received this message because you are subscribed to the Google Groups "open-iscsi" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/open-iscsi. For more options, visit https://groups.google.com/d/optout.
Martin K. Petersen
AppliedChris,
Quoted 2 lines
Looks good to me, fixes up the code given that the comment there about calling
iscsi_remove_sessionwasn't being followed.
Applied these two to 4.14/scsi-queue.
Signature · 8 lines
Martin K. Petersen Oracle Linux Engineering -- You received this message because you are subscribed to the Google Groups "open-iscsi" group. To unsubscribe from this group and stop receiving emails from it, send an email to open-iscsi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected] To post to this group, send email to open-iscsi-/JYPxA39Uh5TLH3MbocFF+G/[email protected] Visit this group at https://groups.google.com/group/open-iscsi. For more options, visit https://groups.google.com/d/optout.
Noticed these don't seem to be in 4.14/scsi-queue
Quoted 10 lines · Martin K. Petersen
Chris,
Quoted 2 lines
Looks good to me, fixes up the code given that the comment there about calling
iscsi_remove_sessionwasn't being followed.Applied these two to 4.14/scsi-queue.
--
Martin K. Petersen Oracle Linux Engineering
Signature · 5 lines
You received this message because you are subscribed to the Google Groups "open-iscsi" group. To unsubscribe from this group and stop receiving emails from it, send an email to open-iscsi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected] To post to this group, send email to open-iscsi-/JYPxA39Uh5TLH3MbocFF+G/[email protected] Visit this group at https://groups.google.com/group/open-iscsi. For more options, visit https://groups.google.com/d/optout.
Khazhismel,
Quoted 1 line
Noticed these don't seem to be in 4.14/scsi-queue
Not sure what happened there. I apologize.
They are now in 4.14/scsi-fixes.
Signature · 8 lines
Martin K. Petersen Oracle Linux Engineering -- You received this message because you are subscribed to the Google Groups "open-iscsi" group. To unsubscribe from this group and stop receiving emails from it, send an email to open-iscsi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected] To post to this group, send email to open-iscsi-/JYPxA39Uh5TLH3MbocFF+G/[email protected] Visit this group at https://groups.google.com/group/open-iscsi. For more options, visit https://groups.google.com/d/optout.