Re: [PATCH] posix-timer: fix deletion race

From: Ingo Molnar
Date: Tue Jul 17 2007 - 05:57:39 EST



* Thomas Gleixner <tglx@xxxxxxxxxxxxx> wrote:

> 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@xxxxxxxxxxxxx>

nice one! The race looks pretty narrow - Jeremy, does your Xens have
hyperthreading? (or are there any heavy SMI sources perhaps that could
open up this race.) If not then there might be some other bug lurking in
there as well.

Acked-by: Ingo Molnar <mingo@xxxxxxx>

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