Skip to content

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

Closed
dilr wants to merge 1 commit into
andylokandy:masterfrom
dilr:fix_frombox
Closed

Ensure from_box works if boxed.addr() == 1#52
dilr wants to merge 1 commit into
andylokandy:masterfrom
dilr:fix_frombox

Conversation

@dilr

@dilr dilr commented Jul 25, 2025

Copy link
Copy Markdown

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
Copy Markdown
Owner

I rather like to revert #45 considering this case.

@dilr

dilr commented Jul 25, 2025

Copy link
Copy Markdown
Author

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