Skip to content
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

Work around UB in LMDB bindings #6211

Merged
merged 1 commit into from
Aug 1, 2024

Conversation

michaelsproul
Copy link
Member

Issue Addressed

Fix a crazy memory corruption bug in the LMDB slasher impl.

Proposed Changes

Copy the contents of the cursor's value prior to returning it, so that LMDB can't mutate the data being pointed to when .delete_current() is called.

Additional Info

This possibly explains the strange behaviour seen on some slasher nodes:

The bug had existed latently for a long time, but only now became executable with the refactor in:

@michaelsproul michaelsproul added bug Something isn't working ready-for-review The code is ready for review v5.3.0 Q3 2024 release with database changes! labels Aug 1, 2024
@michaelsproul
Copy link
Member Author

Thanks @jimmygchen for helping debug this.

I'll have another follow-up PR that fixes the file descriptor leak in the iterated tests. I want to keep it separate from this PR because it involves unsafe.

Copy link
Member

@jimmygchen jimmygchen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@jimmygchen jimmygchen added ready-for-merge This PR is ready to merge. and removed ready-for-review The code is ready for review labels Aug 1, 2024
@jimmygchen
Copy link
Member

Nice, let's deploy this fix to our testnet slasher.

@jimmygchen
Copy link
Member

@mergify queue

Copy link

mergify bot commented Aug 1, 2024

queue

✅ The pull request has been merged automatically

The pull request has been merged automatically at 0bb2386

@mergify mergify bot merged commit 0bb2386 into sigp:release-v5.3.0 Aug 1, 2024
28 checks passed
@michaelsproul michaelsproul deleted the fix-slasher branch August 1, 2024 08:00
@michaelsproul
Copy link
Member Author

For reference, I think the exact type of UB triggered was:

Mutating immutable bytes. All bytes inside a const item are immutable. The bytes owned by an immutable binding are immutable, unless those bytes are part of an UnsafeCell.

From https://doc.rust-lang.org/reference/behavior-considered-undefined.html

AgeManning pushed a commit to AgeManning/lighthouse that referenced this pull request Sep 3, 2024
* Work around UB in LMDB bindings
chong-he pushed a commit to chong-he/lighthouse that referenced this pull request Nov 26, 2024
* Work around UB in LMDB bindings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ready-for-merge This PR is ready to merge. v5.3.0 Q3 2024 release with database changes!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants