]> git.kernelconcepts.de Git - karo-tx-linux.git/commit
sunrpc/cache: remove races with queuing an upcall.
authorNeilBrown <neilb@suse.de>
Thu, 13 Jun 2013 02:53:42 +0000 (12:53 +1000)
committerJ. Bruce Fields <bfields@redhat.com>
Mon, 1 Jul 2013 21:42:53 +0000 (17:42 -0400)
commitf9e1aedc6c79f18bb56caa3735b94217c4ec1e0c
tree41ccb179f3d71ded6d035f3bc292f752c32f6995
parentd08d32e6e5c0fee127d3b20d70f5b59d8af0a261
sunrpc/cache: remove races with queuing an upcall.

We currently queue an upcall after setting CACHE_PENDING,
and dequeue after clearing CACHE_PENDING.
So a request should only be present when CACHE_PENDING is set.

However we don't combine the test and the enqueue/dequeue in
a protected region, so it is possible (if unlikely) for a race
to result in a request being queued without CACHE_PENDING set,
or a request to be absent despite CACHE_PENDING.

So: include a test for CACHE_PENDING inside the regions of
enqueue and dequeue where queue_lock is held, and abort
the operation if the value is not as expected.

Also remove the early 'return' from cache_dequeue() to ensure that it
always removes all entries: As there is no locking between setting
CACHE_PENDING and calling sunrpc_cache_pipe_upcall it is not
inconceivable for some other thread to clear CACHE_PENDING and then
someone else to set it and call sunrpc_cache_pipe_upcall, both before
the original threads completed the call.

With this, it perfectly safe and correct to:
 - call cache_dequeue() if and only if we have just
   cleared CACHE_PENDING
 - call sunrpc_cache_pipe_upcall() (via cache_make_upcall)
   if and only if we have just set CACHE_PENDING.

Reported-by: Bodo Stroesser <bstroesser@ts.fujitsu.com>
Signed-off-by: NeilBrown <neilb@suse.de>
Signed-off-by: Bodo Stroesser <bstroesser@ts.fujitsu.com>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
net/sunrpc/cache.c