Microsoft’s AI Scanner Uncovers Rust Memory Safety Bugs in Stable Code
Rust’s memory safety guarantees depend on a boundary that’s easy to overlook: its standard library uses unsafe code internally, and safe APIs must keep that code sound under every valid use. Microsoft researchers found several places where that boundary could fail, including two issues in stable Rust and a process-handling bug that had persisted for nearly 11 years.
The investigation used Hyenas, an AI-powered vulnerability scanning system developed by Microsoft’s FORGE Lab. Hyenas is the lab’s research version of codename MDASH, Microsoft’s agentic vulnerability discovery system. Researchers used the tool to identify potential problems, then inspected the code, reproduced findings, assessed their impact, and reported them to Rust maintainers.
Three ways unsafe internals can fail
The findings fell into three broad patterns: unsafe code that doesn’t account for panics, code that relies on user-provided implementations behaving as expected, and assumptions about operating system or C library behavior that don’t hold in every case.
One panic-safety flaw affected MapWindows::clone. The implementation allocated a buffer and began filling it by calling a user-provided clone operation. If that operation panicked before initialization finished, Rust’s unwinding process could run the buffer’s destructor, which might read uninitialized memory. The reported fix prevents destruction of the buffer until its contents are fully initialized.
A separate issue involved str::replace and a custom implementation of Rust’s nightly Pattern trait. The replacement code assumed the implementation would provide an ASCII byte. A custom implementation could violate that assumption, leading the function to create invalid UTF-8. Later string operations could then trigger undefined behavior.
These cases highlight the contract behind safe library APIs: callers shouldn’t be able to cause undefined behavior through valid safe code, even when the library’s internal implementation uses operations the compiler can’t verify.
Two system-level flaws affect stable Rust
The oldest reported issue involved process::exit. When a child thread called the function, the runtime could remove the main thread’s alternate signal stack while that thread was still running. If the main thread later overflowed its stack, the operating system might fail to deliver the signal Rust uses for stack-overflow handling, causing a segmentation fault instead.
Microsoft said it found no reliable exploitation path under the conditions it examined and considered practical exploitation unlikely. The issue had remained in the standard library for nearly 11 years.
The other stable Rust finding concerned CommandExt::exec and the process-wide environment variable array. Microsoft found that the function could modify the shared array while holding a read lock. Concurrent access could leave the environment pointer referring to freed memory.
A proposed fix was under review when Microsoft published its findings. It avoids changing the shared array by calling execve directly. The process::exit and CommandExt::exec issues both affect stable Rust.
Risk depends on how programs reach the code
Microsoft described the practical risk as limited because each flaw requires unusual conditions. A standard library defect becomes a serious vulnerability only when a real program reaches the affected API in the relevant way, the researchers wrote.
The work also connects to earlier research by members of the team. Microsoft said Rudra, their static analyzer, was already examining the first two categories of weaknesses in 2021. Rust’s standard library had addressed panic-safety issues as early as 2015, though similar implementation mistakes continue to appear.
At publication, two issues reported by the team remained open, alongside related reports from other researchers and fixes still under review. Microsoft said findings from this work can inform Microsoft Perception, its multi-agent security system, and help improve MDASH, which brings agent-based vulnerability discovery into Microsoft Defender. Its Web App Pen Test Agent, for example, can use MDASH findings to guide testing, assess exploitability against live applications, and support remediation.
The practical lesson for Rust users is that safe language features still rely on careful library internals and precise contracts at system boundaries. Automated discovery can help locate weak points; reproducing and assessing them determines which ones matter to the software people actually run.