Skip to content

Instantly share code, notes, and snippets.

@alirobe
Last active October 12, 2026 01:46
Show Gist options
  • Select an option

  • Save alirobe/e79fadfe47c064514e4a8af5b1b9fb6b to your computer and use it in GitHub Desktop.

Select an option

Save alirobe/e79fadfe47c064514e4a8af5b1b9fb6b to your computer and use it in GitHub Desktop.
Fix Git Bash fork errors (0xC0000142) on Windows with Mandatory ASLR

Git Bash fork errors (0xC0000142) on Windows

dofork: child -1 - forked process 50032 died unexpectedly, retry 0, exit code 0xC0000142, errno 11
/usr/bin/bash: fork: retry: Resource temporarily unavailable

Also breaks editors and AI coding agents that run commands through Git Bash.

Cause: Windows Security > Exploit protection > Force randomization for images (Mandatory ASLR) is on. Git's MSYS runtime can't emulate fork() under it. Check with (Get-ProcessMitigation -System).ASLR.ForceRelocateImages (ON = affected).

Fix: let the Git installer (2.42+) add the exemptions. Interactive setup shows a "Security options" page when it detects Mandatory ASLR; silent installs (winget) skip it unless you ask:

winget install --id Git.Git --custom "/o:AddmandatoryASLRsecurityexceptions=Enabled"

Or run this gist's script in an elevated PowerShell (same exemptions, by full path; re-run after Git upgrades; -Undo removes them). It should finish with forked: ok.

pwsh -NoProfile -ExecutionPolicy Bypass -File .\fix-git-bash-aslr.ps1

Security: Mandatory ASLR loads every DLL at a random address, even ones not built for it, so an exploit can't rely on code sitting at a known location. It's a good hardening default (Windows ships with it off). Git's MSYS runtime must load at a fixed address to emulate fork(), so it can't run under it. Exempting only Git's executables, by full path, puts them back to Windows' default while everything else stays hardened - much better than turning it off system-wide. (Pass a bare file name to Set-ProcessMitigation and the exemption applies to every executable with that name on the machine; the script passes full paths.) The trade-off: a memory bug in Git's tools (hit via a malicious repo or archive, say) would be easier to exploit, so keep Git updated. Read the script before running it elevated.

Background: Git for Windows #1412, installer option, Cygwin can't run under forced ASLR.

See also: MSYS2 runtime PR 381, which restores ASLR support in the runtime so none of this is needed once it ships in Git for Windows, and the fallback PR 380, which makes the error message name the cause.

#Requires -RunAsAdministrator
# Fix Git Bash "fork ... 0xC0000142" under Mandatory ASLR: exempt Git's MSYS executables only, by
# full path (what the Git installer does). Re-run after Git upgrades. -Undo removes the exemptions.
param([string]$GitRoot = (Get-ItemProperty HKLM:\SOFTWARE\GitForWindows -ErrorAction Ignore).InstallPath, [switch]$Undo)
if (-not $GitRoot) { throw 'Git for Windows not found; pass -GitRoot "C:\Program Files\Git"' }
$ifeo = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options'
Get-ChildItem "$GitRoot\usr\bin\*.exe" | ForEach-Object {
if (-not $Undo) { Set-ProcessMitigation -Name $_.FullName -Disable ForceRelocateImages; return }
# Set-ProcessMitigation cannot remove the path-scoped entries it creates, so delete them directly.
$key = "$ifeo\$($_.Name)"; $path = $_.FullName
Get-ChildItem -LiteralPath $key -ErrorAction Ignore | Where-Object { (Get-ItemProperty -LiteralPath $_.PSPath).FilterFullPath -eq $path } | Remove-Item -Recurse -Force
if ((Test-Path -LiteralPath $key) -and -not (Get-ChildItem -LiteralPath $key -ErrorAction Ignore)) { Remove-Item -LiteralPath $key -Recurse -Force }
}
if (-not $Undo) { & "$GitRoot\bin\bash.exe" -c 'echo "forked: $(echo ok)"' }
@alirobe

alirobe commented Oct 12, 2026

Copy link
Copy Markdown
Author

Note, working upstream on a more permanent solution: msys2/msys2-runtime#381

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment