Re: [PATCH] Re: [BUG] Race condition with it_real_fn in kernel/itimer.c

From: Oleg Nesterov
Date: Thu Jun 16 2005 - 02:36:47 EST

Steven Rostedt wrote:
> So, timer_pending tests if timer->base is NULL, but here we see that
> timer->base IS NULL before the function is called, and as I have said
> earlier, the it_real_arm can be called on two CPUS simultaneously. So
> here's another patch that should fix this race condition too.
> [...]
> + /*
> + * Call del_timer_sync unconditionally, since we don't
> + * know if it is running or not. We also need to unlock
> + * the siglock so that the it_real_fn called by ksoftirqd
> + * doesn't wait for us.
> + */
> + spin_unlock(&tsk->sighand->siglock);
> + del_timer_sync(&tsk->signal->real_timer);
> + spin_lock(&tsk->sighand->siglock);

I don't think this is 100% correct. After del_timer_sync() returns another
thread can come and call do_setitimer() and re-arm the timer (because with
your patch we are dropping tsk->sighand->siglock here). So this patch does
not garantees that the timer is not queued/running after del_timer_sync(),
and the it_real_arm can be called on two CPUS simultaneously again.

There is a try_to_del_timer_sync() in the -mm tree which is suitable here:

if (try_to_del_timer_sync(&tsk->signal->real_timer) < 0) {
goto again;

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at