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

Fix aliasing bugs revealed by Tree Borrows #889

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

JoJoDeveloping
Copy link

@JoJoDeveloping JoJoDeveloping commented Aug 29, 2024

This PR fixes some aliasing bugs caused by improper usage of shared and mutable references intermixed with raw pointer accesses. These have been discovered by running the testsuite under Tree Borrows, a new aliasing model for Rust and a potential replacement for Stacked Borrows. While TB is in general more lenient than SB, there are some cases where it is more strict due to SB relying on gross hacks, which have been removed from TB.

Turns out that deno_core relied on such hacks. The problem is with the DynFutureInfoErased, which has arbitrary data that is being modified by a future while other references to it are held in the runtime. To prevent this, that is put into an UnsafeCell which makes such modifications allowed.

But UnsafeCell only ensures that shared references can be modified without causing UB, it does not permit mutable references to be aliased. Thus, one should take care not to create mutable references here. The easiest way of doing this is to remove the implementation of DerefMut and AsMut for ArenaBox<T>, and work around the few cases where that leads to breakage (by using raw pointers, which is also more robust in terms of the aliasing model).

This fixes #884. See that issue for more information.

I have not audited the entire crate, so it is possible that other TB bugs are lurking elsewhere; especially in the parts that Miri can currently not test properly. But this at least makes all the test that could work, do work.

@CLAassistant
Copy link

CLAassistant commented Aug 29, 2024

CLA assistant check
All committers have signed the CLA.

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.91%. Comparing base (0c7f83e) to head (3f60789).
Report is 113 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #889      +/-   ##
==========================================
+ Coverage   81.43%   81.91%   +0.47%     
==========================================
  Files          97       98       +1     
  Lines       23877    24928    +1051     
==========================================
+ Hits        19445    20419     +974     
- Misses       4432     4509      +77     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@devsnek devsnek left a comment

Choose a reason for hiding this comment

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

i don't have any context on this code specifically but the overall changes seem good for an arena-shaped api

@dsherret dsherret removed their request for review September 23, 2024 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tree Borrows support
4 participants