-
-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix the caches mutating a deque node through a NonNull
pointer derived from a shared reference
#259
Conversation
from a shared ref Add a test to `deque` module to reproduce the bug.
from a shared ref - Add `Deque::peek_front_ptr` method that returns a `NonNull` pointer (instead of a shared reference) to the front node. - Remove `DeqNode::next` method. - Add `DeqNode::next_ptr` _function_ that returns a `NonNull` pointers to the next node. - Add `Deque::move_front_to_back` method that moves the front node to the back of the deque, instead of moving the node through a shared reference to the node.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merging.
I was wrong. A Moka v0.9.6 user reported segmentation fault. I analyzed a core dump and it seems it was caused by this bug: I backported this fix to v0.9.8 and also plan to backport to v0.10.x. |
Fix the caches mutating a deque node through a `NonNull` pointer derived from a shared reference.
Fix the caches mutating a deque node through a `NonNull` pointer derived from a shared reference.
I found bugs in the
sync
andfuture
caches; they were mutating an internal deque node through aNonNull
pointer derived from a shared ref&
. This PR fixes these bugs.These bugs already existed from very early version of Moka but I could not find them until now. Miri tests could have helped to find them, but we are not running Miri tests on the
sync_base
module who has the bugs. This is because the module uses some FFI calls that Miri does not support.In commit 03c75ff (included in this PR), I added a test to
deque
module to reproduce the bug and confirmed that Miri can catch it.This PR fixes the bugs by not using a shared reference in these cases:
Deque::peek_front_ptr
method, which is similar to existingpeek_front
method. It returns aNonNull
pointer to the front node, instead of a shared reference.DeqNode::next
method that returns a shared reference to the next node.DeqNode::next_ptr
function that returns aNonNull
pointers to the next node.Deque::move_front_to_back
method that moves the front node to the back of the deque, instead of moving the node through a shared reference to the node.sync_base
module to use above methods when they need to mutate aDeqNode
.This PR also adds the test mentioned above to
deque
module to ensure that the bugs are fixed.I do not know if there were actual impacts of the bugs. I think the bugs were not triggered because the code never accesses the shared reference again after the mutable reference is created. Also the code is executed only when some corner cases are met.