Subject: [PATCH 07/21] net: pktgen: fix race between pktgen_thread_worker() and kthread_stop()

From: Oleg Nesterov <[email-masked]>
Date: Wed, 8 Jul 2015 21:42:11 +0200

[ Upstream commit fecdf8be2d91e04b0a9a4f79ff06499a36f5d14f ]

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 <[email-masked]>
Reported-by: Jan Stancek <[email-masked]>
Reported-by: Marcelo Leitner <[email-masked]>
Signed-off-by: David S. Miller <[email-masked]>
---
 net/core/pktgen.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index a104ba3..cea4734 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -3423,8 +3423,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);
-- 
2.1.0