From: Thomas Gleixner <tglx@linutronix.de>
To: Jeremy Katz <jeremy.katz@windriver.com>
Cc: linux-kernel@vger.kernel.org, Andrew Morton <akpm@osdl.org>,
Ingo Molnar <mingo@elte.hu>, Oleg Nesterov <oleg@tv-sign.ru>,
Stable Team <stable@kernel.org>
Subject: [PATCH] posix-timer: fix deletion race
Date: Tue, 17 Jul 2007 10:53:49 +0200 [thread overview]
Message-ID: <1184662429.12353.426.camel@chaos> (raw)
In-Reply-To: <Pine.LNX.4.63.0707131058390.10358@localhost.localdomain>
Jeremy Katz experienced a posix-timer related bug on 2.6.14. This is
caused by a subtle race, which is there since the original posix timer
commit and persists until today.
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>
diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
index 329ce01..c2ac6fd 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)
timr = (struct k_itimer *) idr_find(&posix_timers_id, (int) timer_id);
if (timr) {
spin_lock(&timr->it_lock);
- spin_unlock(&idr_lock);
if ((timr->it_id != timer_id) || !(timr->it_process) ||
timr->it_process->tgid != current->tgid) {
- unlock_timer(timr, *flags);
+ spin_unlock(&timr->it_lock);
+ spin_unlock_irqrestore(&idr_lock, *flags);
timr = NULL;
- }
+ } else
+ spin_unlock(&idr_lock);
} else
spin_unlock_irqrestore(&idr_lock, *flags);
next prev parent reply other threads:[~2007-07-17 8:54 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-13 18:19 POSIX timer deletion race? Jeremy Katz
2007-07-17 8:53 ` Thomas Gleixner [this message]
2007-07-17 9:57 ` [PATCH] posix-timer: fix deletion race Ingo Molnar
2007-07-17 18:29 ` Jeremy Katz
2007-07-17 13:07 ` Oleg Nesterov
2007-07-17 17:02 ` Thomas Gleixner
2007-07-17 18:39 ` Jeremy Katz
2007-07-17 20:17 ` Thomas Gleixner
2007-07-17 23:12 ` Jeremy Katz
2007-07-17 23:58 ` Jeremy Katz
2007-07-18 6:05 ` Thomas Gleixner
2007-07-18 6:58 ` Thomas Gleixner
2007-07-18 19:02 ` Jeremy Katz
2007-07-18 23:43 ` Jeremy Katz
2007-07-19 5:50 ` Thomas Gleixner
2007-07-19 19:24 ` Jeremy Katz
2007-07-18 16:11 ` Oleg Nesterov
2007-07-18 19:08 ` Jeremy Katz
2007-07-20 14:15 ` Oleg Nesterov
2007-07-24 2:07 ` Jeremy Katz
2007-07-24 14:51 ` Oleg Nesterov
2007-07-24 18:36 ` Jeremy Katz
2007-07-24 20:43 ` Oleg Nesterov
2007-07-24 21:19 ` Jeremy Katz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1184662429.12353.426.camel@chaos \
--to=tglx@linutronix.de \
--cc=akpm@osdl.org \
--cc=jeremy.katz@windriver.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=oleg@tv-sign.ru \
--cc=stable@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®