From: Oleg Nesterov Date: Wed, 8 Jul 2015 19:42:11 +0000 (+0200) Subject: net: pktgen: fix race between pktgen_thread_worker() and kthread_stop() X-Git-Tag: v4.1.9~39 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=fd08e0ccaa649064ca0df99eaadb58199be41970;p=users%2Fjedix%2Flinux-maple.git net: pktgen: fix race between pktgen_thread_worker() and kthread_stop() [ 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 Reported-by: Jan Stancek Reported-by: Marcelo Leitner Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- diff --git a/net/core/pktgen.c b/net/core/pktgen.c index 508155b283ddc..043ea1867d0f0 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);