Skip to content

Conversation

workingjubilee
Copy link
Member

@workingjubilee workingjubilee commented Sep 25, 2025

As reported in #720, there is a risk that the current code, by using &mut to a struct with padding fields, interacts in ways that cause padding bytes to be written to bytes that Rust originally thought were real and initialized. If this assumption persists forward in time far enough, this could possibly cause an issue due to compiler optimizations.

This seems unlikely, but we can fix this by using MaybeUninit and then addressing the data using raw pointers only. That way, we do not have to depend on all the data being in initialized states even after calling SymFromAddrW. Except for the specific fields we read, of course.

Fixes #720

@workingjubilee workingjubilee force-pushed the address-dbghelp-soundness-risks branch 3 times, most recently from cd50846 to f9ae50a Compare September 25, 2025 23:28
As reported in rust-lang#720, there is a risk that the
current code, by using &mut to a struct with padding fields,
interacts in ways that cause padding bytes to be written to bytes
that Rust originally thought were real and initialized.
If this assumption persists forward in time far enough,
this could possibly cause an issue due to compiler optimizations.

This seems unlikely, but we can fix this by using MaybeUninit and then
addressing the data using raw pointers only. That way, we do not have
to depend on all the data being in initialized states even after calling
SymFromAddrW. Except for the specific fields we read, of course.
Copy link
Member

@ChrisDenton ChrisDenton 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. I made a few comments but nothing that's particularly essential to resolve so I'd be happy for this to be merged as-is.

@workingjubilee workingjubilee force-pushed the address-dbghelp-soundness-risks branch from 605761d to 06dca9a Compare September 26, 2025 01:35
@ChrisDenton ChrisDenton merged commit a405950 into rust-lang:master Sep 26, 2025
40 checks passed
@workingjubilee workingjubilee deleted the address-dbghelp-soundness-risks branch September 26, 2025 01:38
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.

Soundess bug: &mut reference exposes uninitialized bytes
2 participants