Skip to content

Ensure from_box works if boxed.addr() == 1 #52

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

Closed
wants to merge 1 commit into from

Conversation

dilr
Copy link

@dilr dilr commented Jul 25, 2025

SmallBox::from_box will reuse the allocation from its argument as ptr in smallbox. However, said allocation might have an address of 1, which is the INLINE_SENTINAL value.

This would cause the resulting smallbox to read from its uninitialized inline storage space when de-referenced.

Note that this problem likely cannot be triggered on a desktop OS since the first page is typically set up to segfault when read. Thus if the type is not a ZST, then the allocator won't have given out a pointer in the first page, and if the type is a ZST, then reading from the uninitialized storage space is perfectly fine behavior.

However, bare metal programs could conceivably run into this problem, so this commit causes from_box to copy from boxed into a newly created smallbox if boxed.addr() == INLINE_SENTINEL.

SmallBox::from_box will reuse the allocation from its argument as
ptr in smallbox. However, said allocation might be equal to 1,
which is the INLINE_SENTINAL value.

This would cause the resulting smallbox to read from its
uninitialized inline storage space when dereferenced.

Note that this problem likely cannot be triggered on a desktop OS
since the first page is typically set up to segfault when read.
Thus if the type is not a ZST, then the allocator won't have given
out a pointer in the first page, and if the type is a ZST,
then reading from the uninitialized storge space is perfectly fine
behavior.

However, bare metal programs could concivibly run into this
problem, so this commit causes from_box to copy from boxed into
a newly created smallbox if boxed.addr() == INLINE_SENTINEL.
@andylokandy
Copy link
Owner

I rather like to revert #45 considering this case.

@dilr
Copy link
Author

dilr commented Jul 25, 2025

That seems reasonable. I'll close this request.

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.

2 participants