Microsoft FORGE Lab found memory-safety bugs in Rust's standard library: what to check in your code and the Rust inside your iOS app
Short answer

Microsoft's FORGE Lab reported memory-safety bugs in Rust's standard library on November 9, and some can be reached from code with no unsafe. Most projects only need a toolchain update. Check three things first: whether your code calls std::process::exit from a thread other than main, whether it calls CommandExt::exec while other threads run, and whether it implements a custom allocator. If your iOS app links a Rust static library, find out which Rust version built it, remove any exit path from the shared crate, and rebuild the library after you update.

On November 9, Microsoft's FORGE Lab published a report on memory-safety bugs it found inside Rust's own standard library. Some of them can be reached from code that contains no unsafe at all. Part of the work was done with Hyenas, the research version of an AI vulnerability scanner Microsoft calls MDASH, and the rest with ordinary manual research. Every bug was reproduced and reported to the Rust maintainers before the post went up.

The story spread fast on developer sites because it pokes at the promise people repeat about Rust: write safe code and the compiler keeps memory errors out. That promise always rested on the unsafe code inside std and core being correct, and this report shows places where it was not.

Most Rust projects have nothing urgent to fix. Each bug needs an unusual setup to trigger, and the authors judged practical exploitation of the one they studied most closely to be unlikely. Still, a few of the affected APIs are ones real programs call every day, such as std::process::exit and CommandExt::exec, and Rust 1.100 is due on November 12 with related changes. This post covers what was found, how to check whether your code touches the affected paths, and what to change. It also covers the Rust that many iOS teams now ship inside their apps through a static library, because that code gets reviewed less often than the Swift around it.

What FORGE Lab found

The post, written by Yechan Bae, sorts the bugs into three patterns. Each one is a case where unsafe code in the standard library trusted something it should not have trusted.

PatternExample from the reportStatus in the post
Trusting code not to panicIterator::map_windows: if an element's clone panics, a destructor can run over a half-built buffer (issue #156501, seen on Rust 1.97.0). Allocators that unwind could make BTreeMap::insert and other allocator paths unsound (#156490 and reports by others).MapWindows fixed by holding the buffer in ManuallyDrop. The stabilized Allocator trait now forbids unwinding.
Trusting user-provided implementationsstr::replace with a custom Pattern could produce a string that is not valid UTF-8 (#156491, seen on 1.96.0). join had a heap overflow fixed in April 2026 (PR #155708), after an incomplete fix for CVE-2020-36323.Fixed by PR #156556. Two related Pattern issues were still open.
Trusting the underlying systemCalling process::exit from a child thread unmaps the main thread's alternate signal stack (#161018, seen on 1.98.0, dating to 2015). CommandExt::exec writes the global environment while holding only a read lock (#156951, seen on 1.99.0).Signal stack fix in PR #161037. The exec change (PR #157144) and a proposed _exit change for process::exit (PR #165125) were still in review.

The report also mentions a double free in safe code when process::exit meets thread-local destructors (#164243), found by someone else. FORGE does not give a total count, says two of its own reports were still open when it published, and lists no new CVE numbers for the 2026 findings.

On exploitability, the authors are careful. For the signal stack bug they describe a theoretical path to code execution, found no reliable exploit in their tests, and say that conclusion does not carry over to the other issues automatically. The proofs of concept for map_windows, str::replace and exec show crashes, memory corruption or information exposure from safe code, without an assessment of real-world attacks.

Are you affected? Sort it by API

The first question is whether your code can reach any of these paths at all. Two of the headline examples are less reachable than they look.

Iterator::map_windows is still a nightly-only experimental API in the current stable docs (std 1.99.1), behind the iter_map_windows feature. The Pattern trait is also nightly-only, behind the pattern feature. If you build on stable and never turn those features on, you cannot write a custom Pattern or call map_windows, so those two bugs do not reach you through your own code. Projects on nightly, or crates that enable those features, should look closer.

The other examples sit on stable APIs that plenty of programs use:

  • std::process::exit, especially when called from a thread other than the main one. CLI tools, servers and test harnesses do this all the time, often from a signal handler thread or a worker that hit a fatal error.
  • std::os::unix::process::CommandExt::exec, used by launchers, wrappers and tools that hand off to another program.
  • Custom allocators. With Allocator stabilization shipping in Rust 1.100 (PR #156882, according to the FORGE post), the trait requires that implementations never unwind from their methods or from drop.

If none of those appear in your code or your dependencies' hot paths, updating the toolchain is enough. If they do appear, read on.

Where each finding lands, by project type

The report covers several unrelated APIs, so the answer depends on what you build. This table restates the list above by project and not by API.

What you buildWhat can reach youWhere to start
Command-line tool or server on stable Rustprocess::exit, mainly when a worker or signal thread calls itStep 3: send the failure to main and return from there
Launcher or wrapper that hands off to another programCommandExt::exec while other threads run, and writes to the process environmentStep 4: call exec early and set variables on the Command
Crate with a custom allocatorAllocator or GlobalAlloc methods that can panicReview them for unwinding before you move to 1.100
Project on nightly that uses map_windows or a custom PatternBoth nightly-only bugsUpdate the nightly toolchain. Two related Pattern issues were still open when the report came out.
Crate with hand-written unsafe codeNone of these bugs directly, but the same three mistakesSteps 5 and 6
iOS app with a Rust static libraryAn exit path in a shared crate, and an old standard library inside a prebuilt binaryStep 7, then rebuild with the updated toolchain
App with no Rust in itNothingNo action

If you are not sure whether the last row is yours, the check under Step 7 shows how to look inside a binary for Rust.

Step 1: Find out which toolchain actually builds your code

The version on your laptop is often not the one that ships. Check three places: the rust-toolchain.toml file in the repo, the CI configuration, and any build script that installs Rust for a release (for iOS teams, that is often a shell script run from an Xcode build phase or a CI job).

rustc --version
rustup show active-toolchain
cat rust-toolchain.toml 2>/dev/null
grep -rn "toolchain\|rustup" .github/ ci/ scripts/ 2>/dev/null

Write down the version each place uses. A pinned toolchain is good practice, but a pin that nobody has touched since 2025 means you are missing every standard library fix since then, including the ones in this report.

Step 2: Search the repo for the affected APIs

I wrote a small script that lists every line in your own Rust code that touches the APIs named in the report. It skips target/, prints the pinned toolchain, and counts your unsafe blocks so you know how much code to read by hand. I tested it on Linux against a fake repo that used each pattern.

#!/usr/bin/env bash
# rust-std-check.sh: list the std APIs from the FORGE Lab report that a Rust repo touches.
# Usage: ./rust-std-check.sh [repo-dir]
set -u
dir="${1:-.}"
cd "$dir" || exit 1

echo "== Toolchain"
rustc --version 2>/dev/null || echo "rustc could not run here (missing, or the pinned toolchain is not installed)"
for f in rust-toolchain.toml rust-toolchain; do
  [ -f "$f" ] && { echo "-- $f:"; cat "$f"; }
done

search() {
  label="$1"; pattern="$2"
  hits=$(grep -rnE --include='*.rs' "$pattern" . 2>/dev/null | grep -v '/target/' || true)
  if [ -n "$hits" ]; then
    echo; echo "== $label"; echo "$hits"
  fi
}

search "process::exit (check which thread calls it)" 'process::exit|std::process::exit|[^_a-z]exit\('
search "CommandExt::exec (replaces the process)" '\.exec\(\)|CommandExt'
search "Environment writes (env::set_var / remove_var)" 'set_var\(|remove_var\('
search "Custom allocators (must not unwind)" 'impl[^{]*(GlobalAlloc|Allocator) for|#\[global_allocator\]'
search "Nightly features named in the report" 'feature\((iter_map_windows|pattern|allocator_api)'
search "map_windows / custom Pattern impls" 'map_windows|impl[^{]*Pattern[^{]* for'
n=$(grep -rnE --include='*.rs' 'unsafe[[:space:]]*\{' . 2>/dev/null | grep -vc '/target/' || true)
echo; echo "== unsafe blocks in your own code: $n"
echo
echo "Done. A hit is a place to read, not a confirmed bug."

Run it from the repo root with ./rust-std-check.sh, or pass a path. The exit( pattern is loose on purpose and will catch some unrelated functions named exit; that is cheaper than missing a call. Treat every hit as a line to read, then decide.

The script only reads your own code. To see which dependencies use these APIs, run the same search against the vendored sources (cargo vendor into a scratch folder works) and focus on crates that run in your process at startup or shutdown.

What the script prints on a Mac

The script was tested on Linux, so it was also run on macOS 26.0.1 with the system's bash 3.2 and BSD grep, against a one-file sample crate that calls std::process::exit in an error path. It ran without changes:

== Toolchain
rustc 1.94.1 (e408947bf 2026-03-25)

== process::exit (check which thread calls it)
./src/lib.rs:5:        std::process::exit(3);

== unsafe blocks in your own code: 0

Done. A hit is a place to read, not a confirmed bug.

Read the first line of that output as closely as the hits. The Mac used for this check still had a toolchain from March 2026 as its default, which is the stale version Step 1 is about. Sections with no hits are left out, so a short report is normal.

Step 3: Stop calling process::exit from worker threads

This is the change most projects can make today, and it helps beyond this one bug. The standard library docs already say exit skips every destructor on every thread's stack, and they recommend returning a Termination type such as ExitCode or Result from main instead. The docs also note that concurrent calls to Rust's exit and C's exit on Unix are undefined behavior without synchronization, which matters if your binary links C code that can also exit.

The FORGE finding adds one more reason: calling exit from a child thread was the trigger for the signal stack bug. The fix in your code is to have the worker report the failure and let the main thread decide. Here is the smallest version, which I compiled and ran on Rust 1.97.0 (it exits with 0 normally and 2 when passed --fail):

use std::process::ExitCode;
use std::sync::mpsc;
use std::thread;

fn main() -> ExitCode {
    let (tx, rx) = mpsc::channel::<u8>();

    let worker = thread::spawn(move || {
        // Instead of std::process::exit(2) here, report back.
        if std::env::args().any(|a| a == "--fail") {
            let _ = tx.send(2);
            return;
        }
        let _ = tx.send(0);
    });

    let code = rx.recv().unwrap_or(1);
    let _ = worker.join();
    ExitCode::from(code)
}

In a real program the channel carries an error type, and main returns Result<(), YourError>. If you use an async runtime, the same idea applies: send the shutdown reason to the task that owns main and return from there. Destructors then run, buffers flush, and lock files get removed, which is usually what you wanted anyway.

Step 4: Treat exec and environment writes as process-wide events

CommandExt::exec replaces the current process image and does not fork. Its docs warn that if it fails, the process may be left in a broken state with a changed working directory, environment, signal settings or user and group, and they suggest spawn when you need clean error handling. They also say returning from exec skips destructors the same way exit does.

The FORGE bug (#156951) is about exec writing the global environ while another thread may be reading it. Until PR #157144 lands, two habits lower the risk:

  1. Call exec early, before you start other threads, or from a point where every other thread has already stopped.
  2. Set environment variables on the Command with .env() and .env_clear() instead of changing your own process environment with std::env::set_var first. Since the 2024 edition, set_var and remove_var are unsafe functions, which is the compiler telling you the same thing about threads and the environment.

If the process only needs to run a child and wait for it, use spawn or status and keep your own process alive.

Step 5: If you write unsafe code, check it against the three patterns

The report's advice is aimed at people who write unsafe code, and it applies well beyond the standard library. Any crate that builds a data structure by hand, wraps a C library or implements a collection can have the same three mistakes.

For panic safety, the rule is: never leave a structure in a state where running its destructor would be wrong while code that can panic is running. User clone, eq, hash and closure calls can all panic. The usual fix is a guard that knows how much work is finished and cleans up only that part if a panic unwinds through it. This example clones a value into a fixed array and stays sound if clone panics partway. I tested it with a Clone impl that panics on the third call and a live-object counter, and the test confirmed nothing was dropped twice or leaked:

use std::mem::MaybeUninit;

/// Clone src into a fixed array without leaving half-built state behind
/// if T::clone panics part way.
pub fn clone_n<T: Clone, const N: usize>(src: &T) -> [T; N] {
    struct Guard<'a, T, const N: usize> {
        buf: &'a mut [MaybeUninit<T>; N],
        done: usize,
    }
    impl<T, const N: usize> Drop for Guard<'_, T, N> {
        fn drop(&mut self) {
            // Runs only on panic: drop the elements that were finished.
            for slot in &mut self.buf[..self.done] {
                unsafe { slot.assume_init_drop() };
            }
        }
    }

    let mut buf: [MaybeUninit<T>; N] = [const { MaybeUninit::uninit() }; N];
    let mut guard = Guard { buf: &mut buf, done: 0 };
    while guard.done < N {
        guard.buf[guard.done].write(src.clone()); // may panic
        guard.done += 1;
    }
    std::mem::forget(guard);
    // Every slot is initialized now.
    buf.map(|slot| unsafe { slot.assume_init() })
}

For user-provided implementations, the report suggests calling the user's code once and keeping the result, validating what it returns before unsafe code relies on it, encoding the property in the type system, or making the trait itself unsafe so implementors take on the promise explicitly. A Hash or Ord implementation that returns different answers on two calls is legal safe Rust, so unsafe code must not assume it will not happen.

For the system, assume another thread can be in the middle of anything that is process-global: the environment, signal handlers, the current directory, file descriptors. Process exit and replacement are the moments when those assumptions break.

Step 6: Run your tests under Miri

Miri is the Rust interpreter that checks for undefined behavior while it runs your code. It needs nightly, but it does not need you to switch your project to nightly:

rustup +nightly component add miri
cargo +nightly miri test
# run the suite as a Linux program, or on a big-endian target
cargo +nightly miri test --target x86_64-unknown-linux-gnu
cargo +nightly miri test --target s390x-unknown-linux-gnu

Know its limits before you trust a clean run. The Miri README says it does not catch every kind of undefined behavior, it tests one execution per run so thread interleavings can hide bugs, it mostly does not support platform APIs or FFI, and finding no UB does not prove your code is sound. Varying -Zmiri-seed through MIRIFLAGS covers more interleavings. For code that is mostly FFI, which is common in mobile libraries, Miri will skip the part you care about most, so pair it with a test that panics inside your callbacks on purpose, like the one above.

Step 7: The Rust inside your iOS app

A growing number of iOS apps include Rust: a sync engine, a crypto layer, a parser shared with Android, built as a static library and called from Swift through generated bindings. That code is easy to forget because the Xcode project only sees a prebuilt library and a header. Here is what to check there.

First, find the build. Look for a build phase or script that runs cargo build with Apple targets such as aarch64-apple-ios and aarch64-apple-ios-sim, and check which toolchain it installs. If the library is prebuilt and checked into the repo as an .xcframework, find out when it was last rebuilt and with which Rust version. A binary built in early 2026 carries the standard library from early 2026.

Second, search the shared crate for process::exit. An iOS app should not call it in the first place. Apple's archived Technical Q&A QA1561 says there is no API for gracefully terminating an iOS app, that calling exit makes the app look like it crashed, and that it skips applicationWillTerminate: and similar delegate methods, so data may not be saved. A crate shared with a CLI or server often has an exit path for fatal errors. Return an error across the FFI boundary instead and let the Swift side show the user what happened. An exit during review reads as a crash, and Guideline 2.1 Rejection: Why Your AI-Built App Crashed in App Review covers what happens next.

Third, check exec and environment writes. A shared crate might have a desktop code path that launches a helper. Make sure it cannot compile into the iOS build:

#[cfg(not(target_os = "ios"))]
fn launch_helper(path: &std::path::Path) -> std::io::Error {
    use std::os::unix::process::CommandExt;
    std::process::Command::new(path).env_clear().exec()
}

Fourth, run the script from Step 2 on the Rust crate, not just the Swift project. The unsafe count tells you how much hand-written FFI and buffer code lives there, which is usually where the panic-safety pattern shows up.

Read the Rust version out of a prebuilt library

Step 7 says to find out which Rust version built a checked-in library. If nobody wrote it down, the binary can tell you. To check this, a small crate was built as a static library with Rust 1.94.1 on macOS 26.0.1. The Mac had no iOS target installed, so the library was built for macOS. The object format is the same Mach-O that iOS uses, but run the commands on your own .xcframework before you rely on the result there.

strings -a libshared.a | grep -o 'rustc version [0-9][^)]*)' | sort | uniq -c
strings -a libshared.a | grep -oE '/rustc/[0-9a-f]{40}' | sort | uniq -c

The first command printed one distinct line, rustc version 1.94.1 (e408947bf 2026-03-25), repeated 700 times. The second printed one commit hash, the same one rustc -vV reports as commit-hash for that toolchain. More than one distinct line in either output would mean the archive mixes objects from different toolchains.

The library was then linked into a small C program, and the same two searches were run on the result, before and after strip:

MarkerStatic library (.a)Linked binaryLinked and stripped
rustc version linePresentGoneGone
/rustc/ plus commit hashPresentPresent, 99 timesPresent, 99 times

So a shipped binary no longer names the version, but it still carries the commit hash, inside the source paths the standard library keeps for panic messages. That gives the check two uses. For a library, read the version directly and compare it with the release that has the fixes you need. For an app or a closed-source SDK, it answers a simpler question first: is there any Rust in this binary at all? A plain C program built the same way had none of these paths. To turn a hash into a version, compare it with rustc -vV on a machine that has the candidate toolchain, or search for the hash in the rust-lang/rust repository on GitHub.

The check has a blind spot. Some build setups remove panic location strings to save space, and a binary built that way would show nothing. An empty result does not prove a binary is free of Rust.

Step 8: Update when Rust 1.100 ships

Rust releases every six weeks, and 1.100 is scheduled for November 12. The fixes that landed before the release branch cut will reach you through a normal update; the ones still in review in the FORGE post will come later. Updating is the same command as always:

rustup update stable
rustc --version

Then update the pin in rust-toolchain.toml, the CI image and any iOS build script in the same pull request, so the three stay in sync. Rebuild any prebuilt .xcframework from the updated toolchain and run your test suite on a device as well as the simulator. If you implement the Allocator trait or a GlobalAlloc, review it for code that can panic before you upgrade, since the stabilized trait requires that it never unwinds.

Read the release notes on the Rust blog when they go up before you assume a particular issue number is fixed. The FORGE post lists the Rust versions where each bug was observed, not the versions where fixes shipped.

What this says about AI vulnerability scanners

The bugs are real, and some are old: the signal stack behaviour goes back to a 2015 pull request and the exec lock change to 2021. Those are the kind of cross-cutting system assumptions that human reviewers skim past, and a scanner that knows OS behaviour can test them without getting bored. The team also reproduced and assessed every finding before filing it. That last step is what separates a useful report from noise. VulnCheck's November update on Anthropic's Glasswing program, with about 38,000 findings reported and 217 marked fixed, shows what happens when validation falls on maintainers instead.

You can borrow the method for your own code. Ask your coding agent to review each unsafe block against the three patterns in this post: what happens if a user callback panics here, what happens if a trait implementation lies, and what happens if another thread touches process-global state at this moment. Then reproduce anything it reports with a failing test before you change code. An unverified "possible UB" comment from an agent costs the next reader time and proves nothing. Cloudflare's Security Audit Skill Went Viral. How to Run It on an iOS App Repo covers running an agent-driven security review on an iOS repo.

FAQ

Is safe Rust broken?
No. Safe Rust's guarantees depend on the unsafe code beneath it being correct, and these were bugs in that code. Each one needs unusual conditions, they were reported responsibly, and most are fixed or have fixes in review.

Do I need to change my code if I only use stable Rust?
Probably not for map_windows or custom Pattern implementations, which are nightly-only. Do check for process::exit from threads, exec in multithreaded programs, and custom allocators.

Were CVEs assigned?
The FORGE post cites only older CVEs (CVE-2020-36323 and CVE-2015-20001) for context and mentions no new ones for these findings. Watch the Rust security advisories page if you need a formal reference for a compliance report.

Does this affect Swift code?
No. It affects only Rust code, including Rust compiled into an iOS app as a library.

How do I tell which Rust version built a prebuilt library?
Run strings -a on the .a file and search for "rustc version". In a test with Rust 1.94.1, the static library contained that line, and a linked or stripped binary kept only the compiler's commit hash in its /rustc/ paths.

Will Miri catch these bugs in my project?
Miri can catch UB that your tests actually trigger, if the code path does not depend on platform APIs Miri cannot run. The exit and exec issues depend on OS behaviour, so a clean Miri run does not rule them out.

A kit for iOS teams that use coding agents

If your team uses Claude Code on an iOS codebase that mixes Swift with a Rust or C library, Claude Code + Xcode: The Production iOS Workflow Kit is a pack of copy-ready AGENTS.md and CLAUDE.md templates, eight focused rules (privacy and security and release safety among them), six commands including /ios-review and /ios-release, and ten specialized iOS agents. It tells Claude to inspect first, plan narrowly, run real Xcode checks and report evidence and remaining risk. You can add the three review questions from this post to its security rule.

Sources