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

Check page capacity before obtaining base pointer #4731

Merged
merged 1 commit into from
Jun 1, 2022

Conversation

djkoloski
Copy link
Contributor

This doesn't cause any issues in practice because this is a private API that is only used in ways that cannot trigger UB. Indexing into slots is not sound until after we've asserted that the page is allocated, since that aliases the first slot which may not be allocated. This PR also switches to using as_ptr to obtain the base pointer for clarity.

Motivation

While reviewing an upgrade of tokio for Fuchsia, we identified a potential soundness issue in Slots::index_for. In the future, changes to the uses of the structure could cause UB.

Solution

The assertion that the page is not empty has been moved earlier in the function and the method for getting a pointer to the first Vec element has been changed from &slots[0] as *const _ to slots.as_ptr() which was stabilized in 1.37 and meets MSRV.

This doesn't cause any issues in practice because this is a private API
that is only used in ways that cannot trigger UB. Indexing into `slots`
is not sound until after we've asserted that the page is allocated,
since that aliases the first slot which may not be allocated. This PR
also switches to using `as_ptr` to obtain the base pointer for clarity.
@Darksonn Darksonn added the A-tokio Area: The main tokio crate label Jun 1, 2022
Copy link
Contributor

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@Darksonn Darksonn merged commit cc6c2f4 into tokio-rs:master Jun 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants