lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:	Thu,  1 Dec 2011 13:55:08 +0200
From:	Ido Yariv <ido@...ery.com>
To:	Thomas Gleixner <tglx@...utronix.de>, linux-kernel@...r.kernel.org
Cc:	Ido Yariv <ido@...ery.com>
Subject: [PATCH] irq: Fix race condition when stopping the irq thread

In irq_wait_for_interrupt(), the should_stop member is verified before
setting the task's state to TASK_INTERRUPTIBLE and calling schedule().
In case kthread_stop sets should_stop and wakes up the process after
should_stop is checked by the irq thread but before the task's state is
changed, the irq thread might never exit:

kthread_stop                            irq_wait_for_interrupt
------------                            ----------------------

                                        ...
...                                     while (!kthread_should_stop()) {
kthread->should_stop = 1;
wake_up_process(k);
wait_for_completion(&kthread->exited);
...
                                            set_current_state(TASK_INTERRUPTIBLE);

                                            ...

                                            schedule();
                                        }
                                        ...

Fix this by checking if the thread should stop after modifying the
task's state.

Signed-off-by: Ido Yariv <ido@...ery.com>
Cc: stable@...nel.org
---
 kernel/irq/manage.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index 0e2b179..3194d5e 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -631,7 +631,11 @@ static int irq_wait_for_interrupt(struct irqaction *action)
 			__set_current_state(TASK_RUNNING);
 			return 0;
 		}
-		schedule();
+
+		if (!kthread_should_stop())
+			schedule();
+		else
+			__set_current_state(TASK_RUNNING);
 	}
 	return -1;
 }
-- 
1.7.7.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ