fix(init): prevent binfmt_misc handler loss on distro termination#14443
Draft
yeelam-gordon wants to merge 1 commit intomicrosoft:masterfrom
Draft
Conversation
Fixes the issue where terminating a WSL2 distro with systemd clears binfmt_misc handlers across all running distros. Changes: - Add mount unit override to prevent binfmt_misc unmount during shutdown - Fix FP vs P flag inconsistency in WSLInterop registration - Use declarative /run/binfmt.d/ approach for handler persistence Fixes microsoft#13885 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a WSL2/systemd shutdown interaction where terminating one distro could clear binfmt_misc handlers (including WSLInterop) for other running distros, breaking Windows interop.
Changes:
- Generate a declarative
systemd-binfmtconfig in/run/binfmt.d/WSLInterop.conffor persistentWSLInteropregistration. - Add systemd generator drop-in overrides to prevent
systemd-binfmtstop actions and keepbinfmt_miscmounted during shutdown. - Align the
WSLInteropbinfmt registration string to consistently use:FP.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| test/windows/UnitTests.cpp | Adds assertions that the generated /run/binfmt.d config and systemd generator overrides exist (and stay consistent across restarts/reloads), and that protectBinfmt=false disables generation. |
| src/linux/init/main.cpp | Switches BINFMT_REGISTER_STRING to use the shared registration macro (now consistent with :FP). |
| src/linux/init/init.cpp | Implements generation of /run/binfmt.d/WSLInterop.conf and generator drop-ins for systemd-binfmt and the binfmt_misc mount unit when protectBinfmt is enabled. |
| src/linux/init/binfmt.h | Updates the shared binfmt registration macro to use :FP (fixing prior inconsistency). |
You can also share your feedback on Copilot code review. Take the survey.
benhillis
reviewed
Mar 16, 2026
| #define BINFMT_MISC_MOUNT_TARGET "/proc/sys/fs/binfmt_misc" | ||
| #define BINFMT_MISC_REGISTER_FILE BINFMT_MISC_MOUNT_TARGET "/register" | ||
| #define BINFMT_INTEROP_REGISTRATION_STRING(Name) ":" Name ":M::MZ::" LX_INIT_PATH ":P" | ||
| #define BINFMT_INTEROP_REGISTRATION_STRING(Name) ":" Name ":M::MZ::" LX_INIT_PATH ":FP" |
Member
There was a problem hiding this comment.
This will break WSL1 which does not support the 'F' flag.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of the Pull Request
Fixes the issue where terminating a WSL2 distro with systemd clears binfmt_misc handlers across all running distros, breaking Windows interop. Changes:
PR Checklist
Validation Steps Performed
Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com