Skip to content

Commit

Permalink
common/ceph_timer: Pass reference to waited time on stack
Browse files Browse the repository at this point in the history
std::condition_variable::wait_until takes a const reference to a
time_point. It may access this reference after relinquishing the
mutex, creating a potential use-after-free error if the first event is
shut down.

So, just copy the time onto the stack, so we have a reference that
won't disappear.

https://tracker.ceph.com/issues/44373

Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
  • Loading branch information
adamemerson committed Mar 6, 2020
1 parent ab911b6 commit c9d4315
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/common/ceph_timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,15 @@ class timer {

if (suspended)
break;
if (schedule.empty())
if (schedule.empty()) {
cond.wait(l);
else
cond.wait_until(l, schedule.begin()->t);
} else {
// Since wait_until takes its parameter by reference, passing
// the time /in the event/ is unsafe, as it might be canceled
// while we wait.
const auto t = schedule.begin()->t;
cond.wait_until(l, t);
}
}
}

Expand Down

0 comments on commit c9d4315

Please sign in to comment.