Skip to content

Commit db6077f

Browse files
author
Nicholas Bellinger
committed
iscsi-target: Fix incorrect np->np_thread NULL assignment
When shutting down a target there is a race condition between iscsit_del_np() and __iscsi_target_login_thread(). The latter sets the thread pointer to NULL, and the former tries to issue kthread_stop() on that pointer without any synchronization. This patch moves the np->np_thread NULL assignment into iscsit_del_np(), after kthread_stop() has completed. It also removes the signal_pending() + np_state check, and only exits when kthread_should_stop() is true. Reported-by: Hannes Reinecke <[email protected]> Cc: <[email protected]> #3.12+ Signed-off-by: Nicholas Bellinger <[email protected]>
1 parent 63832aa commit db6077f

File tree

2 files changed

+1
-6
lines changed

2 files changed

+1
-6
lines changed

drivers/target/iscsi/iscsi_target.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ int iscsit_del_np(struct iscsi_np *np)
465465
*/
466466
send_sig(SIGINT, np->np_thread, 1);
467467
kthread_stop(np->np_thread);
468+
np->np_thread = NULL;
468469
}
469470

470471
np->np_transport->iscsit_free_np(np);

drivers/target/iscsi/iscsi_target_login.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,19 +1403,13 @@ static int __iscsi_target_login_thread(struct iscsi_np *np)
14031403

14041404
out:
14051405
stop = kthread_should_stop();
1406-
if (!stop && signal_pending(current)) {
1407-
spin_lock_bh(&np->np_thread_lock);
1408-
stop = (np->np_thread_state == ISCSI_NP_THREAD_SHUTDOWN);
1409-
spin_unlock_bh(&np->np_thread_lock);
1410-
}
14111406
/* Wait for another socket.. */
14121407
if (!stop)
14131408
return 1;
14141409
exit:
14151410
iscsi_stop_login_thread_timer(np);
14161411
spin_lock_bh(&np->np_thread_lock);
14171412
np->np_thread_state = ISCSI_NP_THREAD_EXIT;
1418-
np->np_thread = NULL;
14191413
spin_unlock_bh(&np->np_thread_lock);
14201414

14211415
return 0;

0 commit comments

Comments
 (0)