kernel - Fix rare token overwrite race
authorMatthew Dillon <dillon@apollo.backplane.com>
Sat, 25 Sep 2010 23:10:48 +0000 (16:10 -0700)
committerMatthew Dillon <dillon@apollo.backplane.com>
Sat, 25 Sep 2010 23:10:48 +0000 (16:10 -0700)
commitb528f10fca490702489154b515758fc09439a0aa
tree32d5fa2d89034cc64b40c9c014e9fb6e4b802d71
parent955b4283c05a07883e5a746ab0061be4b0946553
kernel - Fix rare token overwrite race

td_toks_stop was being decremented prior to releasing the token reference
and cleaning up the optional mp lock.  This left a very small
one-instruction opening where the following sequence of events could
occur:

  * While releasing the ref in 'if (tok->t_ref == ref) tok->t_ref = NULL;'
    a fast interrupt could come along, acquire a token reusing our ref,
    then release it.

  * A thread on another cpu then successfully acquires the now released
    token.

  * The fast interrupt returns our interrupted thread resumes with the
    execution of 'tok->t_ref = NULL;'.

  * The other thread asserts on the missing token ref or otherwise performs
    actions which assume the token is still held when it is not due to
    the first thread blowing it up.

Reported-by: Francois Tigeot <ftigeot@wolfpond.org>
sys/kern/lwkt_token.c