Microsoft's FORGE Lab uses AI agents to find soundness bugs in Rust's standard library
On November 9, 2026, Microsoft's FORGE Lab published research on memory safety issues it found in Rust's standard library. The headline finding is uncomfortable but precise: several bugs in std and core allow code written entirely in safe Rust to trigger undefined behavior. The research used Hyenas, FORGE's frontier research version of codename MDASH, an AI-powered vulnerability-scanning system.
The result does not mean that Rust's safety model is broken. It means that the model has a boundary, and the boundary is the unsafe code inside the standard library. Rust's safe APIs are supposed to be sound: no matter how safe code uses them, undefined behavior must be impossible. When an unsafe block inside the library breaks its own contract, the safe API above it can become unsound, and the compiler cannot catch it.
That is the right way to read the research. The bugs are real, several were fixed, and a few remain open. But they are also a demonstration of how the safety contract is supposed to work: researchers find a violation, maintainers fix the design, and the library becomes harder to misuse.
Three patterns of misplaced trust
FORGE Lab groups the bugs into three patterns:
- Trusting code not to panic.
- Trusting user-provided implementations to be correct.
- Trusting the underlying system.
The patterns are useful because they are not specific to any one function. They describe the kinds of assumptions that unsafe code makes about the code around it, and they recur across the standard library.
The first pattern is about unwinding. Unsafe code often breaks an invariant temporarily, then restores it before returning. If a panic unwinds through that window, a destructor can run on a value that is not in a valid state. The second pattern is about callers. Unsafe code often calls a trait method, comparator, or closure supplied by safe code. Safe code can still be wrong, and the unsafe code has to stay sound even when it is. The third pattern is about the environment. Rust shares process-wide state with the operating system and the C library, and that state can change underneath the code.
The common thread is that unsafe code cannot trust things it does not control. The fixes tend to move the guarantee into a type, a guard, or a contract that the compiler or the runtime can enforce.
Pattern 1: trusting code not to panic
The clearest example is MapWindows::clone, reported as issue #156501. The nightly Iterator::map_windows adapter yields overlapping windows of N items. It keeps the current window in a Buffer whose destructor drops the N items starting at start. In Rust 1.97.0, Buffer::clone built the new buffer first and filled it afterward:
impl<T: Clone, const N: usize> Clone for Buffer<T, N> {
fn clone(&self) -> Self {
let mut buffer = Buffer {
buffer: [[const { MaybeUninit::uninit() }; N], [const { MaybeUninit::uninit() }; N]],
start: self.start,
};
buffer.as_uninit_array_mut().write(self.as_array_ref().clone());
buffer
}
}
After the buffer is constructed, it breaks its own invariant: its slots are uninitialized, but its destructor is already armed. The self.as_array_ref().clone() call runs the user's T::clone before the slots are written. If that call panics, unwinding drops the buffer and runs drop_in_place on N uninitialized values. FORGE's proof of concept uses only safe code: an element type whose clone always panics, which causes a crash when the destructor touches uninitialized memory.
The fix holds the new buffer in ManuallyDrop until it is fully written, so unwinding leaks the half-built buffer instead of dropping it. The lesson is broader than one function: treat every call to code you do not control, including clone, drop, comparisons, closures, and iterator methods, as a possible early exit. Either finish the work that may panic before breaking an invariant, or make the broken state safe to unwind through.
The same pattern shows up in the Allocator API. With std, an allocation failure aborts the process by default instead of unwinding, so much of the standard library's unsafe code assumes allocation never unwinds. Custom allocators can break that assumption. While the API was being stabilized, FORGE reported a place in BTreeMap::insert (issue #156490) that becomes unsound when an allocator unwinds, and others reported more (#159334, #159368, #159370). Fixing them one by one would mean auditing everything that allocates, so the stabilization, shipping in Rust 1.100 on November 12, instead requires implementors never to unwind from the trait's methods or from drop. The proposal notes that "unwinding out of many allocation-related methods was found to be a pervasive source of unsoundness."
That is a design fix, not a patch. It moves the guarantee from "every allocation site must handle an unwinding allocator" to "an allocator must not unwind," which is a contract the type system and the trait documentation can express. It is also a good example of the pattern: when a guarantee is hard to enforce at every call site, push it into the API contract.
Pattern 2: trusting user-provided implementations
The second pattern is about safe code that is nevertheless wrong. Unsafe code often calls into code its caller provides: a comparator, a trait implementation, a closure. That code is safe, but safe does not mean correct, and it can return inconsistent or plainly wrong answers.
The str::replace bug (#156491) is a clean illustration. String search APIs accept any type that implements the nightly Pattern trait, and a pattern can describe itself through as_utf8_pattern. str::replace uses that description to take a fast path when replacing one ASCII byte with another. In Rust 1.96.0, the fast path looked like this:
pub fn replace<P: Pattern>(&self, from: P, to: &str) -> String {
if let Some(from_byte) = match from.as_utf8_pattern() {
Some(Utf8Pattern::StringPattern([from_byte])) => Some(*from_byte),
Some(Utf8Pattern::CharPattern(c)) => c.as_ascii().map(|ascii_char| ascii_char.to_u8()),
_ => None,
} {
if let [to_byte] = to.as_bytes() {
return unsafe { replace_ascii(self.as_bytes(), from_byte, *to_byte) };
}
}
// ...
}
The CharPattern branch checks that the character is ASCII, but the StringPattern branch assumes that a one-byte string pattern must be ASCII. That holds for &str patterns, but StringPattern stored &[u8], and as_utf8_pattern is a safe method that any Pattern can implement. A custom pattern can report the single byte 0x80, which only appears inside multibyte UTF-8 sequences. str::replace then rewrites the continuation bytes and returns a String that is not valid UTF-8. Later string operations that rely on UTF-8 can reach undefined behavior.
The fix changed StringPattern to hold &str instead of &[u8], so the type itself guarantees UTF-8. That is the pattern: when unsafe code depends on a property of a user-provided implementation, do not take it on faith. Call the implementation once and keep the result, validate what it returns, or encode the property in a type that safe code cannot forge. If none of those work, make the trait unsafe so implementors explicitly promise to uphold it.
The join function shows that these fixes are not always complete. In 2020, FORGE reported that join trusted Borrow::borrow to return the same string on each call (CVE-2020-36323), and the fix handled strings that shrink between calls. In April 2026, the same function needed another fix (#155708): join borrows the first element twice, and if it grows on the second call, the remaining-length calculation underflows into a heap overflow. The earlier fix had never covered that path.
Others reported similar problems in the Pattern API this year. A safe Pattern can hand back a valid searcher built for a different string, and consumers such as strip_prefix_of apply its ranges to the original string unchecked, reading out of bounds (#158265). The same problem turned up in split_once (#165076) after a report that the Searcher contract does not spell out what str::split relies on (#164904). Both bugs are still open at publication.
Pattern 3: trusting the underlying system
The third pattern sits at the boundary with the operating system, where unsafe code trusts process-wide state such as signal stacks, memory mappings, and the environment. Other threads, C libraries, or the kernel can touch that state at any time.
The process::exit signal stack bug (#161018) is a good example. When a thread overflows its stack, Rust prints a clear message and aborts instead of crashing with a bare segmentation fault. That relies on a guard page at the end of each thread's stack and an alternate signal stack that the kernel switches to when it delivers the signal. The handler checks that the faulting address is inside the guard page, prints the message, and aborts.
FORGE found that calling process::exit from a child thread tears down the main thread's alternate stack while the main thread is still running. The cleanup function passes the main thread's alternate stack to drop_handler, which calls sigaltstack to disable the alternate stack of the calling thread and then munmap to unmap the main thread's. The code assumes it runs on the main thread, which is not true when a child thread calls process::exit. The main thread keeps running until libc's exit finishes, with its signal stack registration still pointing at unmapped memory. If it overflows its stack in that window, the kernel cannot deliver the signal, and the process dies with a plain segmentation fault instead of Rust's message. The bug dates back to 2015, and the fix (#161037) stops cleaning up the main thread's alternate stack altogether.
The CommandExt::exec bug (#156951) is about the environment. On Unix, exec replaces the current process with a new program. When the command has its own environment variables, exec points the process-global environ at a new array, calls execvp, and restores environ if execvp fails. Command::exec takes only the read side of the environment lock, yet do_exec writes the process-global environ. A thread calling env::var takes the same read lock and can see variables meant only for the new program, and two failed exec calls racing each other can leave environ pointing at a freed array that a later env::vars_os() reads. Both proofs of concept use only safe Rust. A 2018 fix held an exclusive lock here, but when the environment lock became a read-write lock in 2021, exec kept the read side. A fix that avoids touching environ by calling execve directly is in review (#157144).
A third example is a double free in safe code that process::exit can cause through thread-local destructors (#164243). libc's exit first runs the calling thread's thread-local destructors, and Rust registers its destructors the same way. If a destructor calls process::exit while a thread local is being replaced, libc drops that thread local a second time. A proposed fix switches process::exit to POSIX _exit, which ends the process without running these handlers (#165125).
Why AI agents change the search
The first two patterns are well studied. FORGE's own Rudra looked for both in 2021, and the standard library was already fixing panic-safety bugs in 2015. They remain challenging because any call inside unsafe code might unwind or run code the caller supplied.
The third pattern is different. Its bugs live where Rust meets the kernel and the C library: sigaltstack, munmap, environ, and the cleanup that libc's exit runs. Getting them right takes knowledge that lives outside Rust's type system, which has made them difficult to find with traditional static analysis. That may also be why they last so long: the process::exit signal stack bug was in the standard library for nearly 11 years, and exec has written environ under a read lock since 2021. Unlike the first two patterns, both affect stable Rust.
Language models already know a great deal about how these interfaces behave, so agentic scanners can check unsafe code against the system it runs on, not just the language. That is the case FORGE makes for Hyenas and for applying AI to vulnerability discovery in foundational libraries. It is a plausible argument, and the results are concrete: the research produced reported issues, fixes, and design changes.
The caveat is that AI-assisted discovery is not a substitute for maintainer judgment. FORGE notes that the Rust maintainers triaged and responded quickly, and that two of the reported issues remain open at publication. The research is a contribution to a process, not a replacement for it.
What to watch
The first thing to watch is the open issues. The Pattern API bugs (#158265, #165076, #164904) and the exec environment fix (#157144) are still in progress. Their resolution will show whether the type-level approach generalizes or whether some of these contracts need a different design.
The second is the Allocator API. Rust 1.100 stabilized the core of the API with a no-unwind requirement. Watch for follow-up work on the rest of the API surface, and for custom allocator implementations that have to adapt to the new contract.
The third is the standard library's use of unsafe. The research is a reminder that core and std are not magic; they are code with safety comments and invariants. More scrutiny of that code is good, especially as Rust spreads into the kernel, Android, cloud infrastructure, and AI tooling.
The fourth is the tooling. Hyenas and MDASH are research systems, but Microsoft says the work informs codename MDASH in Defender and Microsoft Perception. If agentic scanners become a routine part of vulnerability discovery, the volume of reported soundness bugs may rise, and so will the importance of triage and design-level fixes.
The fifth is the distinction between a soundness bug and a vulnerability. A soundness bug is a violation of Rust's safety contract; a vulnerability is a path an attacker can actually use. Most of the bugs in this research need an unusual setup, such as a panic at exactly the wrong moment, a deliberately misbehaving implementation, or process::exit from a child thread. That does not make them unimportant, but it does mean that "safe Rust can trigger UB" is a statement about the library's contract, not a claim that every Rust program is exploitable.
The research's most useful contribution is the framing. Rust's safety model is a set of contracts, and those contracts have to be enforced at the boundaries: panic, user code, and the operating system. The bugs are what happens when a boundary is trusted without evidence. The fixes are what happens when the boundary is made explicit. That is a healthier way to think about Rust's safety than either treating it as absolute or dismissing it as marketing.
Sources
- FORGE Lab uses agentic tools to identify memory safety issues in Rust (Microsoft Security Blog, 2026-11-09)
- Rust issue tracker (GitHub)
- Rust 1.100.0 release notes (Rust Blog, 2026-11-12)