nfsd: Fix slot wake up race in the nfsv4.1 callback code
Subsystems (2)
PATCH 1/1 nfsd: Fix slot wake up race in the nfsv4.1 callback code
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().
--- fs/nfsd/nfs4callback.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
fs/nfsd/nfs4callback.c +6 -2
@@ -774,8 +774,12 @@ static bool nfsd41_cb_get_slot(struct nfs4_client *clp, struct rpc_task *task) {if (test_and_set_bit (0 , &clp->cl_cb_slot_busy) !=0 ) {rpc_sleep_on (&clp->cl_cb_waitq, task,NULL ); -dprintk ("%s slot is busy\n" , __func__); -return false; +/* Race breaker */ +if (test_and_set_bit (0 , &clp->cl_cb_slot_busy) !=0 ) { +dprintk ("%s slot is busy\n" , __func__); +return false; + } +rpc_wake_up_queued_task (&clp->cl_cb_waitq, task); }return true; }
Signature · 1 line
1.9.3
Quoted 3 lines · Trond Myklebust
The currect code for
nfsd41_cb_get_slot()andnfsd4_cb_done()has no locking in order to guarantee atomicity, and so allows for races of the form.
Makes sense, thanks. Applying for 3.18 and stable.
--b.
Quoted 41 lines
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 <[email protected]>--- fs/nfsd/nfs4callback.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)fs/nfsd/nfs4callback.c +6
-2@@ -774,8 +774,12 @@ static bool nfsd41_cb_get_slot(struct nfs4_client *clp, struct rpc_task *task) {if (test_and_set_bit (0 , &clp->cl_cb_slot_busy) !=0 ) {rpc_sleep_on (&clp->cl_cb_waitq, task,NULL ); -dprintk ("%s slot is busy\n" , __func__); -return false; +/* Race breaker */ +if (test_and_set_bit (0 , &clp->cl_cb_slot_busy) !=0 ) { +dprintk ("%s slot is busy\n" , __func__); +return false; + } +rpc_wake_up_queued_task (&clp->cl_cb_waitq, task); }return true; }Signature · 1 line
1.9.3