nfsd: Fix slot wake up race in the nfsv4.1 callback code
authorTrond Myklebust <trond.myklebust@primarydata.com>
Wed, 19 Nov 2014 17:47:50 +0000 (12:47 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 6 Dec 2014 23:05:49 +0000 (15:05 -0800)
commitbfa09bfcfb3a6f172f3c6c623e5b376f8e73fd15
treeb1f3c12641a8defbc36f66fc55dc8238fb789115
parent158a695a37743947958ca415fcea2dbd88ee7661
nfsd: Fix slot wake up race in the nfsv4.1 callback code

commit c6c15e1ed303ffc47e696ea1c9a9df1761c1f603 upstream.

The currect code for nfsd41_cb_get_slot() and nfsd4_cb_done() has no
locking in order to guarantee atomicity, and so allows for races of
the form.

Task 1                                  Task 2
======                                  ======
if (test_and_set_bit(0) != 0) {
                                        clear_bit(0)
                                        rpc_wake_up_next(queue)
        rpc_sleep_on(queue)
        return false;
}

This patch breaks the race condition by adding a retest of the bit
after the call to rpc_sleep_on().

Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/nfsd/nfs4callback.c