• Brian King's avatar
    [PATCH] sg: Fix oops of sg_cmd_done and sg_release race · fad44d87
    Brian King authored
    The following patch fixes a race condition in sg of sg_cmd_done racing
    with sg_release. I've seen this bug hit several times on test machines
    and the following patch fixes it. The race is that if srp->done is set
    and the waiting thread gets a spurious wakeup immediately afterwards,
    then the waiting thread can end up executing and completing, then getting
    closed, freeing sfp before the wake_up_interruptible is called, which
    then will result in an oops. The oops is fixed by locking around the
    setting srp->done to 1 and the wake_up, and also locking around the
    checking of srp->done, which guarantees that the wake_up_interruptible
    will always occur before the sleeping thread gets a chance to run.
    Signed-off-by: default avatarBrian King <brking@us.ibm.com>
    Signed-off-by: default avatarJames Bottomley <James.Bottomley@SteelEye.com>
    fad44d87
sg.c 83.9 KB