Skip to content

Commit

Permalink
Pipe: take a ref to existing while we are waiting
Browse files Browse the repository at this point in the history
Otherwise, if it is reaped while we are waiting, it'll be a
use-after-free.

Fixes: http://tracker.ceph.com/issues/15870
Signed-off-by: Samuel Just <sjust@redhat.com>
(cherry picked from commit b224912)
  • Loading branch information
athanatos authored and smithfarm committed May 20, 2016
1 parent b9b5f96 commit b02986f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/msg/simple/Pipe.cc
Expand Up @@ -479,13 +479,21 @@ int Pipe::accept()
* held by somebody trying to make use of the SimpleMessenger lock.
* So drop locks, wait, and retry. It just looks like a slow network
* to everybody else.
*
* We take a ref to existing here since it might get reaped before we
* wake up (see bug #15870). We can be confident that it lived until
* locked it since we held the msgr lock from _lookup_pipe through to
* locking existing->lock and checking reader_dispatching.
*/
existing->get();
pipe_lock.Unlock();
msgr->lock.Unlock();
existing->notify_on_dispatch_done = true;
while (existing->reader_dispatching)
existing->cond.Wait(existing->pipe_lock);
existing->pipe_lock.Unlock();
existing->put();
existing = nullptr;
goto retry_existing_lookup;
}

Expand Down

0 comments on commit b02986f

Please sign in to comment.