diff mbox

[1/2] net: pktgen: fix race between pktgen_thread_worker() and kthread_stop()

Message ID 20150708194211.GA26552@redhat.com
State Accepted, archived
Delegated to: David Miller
Headers show

Commit Message

Oleg Nesterov July 8, 2015, 7:42 p.m. UTC
pktgen_thread_worker() is obviously racy, kthread_stop() can come
between the kthread_should_stop() check and set_current_state().

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Reported-by: Jan Stancek <jstancek@redhat.com>
Reported-by: Marcelo Leitner <mleitner@redhat.com>
---
 net/core/pktgen.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
diff mbox

Patch

diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index 508155b..043ea18 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -3490,8 +3490,10 @@  static int pktgen_thread_worker(void *arg)
 	pktgen_rem_thread(t);
 
 	/* Wait for kthread_stop */
-	while (!kthread_should_stop()) {
+	for (;;) {
 		set_current_state(TASK_INTERRUPTIBLE);
+		if (kthread_should_stop())
+			break;
 		schedule();
 	}
 	__set_current_state(TASK_RUNNING);