Skip to content

Prevent binfmt_misc unmount propagation across distros#40614

Closed
benhillis wants to merge 1 commit into
release/2.7from
benhill/fix-binfmt-exec-format-error-2.7
Closed

Prevent binfmt_misc unmount propagation across distros#40614
benhillis wants to merge 1 commit into
release/2.7from
benhill/fix-binfmt-exec-format-error-2.7

Conversation

@benhillis

Copy link
Copy Markdown
Member

Summary

Minimal cherry-pick of #40612 for the 2.7 release branch.

Fixes an Exec format error bug where Windows interop breaks in all running distros when a peer distro with systemd shuts down.

Root Cause

/proc is mounted with MS_SHARED, so binfmt_misc inherits shared mount propagation. When a peer distro's systemd shuts down and unmounts binfmt_misc in its namespace, the unmount propagates back through the shared peer group to init's namespace, wiping ALL registrations globally.

Fix

One additional mount() call with MS_PRIVATE immediately after mounting binfmt_misc. This is the minimal version — the master branch PR also extends UtilMount to handle propagation flags generically.

PR Checklist

  • Builds cleanly
  • Includes regression test (InteropSurvivesPeerDistroShutdown)
  • Passes clang-format

Fixes #13885

@benhillis benhillis requested a review from a team as a code owner May 21, 2026 01:39
Copilot AI review requested due to automatic review settings May 21, 2026 01:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR is a minimal backport for the 2.7 release branch to prevent binfmt_misc unmount propagation across distros, which can otherwise clear global binfmt registrations and break Windows interop (Exec format error) when a peer systemd-enabled distro shuts down.

Changes:

  • Mark the binfmt_misc mount as MS_PRIVATE after mounting to isolate it from peer namespace unmount propagation.
  • Add a WSL2 regression test that imports a peer distro, enables systemd, terminates it, and validates interop/binfmt state survives.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/linux/init/main.cpp Marks the binfmt_misc mount private to prevent shutdown unmount propagation from affecting other distros.
test/windows/UnitTests.cpp Adds a regression test intended to validate interop survives a peer systemd distro termination.

Comment thread test/windows/UnitTests.cpp
Comment thread test/windows/UnitTests.cpp
When multiple WSL2 distros share a VM, binfmt_misc inherits shared mount
propagation from /proc. If a peer distro running systemd shuts down, its
final unmount of binfmt_misc propagates back through the shared peer group
to the init namespace, destroying all interop registrations globally and
causing 'Exec format error' for every running distro.

Mark binfmt_misc as MS_PRIVATE immediately after mounting so that child
namespace unmounts are isolated and cannot propagate back.

Fixes #13885

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@benhillis benhillis force-pushed the benhill/fix-binfmt-exec-format-error-2.7 branch from 15c5dac to 5ee1442 Compare May 21, 2026 02:02
@benhillis

Copy link
Copy Markdown
Member Author

Closing in favor of #14443, which is the correct fix and has CI passing.

Our MS_PRIVATE approach was wrong: binfmt_misc entries are scoped per user-namespace (or effectively global), not per mount-namespace. WSL peer distros share the root user-ns (no CLONE_NEWUSER), so peer's systemd-binfmt --unregister -> write -1 to /proc/sys/fs/binfmt_misc/status clears the global entry table regardless of mount propagation.

Once #14443 merges to master, we'll do a clean cherry-pick backport to release/2.7.

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