target: stable backports
cover target: stable backports
From: Nicholas Bellinger <[email protected]>
Hi Sasha,
Here are a number of target patches for v4.1.y stable, which haven't been applied over the last two of releases due to various context changes.
The series has been cut against v4.1.43. Please apply at your earliest convenience.
Thank you.
--nab
Jiang Yi (1):
iscsi-target: Always wait for kthread_should_stop() before kthread
exit
Nicholas Bellinger (6):
target: Obtain se_node_acl->acl_kref during get_initiator_node_acl
target: Fix multi-session dynamic se_node_acl double free OOPs
target: Avoid mappedlun symlink creation during lun shutdown
iscsi-target: Fix delayed logout processing greater than
SECONDS_FOR_LOGOUT_COMP
iser-target: Avoid isert_conn->cm_id dereference in
isert_login_recv_done
Revert "target: Fix VERIFY and WRITE VERIFY command parsing"
drivers/infiniband/ulp/isert/ib_isert.c | 2 +- drivers/target/iscsi/iscsi_target.c | 40 ++++++++++--- drivers/target/iscsi/iscsi_target_erl0.c | 6 +- drivers/target/iscsi/iscsi_target_erl0.h | 2 +- drivers/target/iscsi/iscsi_target_login.c | 4 ++ drivers/target/target_core_fabric_configfs.c | 5 ++ drivers/target/target_core_sbc.c | 71 +++------------------- drivers/target/target_core_tpg.c | 47 ++++++++++++++- drivers/target/target_core_transport.c | 88 ++++++++++++++++++---------- include/target/target_core_base.h | 2 + include/target/target_core_fabric.h | 2 + 11 files changed, 162 insertions(+), 107 deletions(-)
Signature · 1 line
1.8.5.3
PATCH 1/7 target: Obtain se_node_acl->acl_kref during get_initiator_node_acl
From: Nicholas Bellinger <[email protected]>
commit 21aaa23b0ebbd19334fa461370c03cbb076b3295 upstream.
This patch addresses a long standing race where obtaining se_node_acl->acl_kref in __transport_register_session() happens a bit too late, and leaves open the potential for core_tpg_del_initiator_node_acl() to hit a NULL pointer dereference.
Instead, take ->acl_kref in core_tpg_get_initiator_node_acl() while se_portal_group->acl_node_mutex is held, and move the final target_put_nacl() from transport_deregister_session() into transport_free_session() so that fabric driver login failure handling using the modern method to still work as expected.
Also, update core_tpg_get_initiator_node_acl() to take an extra reference for dynamically generated acls for demo-mode, before returning to fabric caller. Also update iscsi-target sendtargets special case handling to use target_tpg_has_node_acl() when checking if demo_mode_discovery == true during discovery lookup.
Note the existing wait_for_completion(&acl->acl_free_comp) in core_tpg_del_initiator_node_acl() does not change.
--- drivers/target/iscsi/iscsi_target.c | 2 +- drivers/target/target_core_tpg.c | 44 ++++++++++++++++++++++++++++++++-- drivers/target/target_core_transport.c | 18 +++++++++----- include/target/target_core_fabric.h | 2 ++ 4 files changed, 57 insertions(+), 9 deletions(-)
drivers/target/iscsi/iscsi_target.c +1 -1
@@ -3447,7 +3447,7 @@ iscsit_build_sendtargets_response(struct iscsi_cmd *cmd,if ((tpg->tpg_attrib.generate_node_acls ==0 ) && (tpg->tpg_attrib.demo_mode_discovery ==0 ) && - (!core_tpg_get_initiator_node_acl (&tpg->tpg_se_tpg, + (!target_tpg_has_node_acl (&tpg->tpg_se_tpg, cmd->conn->sess->sess_ops->InitiatorName))) {continue ; }
drivers/target/target_core_tpg.c +42 -2
67 lines not on this page · raw message
drivers/target/target_core_transport.c +12 -6
@@ -359,7 +359,6 @@ void __transport_register_session( &buf[0], PR_REG_ISID_LEN); se_sess->sess_bin_isid =get_unaligned_be64 (&buf[0 ]); } -kref_get (&se_nacl->acl_kref);spin_lock_irq (&se_nacl->nacl_sess_lock);/*
@@ -456,6 +455,7 @@ void target_put_nacl(struct se_node_acl *nacl) {kref_put (&nacl->acl_kref, target_complete_nacl); } +EXPORT_SYMBOL (target_put_nacl);void transport_deregister_session_configfs (struct se_session *se_sess) {
@@ -488,6 +488,15 @@ EXPORT_SYMBOL(transport_deregister_session_configfs);void transport_free_session (struct se_session *se_sess) { +struct se_node_acl *se_nacl = se_sess->se_node_acl; +/* +* Drop the se_node_acl->nacl_kref obtained from within +* core_tpg_get_initiator_node_acl(). +*/ +if (se_nacl) { + se_sess->se_node_acl =NULL ; +target_put_nacl (se_nacl); + }if (se_sess->sess_cmd_map) {percpu_ida_destroy (&se_sess->sess_tag_pool);if (is_vmalloc_addr (se_sess->sess_cmd_map))
@@ -505,7 +514,6 @@ void transport_deregister_session(struct se_session *se_sess)const struct target_core_fabric_ops *se_tfo;struct se_node_acl *se_nacl;unsigned long flags; -bool comp_nacl = true;if (!se_tpg) {transport_free_session (se_sess);
@@ -533,9 +541,9 @@ void transport_deregister_session(struct se_session *se_sess)spin_unlock_irqrestore (&se_tpg->acl_node_lock, flags);core_tpg_wait_for_nacl_pr_ref (se_nacl);core_free_device_list_for_node (se_nacl, se_tpg); + se_sess->se_node_acl =NULL ; se_tfo->tpg_release_fabric_acl (se_tpg, se_nacl); - comp_nacl = false;spin_lock_irqsave (&se_tpg->acl_node_lock, flags); } }
@@ -546,10 +554,8 @@ void transport_deregister_session(struct se_session *se_sess)/* * If last kref is dropping now for an explicit NodeACL, awake sleeping * ->acl_free_comp caller to wakeup configfs se_node_acl->acl_group -* removal context. +* removal context from within transport_free_session() code. */ -if (se_nacl && comp_nacl) -target_put_nacl (se_nacl);transport_free_session (se_sess); }
include/target/target_core_fabric.h +2 -0
@@ -171,6 +171,8 @@ int transport_lookup_tmr_lun(struct se_cmd *, u32);struct se_node_acl *core_tpg_get_initiator_node_acl (struct se_portal_group *tpg,unsigned char *); +bool target_tpg_has_node_acl (struct se_portal_group *tpg, +const char *);struct se_node_acl *core_tpg_check_initiator_node_acl (struct se_portal_group *,unsigned char *);void core_tpg_clear_object_luns (struct se_portal_group *);
Signature · 1 line
1.8.5.3
PATCH 2/7 target: Fix multi-session dynamic se_node_acl double free OOPs
In reply to Nicholas A. BellingerFrom: Nicholas Bellinger <[email protected]>
commit 01d4d673558985d9a118e1e05026633c3e2ade9b upstream.
This patch addresses a long-standing bug with multi-session (eg: iscsi-target + iser-target) se_node_acl dynamic free withini transport_deregister_session().
This bug is caused when a storage endpoint is configured with demo-mode (generate_node_acls = 1 + cache_dynamic_acls = 1) initiators, and initiator login creates a new dynamic node acl and attaches two sessions to it.
After that, demo-mode for the storage instance is disabled via configfs (generate_node_acls = 0 + cache_dynamic_acls = 0) and the existing dynamic acl is never converted to an explicit ACL.
The end result is dynamic acl resources are released twice when the sessions are shutdown in transport_deregister_session().
If the storage instance is not changed to disable demo-mode, or the dynamic acl is converted to an explict ACL, or there is only a single session associated with the dynamic ACL, the bug is not triggered.
To address this big, move the release of dynamic se_node_acl memory into target_complete_nacl() so it's only freed once when se_node_acl->acl_kref reaches zero.
(Drop unnecessary list_del_init usage - HCH)
--- drivers/target/target_core_transport.c | 72 ++++++++++++++++++++++------------ include/target/target_core_base.h | 1 + 2 files changed, 47 insertions(+), 26 deletions(-)
drivers/target/target_core_transport.c +46 -26
@@ -447,8 +447,23 @@ static void target_complete_nacl(struct kref *kref) {struct se_node_acl *nacl =container_of (kref, struct se_node_acl, acl_kref); +struct se_portal_group *se_tpg = nacl->se_tpg; +const struct target_core_fabric_ops *se_tfo = se_tpg->se_tpg_tfo; +unsigned long flags; + +if (!nacl->dynamic_stop) { +complete (&nacl->acl_free_comp); +return ; + } + +spin_lock_irqsave (&se_tpg->acl_node_lock, flags); +list_del (&nacl->acl_list); + se_tpg->num_node_acls--; +spin_unlock_irqrestore (&se_tpg->acl_node_lock, flags); -complete (&nacl->acl_free_comp); +core_tpg_wait_for_nacl_pr_ref (nacl); +core_free_device_list_for_node (nacl, se_tpg); + se_tfo->tpg_release_fabric_acl (se_tpg, nacl); }void target_put_nacl (struct se_node_acl *nacl)
@@ -489,12 +504,39 @@ EXPORT_SYMBOL(transport_deregister_session_configfs);void transport_free_session (struct se_session *se_sess) {struct se_node_acl *se_nacl = se_sess->se_node_acl; +/* * Drop the se_node_acl->nacl_kref obtained from within * core_tpg_get_initiator_node_acl(). */ if (se_nacl) { +struct se_portal_group *se_tpg = se_nacl->se_tpg; +const struct target_core_fabric_ops *se_tfo = se_tpg->se_tpg_tfo; +unsigned long flags; + se_sess->se_node_acl =NULL ; + +/* +* Also determine if we need to drop the extra ->cmd_kref if +* it had been previously dynamically generated, and +* the endpoint is not caching dynamic ACLs. +*/ +spin_lock_irqsave (&se_tpg->acl_node_lock, flags); +if (se_nacl->dynamic_node_acl && + !se_tfo->tpg_check_demo_mode_cache (se_tpg)) { +spin_lock (&se_nacl->nacl_sess_lock); +if (list_empty (&se_nacl->acl_sess_list)) + se_nacl->dynamic_stop = true; +spin_unlock (&se_nacl->nacl_sess_lock); + +if (se_nacl->dynamic_stop) +list_del (&se_nacl->acl_list); + } +spin_unlock_irqrestore (&se_tpg->acl_node_lock, flags); + +if (se_nacl->dynamic_stop) +target_put_nacl (se_nacl); +target_put_nacl (se_nacl); }if (se_sess->sess_cmd_map) {
@@ -511,15 +553,12 @@ EXPORT_SYMBOL(transport_free_session);void transport_deregister_session (struct se_session *se_sess) {struct se_portal_group *se_tpg = se_sess->se_tpg; -const struct target_core_fabric_ops *se_tfo; -struct se_node_acl *se_nacl;unsigned long flags;if (!se_tpg) {transport_free_session (se_sess);return ; } - se_tfo = se_tpg->se_tpg_tfo;spin_lock_irqsave (&se_tpg->session_lock, flags);list_del (&se_sess->sess_list);
@@ -527,34 +566,15 @@ void transport_deregister_session(struct se_session *se_sess) se_sess->fabric_sess_ptr =NULL ;spin_unlock_irqrestore (&se_tpg->session_lock, flags); -/* -* Determine if we need to do extra work for this initiator node's -* struct se_node_acl if it had been previously dynamically generated. -*/ - se_nacl = se_sess->se_node_acl; - -spin_lock_irqsave (&se_tpg->acl_node_lock, flags); -if (se_nacl && se_nacl->dynamic_node_acl) { -if (!se_tfo->tpg_check_demo_mode_cache (se_tpg)) { -list_del (&se_nacl->acl_list); - se_tpg->num_node_acls--; -spin_unlock_irqrestore (&se_tpg->acl_node_lock, flags); -core_tpg_wait_for_nacl_pr_ref (se_nacl); -core_free_device_list_for_node (se_nacl, se_tpg); - se_sess->se_node_acl =NULL ; - se_tfo->tpg_release_fabric_acl (se_tpg, se_nacl); - -spin_lock_irqsave (&se_tpg->acl_node_lock, flags); - } - } -spin_unlock_irqrestore (&se_tpg->acl_node_lock, flags); -pr_debug ("TARGET_CORE[%s]: Deregistered fabric_sess\n" , se_tpg->se_tpg_tfo->get_fabric_name ());/* * If last kref is dropping now for an explicit NodeACL, awake sleeping * ->acl_free_comp caller to wakeup configfs se_node_acl->acl_group * removal context from within transport_free_session() code. +* +* For dynamic ACL, target_put_nacl() uses target_complete_nacl() +* to release all remaining generate_node_acl=1 created ACL resources. */ transport_free_session (se_sess);
include/target/target_core_base.h +1 -0
@@ -590,6 +590,7 @@ struct se_node_acl {/* Used to signal demo mode created ACL, disabled by default */ bool dynamic_node_acl; bool acl_stop:1; +bool dynamic_stop;u32 queue_depth;u32 acl_index;enum target_prot_type saved_prot_type;
Signature · 1 line
1.8.5.3
PATCH 3/7 target: Avoid mappedlun symlink creation during lun shutdown
In reply to Nicholas A. BellingerFrom: Nicholas Bellinger <[email protected]>
commit 49cb77e297dc611a1b795cfeb79452b3002bd331 upstream.
This patch closes a race between se_lun deletion during configfs unlink in target_fabric_port_unlink() -> core_dev_del_lun() -> core_tpg_remove_lun(), when transport_clear_lun_ref() blocks waiting for percpu_ref RCU grace period to finish, but a new NodeACL mappedlun is added before the RCU grace period has completed.
This can happen in target_fabric_mappedlun_link() because it only checks for se_lun->lun_se_dev, which is not cleared until after transport_clear_lun_ref() percpu_ref RCU grace period finishes.
This bug originally manifested as NULL pointer dereference OOPsen in target_stat_scsi_att_intr_port_show_attr_dev() on v4.1.y code, because it dereferences lun->lun_se_dev without a explicit NULL pointer check.
In post v4.1 code with target-core RCU conversion, the code in target_stat_scsi_att_intr_port_show_attr_dev() no longer uses se_lun->lun_se_dev, but the same race still exists.
To address the bug, go ahead and set se_lun>lun_shutdown as early as possible in core_tpg_remove_lun(), and ensure new NodeACL mappedlun creation in target_fabric_mappedlun_link() fails during se_lun shutdown.
--- drivers/target/target_core_fabric_configfs.c | 5 +++++ drivers/target/target_core_tpg.c | 3 +++ include/target/target_core_base.h | 1 + 3 files changed, 9 insertions(+)
drivers/target/target_core_fabric_configfs.c +5 -0
@@ -98,6 +98,11 @@ static int target_fabric_mappedlun_link( "_tpg does not exist\n");return -EINVAL ; } +if (lun->lun_shutdown) { +pr_err ("Unable to create mappedlun symlink because" +" lun->lun_shutdown=true\n" ); +return -EINVAL ; + } se_tpg = lun->lun_sep->sep_tpg; nacl_ci = &lun_acl_ci->ci_parent->ci_group->cg_item;
drivers/target/target_core_tpg.c +3 -0
@@ -883,6 +883,8 @@ void core_tpg_remove_lun(struct se_portal_group *tpg, struct se_lun *lun) { + lun->lun_shutdown = true; +core_clear_lun_from_tpg (lun, tpg);transport_clear_lun_ref (lun);
@@ -890,6 +892,7 @@ void core_tpg_remove_lun(spin_lock (&tpg->tpg_lun_lock); lun->lun_status =TRANSPORT_LUN_STATUS_FREE ; + lun->lun_shutdown = false;spin_unlock (&tpg->tpg_lun_lock);percpu_ref_exit (&lun->lun_ref);
include/target/target_core_base.h +1 -0
@@ -724,6 +724,7 @@ struct se_lun {u32 lun_access;u32 lun_flags;u32 unpacked_lun; +bool lun_shutdown;atomic_t lun_acl_count;spinlock_t lun_acl_lock;spinlock_t lun_sep_lock;
Signature · 1 line
1.8.5.3
PATCH 4/7 iscsi-target: Always wait for kthread_should_stop() before kthread exit
In reply to Nicholas A. BellingerFrom: Jiang Yi <[email protected]>
commit 5e0cf5e6c43b9e19fc0284f69e5cd2b4a47523b0 upstream.
There are three timing problems in the kthread usages of iscsi_target_mod:
- np_thread of struct iscsi_np
- rx_thread and tx_thread of struct iscsi_conn
In iscsit_close_connection(), it calls
send_sig(SIGINT, conn->tx_thread, 1);
kthread_stop(conn->tx_thread);
In conn->tx_thread, which is iscsi_target_tx_thread(), when it receive SIGINT the kthread will exit without checking the return value of kthread_should_stop().
So if iscsi_target_tx_thread() exit right between send_sig(SIGINT...) and kthread_stop(...), the kthread_stop() will try to stop an already stopped kthread.
This is invalid according to the documentation of kthread_stop().
(Fix -ECONNRESET logout handling in iscsi_target_tx_thread and
early iscsi_target_rx_thread failure case - nab)
--- drivers/target/iscsi/iscsi_target.c | 28 ++++++++++++++++++++++------ drivers/target/iscsi/iscsi_target_erl0.c | 6 +++++- drivers/target/iscsi/iscsi_target_erl0.h | 2 +- drivers/target/iscsi/iscsi_target_login.c | 4 ++++ 4 files changed, 32 insertions(+), 8 deletions(-)
drivers/target/iscsi/iscsi_target.c +22 -6
@@ -3967,6 +3967,8 @@ int iscsi_target_tx_thread(void *arg) {int ret =0 ;struct iscsi_conn *conn = arg; +bool conn_freed = false; +/* * Allow ourselves to be interrupted by SIGINT so that a * connection recovery / failure event can be triggered externally.
@@ -3992,12 +3994,14 @@ get_immediate: goto transport_err; ret =iscsit_handle_response_queue (conn); -if (ret ==1 ) +if (ret ==1 ) { goto get_immediate; -else if (ret == -ECONNRESET ) + }else if (ret == -ECONNRESET ) { + conn_freed = true; goto out; -else if (ret <0 ) + }else if (ret <0 ) { goto transport_err; + } } transport_err:
@@ -4007,8 +4011,13 @@ transport_err:* responsible for cleaning up the early connection failure. */ if (conn->conn_state !=TARG_CONN_STATE_IN_LOGIN ) -iscsit_take_action_for_connection_exit (conn); +iscsit_take_action_for_connection_exit (conn, &conn_freed); out: +if (!conn_freed) { +while (!kthread_should_stop ()) { +msleep (100 ); + } + }return 0 ; }
@@ -4115,6 +4124,7 @@ int iscsi_target_rx_thread(void *arg)u32 checksum =0 , digest =0 ;struct iscsi_conn *conn = arg;struct kvec iov; +bool conn_freed = false;/* * Allow ourselves to be interrupted by SIGINT so that a * connection recovery / failure event can be triggered externally.
@@ -4126,7 +4136,7 @@ int iscsi_target_rx_thread(void *arg)*/ rc =wait_for_completion_interruptible (&conn->rx_login_comp);if (rc <0 ||iscsi_target_check_conn_state (conn)) -return 0 ; + goto out;if (conn->conn_transport->transport_type ==ISCSI_INFINIBAND ) {struct completion comp;
@@ -4211,7 +4221,13 @@ int iscsi_target_rx_thread(void *arg) transport_err:if (!signal_pending (current))atomic_set (&conn->transport_failed,1 ); -iscsit_take_action_for_connection_exit (conn); +iscsit_take_action_for_connection_exit (conn, &conn_freed); +out: +if (!conn_freed) { +while (!kthread_should_stop ()) { +msleep (100 ); + } + }return 0 ; }
drivers/target/iscsi/iscsi_target_erl0.c +5 -1
@@ -930,8 +930,10 @@ static void iscsit_handle_connection_cleanup(struct iscsi_conn *conn) } } -void iscsit_take_action_for_connection_exit (struct iscsi_conn *conn) +void iscsit_take_action_for_connection_exit (struct iscsi_conn *conn,bool *conn_freed) { + *conn_freed = false; +spin_lock_bh (&conn->state_lock);if (atomic_read (&conn->connection_exit)) {spin_unlock_bh (&conn->state_lock);
@@ -942,6 +944,7 @@ void iscsit_take_action_for_connection_exit(struct iscsi_conn *conn)if (conn->conn_state ==TARG_CONN_STATE_IN_LOGOUT ) {spin_unlock_bh (&conn->state_lock);iscsit_close_connection (conn); + *conn_freed = true;return ; }
@@ -955,6 +958,7 @@ void iscsit_take_action_for_connection_exit(struct iscsi_conn *conn)spin_unlock_bh (&conn->state_lock);iscsit_handle_connection_cleanup (conn); + *conn_freed = true; }/*
drivers/target/iscsi/iscsi_target_erl0.h +1 -1
@@ -9,7 +9,7 @@ extern int iscsit_stop_time2retain_timer(struct iscsi_session *);extern void iscsit_connection_reinstatement_rcfr (struct iscsi_conn *);extern void iscsit_cause_connection_reinstatement (struct iscsi_conn *,int );extern void iscsit_fall_back_to_erl0 (struct iscsi_session *); -extern void iscsit_take_action_for_connection_exit (struct iscsi_conn *); +extern void iscsit_take_action_for_connection_exit (struct iscsi_conn *,bool *);extern int iscsit_recover_from_unknown_opcode (struct iscsi_conn *);#endif /*** ISCSI_TARGET_ERL0_H ***/
drivers/target/iscsi/iscsi_target_login.c +4 -0
@@ -1507,5 +1507,9 @@ int iscsi_target_login_thread(void *arg)break ; } +while (!kthread_should_stop ()) { +msleep (100 ); + } +return 0 ; }
Signature · 1 line
1.8.5.3
PATCH 5/7 iscsi-target: Fix delayed logout processing greater than SECONDS_FOR_LOGOUT_COMP
In reply to Nicholas A. BellingerFrom: Nicholas Bellinger <[email protected]>
commit 105fa2f44e504c830697b0c794822112d79808dc upstream.
This patch fixes a BUG() in iscsit_close_session() that could be triggered when iscsit_logout_post_handler() execution from within tx thread context was not run for more than SECONDS_FOR_LOGOUT_COMP (15 seconds), and the TCP connection didn't already close before then forcing tx thread context to automatically exit.
This would manifest itself during explicit logout as:
[33206.974254] 1 connection(s) still exist for iSCSI session to iqn.1993-08.org.debian:01:3f5523242179 [33206.980184] INFO: NMI handler (kgdb_nmi_handler) took too long to run: 2100.772 msecs [33209.078643] ------------[ cut here ]------------ [33209.078646] kernel BUG at drivers/target/iscsi/iscsi_target.c:4346!
Normally when explicit logout attempt fails, the tx thread context exits and iscsit_close_connection() from rx thread context does the extra cleanup once it detects conn->conn_logout_remove has not been cleared by the logout type specific post handlers.
To address this special case, if the logout post handler in tx thread context detects conn->tx_thread_active has already been cleared, simply return and exit in order for existing iscsit_close_connection() logic from rx thread context do failed logout cleanup.
--- drivers/target/iscsi/iscsi_target.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/target/iscsi/iscsi_target.c +8 -2
@@ -4605,8 +4605,11 @@ static void iscsit_logout_post_handler_closesession(* always sleep waiting for RX/TX thread shutdown to complete * within iscsit_close_connection(). */ -if (conn->conn_transport->transport_type ==ISCSI_TCP ) +if (conn->conn_transport->transport_type ==ISCSI_TCP ) { sleep =cmpxchg (&conn->tx_thread_active, true, false); +if (!sleep) +return ; + }atomic_set (&conn->conn_logout_remove,0 );complete (&conn->conn_logout_comp);
@@ -4622,8 +4625,11 @@ static void iscsit_logout_post_handler_samecid( {int sleep =1 ; -if (conn->conn_transport->transport_type ==ISCSI_TCP ) +if (conn->conn_transport->transport_type ==ISCSI_TCP ) { sleep =cmpxchg (&conn->tx_thread_active, true, false); +if (!sleep) +return ; + }atomic_set (&conn->conn_logout_remove,0 );complete (&conn->conn_logout_comp);
Signature · 1 line
1.8.5.3
PATCH 6/7 iser-target: Avoid isert_conn->cm_id dereference in isert_login_recv_done
In reply to Nicholas A. BellingerFrom: Nicholas Bellinger <[email protected]>
commit fce50a2fa4e9c6e103915c351b6d4a98661341d6 upstream.
This patch fixes a NULL pointer dereference in isert_login_recv_done() of isert_conn->cm_id due to isert_cma_handler() -> isert_connect_error() resetting isert_conn->cm_id = NULL during a failed login attempt.
As per Sagi, we will always see the completion of all recv wrs posted on the qp (given that we assigned a ->done handler), this is a FLUSH error completion, we just don't get to verify that because we deref NULL before.
The issue here, was the assumption that dereferencing the connection cm_id is always safe, which is not true since:
commit 4a579da2586bd3b79b025947ea24ede2bbfede62
Author: Sagi Grimberg <[email protected]>
Date: Sun Mar 29 15:52:04 2015 +0300
iser-target: Fix possible deadlock in RDMA_CM connection error
As I see it, we have a direct reference to the isert_device from isert_conn which is the one-liner fix that we actually need like we do in isert_rdma_read_done() and isert_rdma_write_done().
--- drivers/infiniband/ulp/isert/ib_isert.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/ulp/isert/ib_isert.c +1 -1
@@ -1586,7 +1586,7 @@ isert_rcv_completion(struct iser_rx_desc *desc, struct isert_conn *isert_conn, u32 xfer_len) { -struct ib_device *ib_dev = isert_conn->cm_id->device; +struct ib_device *ib_dev = isert_conn->device->ib_device;struct iscsi_hdr *hdr;u64 rx_dma;int rx_buflen, outstanding;
Signature · 1 line
1.8.5.3
PATCH 7/7 Revert "target: Fix VERIFY and WRITE VERIFY command parsing"
In reply to Nicholas A. BellingerFrom: Nicholas Bellinger <[email protected]>
commit 984a9d4c40bed351a92ed31f0723a710444295da upstream.
This reverts commit 0e2eb7d12eaa8e391bf5615d4271bb87a649caaa
Author: Bart Van Assche <[email protected]>
Date: Thu Mar 30 10:12:39 2017 -0700
target: Fix VERIFY and WRITE VERIFY command parsing
This patch broke existing behaviour for WRITE_VERIFY because it dropped the original SCF_SCSI_DATA_CDB assignment for bytchk = 0 so target_cmd_size_check() no longer rejected this case, allowing an overflow case to trigger an OOPs in iscsi-target.
Since the short term and long term fixes are still being discussed, revert it for now since it's late in the merge window and try again in v4.13-rc1.
drivers/target/target_core_sbc.c
--- drivers/target/target_core_sbc.c | 71 +++++----------------------------------- 1 file changed, 9 insertions(+), 62 deletions(-)
drivers/target/target_core_sbc.c +9 -62
@@ -768,59 +768,6 @@ sbc_check_dpofua(struct se_device *dev, struct se_cmd *cmd, unsigned char *cdb)return 0 ; } -/** -* sbc_parse_verify - parse VERIFY, VERIFY_16 and WRITE VERIFY commands -* @cmd: (in) structure that describes the SCSI command to be parsed. -* @sectors: (out) Number of logical blocks on the storage medium that will be -* affected by the SCSI command. -* @bufflen: (out) Expected length of the SCSI Data-Out buffer. -*/ -static sense_reason_t sbc_parse_verify (struct se_cmd *cmd,int *sectors, -u32 *bufflen) -{ -struct se_device *dev = cmd->se_dev; -u8 *cdb = cmd->t_task_cdb; -u8 bytchk = (cdb[1 ] >>1 ) &3 ; -sense_reason_t ret; - -switch (cdb[0 ]) { -case VERIFY : -case WRITE_VERIFY : - *sectors =transport_get_sectors_10 (cdb); - cmd->t_task_lba =transport_lba_32 (cdb); -break ; -case VERIFY_16 : - *sectors =transport_get_sectors_16 (cdb); - cmd->t_task_lba =transport_lba_64 (cdb); -break ; -default : -WARN_ON_ONCE (true); -return TCM_UNSUPPORTED_SCSI_OPCODE ; - } - -if (sbc_check_dpofua (dev, cmd, cdb)) -return TCM_INVALID_CDB_FIELD ; - - ret =sbc_check_prot (dev, cmd, cdb, *sectors, true); -if (ret) -return ret; - -switch (bytchk) { -case 0 : - *bufflen =0 ; -break ; -case 1 : - *bufflen =sbc_get_size (cmd, *sectors); - cmd->se_cmd_flags |=SCF_SCSI_DATA_CDB ; -break ; -default : -pr_err ("Unsupported BYTCHK value %d for SCSI opcode %#x\n" , - bytchk, cdb[0 ]); -return TCM_INVALID_CDB_FIELD ; - } -return TCM_NO_SENSE ; -} -sense_reason_t sbc_parse_cdb (struct se_cmd *cmd,struct sbc_ops *ops) {
@@ -891,6 +838,7 @@ sbc_parse_cdb(struct se_cmd *cmd, struct sbc_ops *ops) cmd->execute_cmd = sbc_execute_rw;break ;case WRITE_10 : +case WRITE_VERIFY : sectors =transport_get_sectors_10 (cdb); cmd->t_task_lba =transport_lba_32 (cdb);
@@ -905,12 +853,6 @@ sbc_parse_cdb(struct se_cmd *cmd, struct sbc_ops *ops) cmd->execute_rw = ops->execute_rw; cmd->execute_cmd = sbc_execute_rw;break ; -case WRITE_VERIFY : - ret =sbc_parse_verify (cmd, §ors, &size); -if (ret) -return ret; - cmd->execute_cmd = sbc_execute_rw; - goto check_lba;case WRITE_12 : sectors =transport_get_sectors_12 (cdb); cmd->t_task_lba =transport_lba_32 (cdb);
@@ -1110,9 +1052,14 @@ sbc_parse_cdb(struct se_cmd *cmd, struct sbc_ops *ops)break ;case VERIFY :case VERIFY_16 : - ret =sbc_parse_verify (cmd, §ors, &size); -if (ret) -return ret; + size =0 ; +if (cdb[0 ] ==VERIFY ) { + sectors =transport_get_sectors_10 (cdb); + cmd->t_task_lba =transport_lba_32 (cdb); + }else { + sectors =transport_get_sectors_16 (cdb); + cmd->t_task_lba =transport_lba_64 (cdb); + } cmd->execute_cmd = sbc_emulate_noop; goto check_lba;case REZERO_UNIT :
Signature · 1 line
1.8.5.3