]> Cypherpunks repositories - gostls13.git/commit
syscall: restrict inherited handles on Windows
authorJason A. Donenfeld <Jason@zx2c4.com>
Sun, 31 Jan 2021 16:54:27 +0000 (17:54 +0100)
committerJason A. Donenfeld <Jason@zx2c4.com>
Fri, 26 Feb 2021 18:23:29 +0000 (18:23 +0000)
commit2d760816ff30bea82f54682f3049cfb6c6027da7
tree606cb6fe0271c72e0235f8102c70697254df32c5
parentba9168bd07bfed6071e3eadcaae40b5481c52c24
syscall: restrict inherited handles on Windows

Windows does not have CLOEXEC, but rather handles are marked explicitly
for being inherited by new processes. This can cause problems when
different Windows functions create new processes from different threads.
syscall.StartProcess has traditionally used a mutex to prevent races
with itself, but this doesn't handle races with other win32 functions.

Fortunately there's a solution: PROC_THREAD_ATTRIBUTE_HANDLE_LIST allows
us to pass the entire list of handles that we want to be inherited. This
lets us get rid of the mutex and also makes process creation safe across
the Go runtime, no matter the context.

Updates #44011.

Change-Id: Ia3424cd2ec64868849cbd6cbb5b0d765224bf4ab
Reviewed-on: https://go-review.googlesource.com/c/go/+/288297
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Trust: Alex Brainman <alex.brainman@gmail.com>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
src/syscall/exec_windows.go