aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/posix-timers.c
diff options
context:
space:
mode:
authorThomas Gleixner <tglx@linutronix.de>2007-08-22 17:01:37 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-08-22 22:52:45 -0400
commit179394af7a2baa1d0a3cb1670075310d72247d38 (patch)
treef15d4ad366b1bfa7787d6a6a809816f507c4a23a /kernel/posix-timers.c
parent928923c76b393e38e5ba1d47e843e208ceef6cf9 (diff)
posix-timers: fix deletion race
timer_delete does: lock_timer(); timer->it_process = NULL; unlock_timer(); release_posix_timer(); timer->it_process is checked in lock_timer() to prevent access to a timer, which is on the way to be deleted, but the check happens after idr_lock is dropped. This allows release_posix_timer() to delete the timer before the lock code can check the timer: CPU 0 CPU 1 lock_timer(); timer->it_process = NULL; unlock_timer(); lock_timer() spin_lock(idr_lock); timer = idr_find(); spin_lock(timer->lock); spin_unlock(idr_lock); release_posix_timer(); spin_lock(idr_lock); idr_remove(timer); spin_unlock(idr_lock); free_timer(timer); if (timer->......) Change the locking to prevent this. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel/posix-timers.c')
-rw-r--r--kernel/posix-timers.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
index 55b3761edaa9..6923ad8a5983 100644
--- a/kernel/posix-timers.c
+++ b/kernel/posix-timers.c
@@ -605,13 +605,14 @@ static struct k_itimer * lock_timer(timer_t timer_id, unsigned long *flags)
605 timr = (struct k_itimer *) idr_find(&posix_timers_id, (int) timer_id); 605 timr = (struct k_itimer *) idr_find(&posix_timers_id, (int) timer_id);
606 if (timr) { 606 if (timr) {
607 spin_lock(&timr->it_lock); 607 spin_lock(&timr->it_lock);
608 spin_unlock(&idr_lock);
609 608
610 if ((timr->it_id != timer_id) || !(timr->it_process) || 609 if ((timr->it_id != timer_id) || !(timr->it_process) ||
611 timr->it_process->tgid != current->tgid) { 610 timr->it_process->tgid != current->tgid) {
612 unlock_timer(timr, *flags); 611 spin_unlock(&timr->it_lock);
612 spin_unlock_irqrestore(&idr_lock, *flags);
613 timr = NULL; 613 timr = NULL;
614 } 614 } else
615 spin_unlock(&idr_lock);
615 } else 616 } else
616 spin_unlock_irqrestore(&idr_lock, *flags); 617 spin_unlock_irqrestore(&idr_lock, *flags);
617 618