timeout/untimeout race conditions/crash [patch]

John Baldwin jhb at freebsd.org
Mon Mar 17 15:29:51 PDT 2008


On Monday 17 March 2008 04:10:14 pm Alfred Perlstein wrote:
> * 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.

Hmm.  My worry is about leaving the callout structure around while invoking 
the timeout routine itself, but it is already off the callwheel so it 
shouldn't be visible via untimeout() to any other code.  I guess the patch is 
ok, but I'll be happy when we can axe timeout/untimeout altogether.

-- 
John Baldwin


More information about the freebsd-stable mailing list