timeout/untimeout race conditions/crash [patch]

Alfred Perlstein alfred at freebsd.org
Mon Mar 17 13:11:30 PDT 2008


* John Baldwin <jhb at freebsd.org> [080317 09:43] wrote:
> 
> This is not a bug.  Don't use untimeout(9) as it is not guaranteed to be 
> reliable.  Instead, use callout_*().  Your patch doesn't solve any races as 
> the driver detach routine needs to use callout_drain() and not just 
> callout_stop/untimeout anyways.  Fix your broken drivers.

I understand that some old Giant locked code can issue timeout/untimeout
without Giant held, which would certainly cause this issue to happen
and is uncorrectable, however, this is with completely Giant locked
code.

We are not trying to use timeout(9) for mpsafe code, this is old
code and relies upon Giant. 

Giant locked code should be timeout/untimeout safe.  As explained
in my email, there exists a condition where the Giant locked code
can have a timer fire even though proper Giant locking is observed.

For a Giant locked subsystem, one should be able to have the following
code work:

mtx_lock(&Giant);	/* formerly spl higher than softclock */
untimeout(&func, arg, &sc->handle);
free(sc);
mtx_unlock(&Giant);	/* formerly splx() */

Normally splsoftclock would completely block the timeout from firing
and this sort of code would be safe.  It is no longer safe due to
a BUG in the way that Giant is used.

Please reread the original mail to better understand the synopsis
of the problem.

thank you,
-Alfred


More information about the freebsd-stable mailing list