src/syscall/dll_windows.go | 13 +++++++++++++ src/syscall/mksyscall_windows.go | 4 ++-- diff --git a/src/syscall/dll_windows.go b/src/syscall/dll_windows.go index ec8d85b66b7bf9cf1839659cbfa56da33d5f117f..453ec11dd6e7e01654113f3119242f7fb30a55a1 100644 --- a/src/syscall/dll_windows.go +++ b/src/syscall/dll_windows.go @@ -37,6 +37,13 @@ Handle Handle } // LoadDLL loads the named DLL file into memory. +// +// If name is not an absolute path and is not a known system DLL used by +// Go, Windows will search for the named DLL in many locations, causing +// potential DLL preloading attacks. +// +// Use LazyDLL in golang.org/x/sys/windows for a secure way to +// load system DLLs. func LoadDLL(name string) (*DLL, error) { namep, err := UTF16PtrFromString(name) if err != nil { @@ -174,6 +181,12 @@ // A LazyDLL implements access to a single DLL. // It will delay the load of the DLL until the first // call to its Handle method or to one of its // LazyProc's Addr method. +// +// LazyDLL is subject to the same DLL preloading attacks as documented +// on LoadDLL. +// +// Use LazyDLL in golang.org/x/sys/windows for a secure way to +// load system DLLs. type LazyDLL struct { mu sync.Mutex dll *DLL // non nil once DLL is loaded diff --git a/src/syscall/mksyscall_windows.go b/src/syscall/mksyscall_windows.go index 546cb0d432aa5ea68320ca72a35adc0e4398a3b7..7786d1349edf6d3c3fd29f5008b7a0d8808d2a97 100644 --- a/src/syscall/mksyscall_windows.go +++ b/src/syscall/mksyscall_windows.go @@ -707,9 +707,9 @@ arg = "sysdll.Add(" + arg + ")" } if *sysRepo { if packageName == "windows" { - return "&LazyDLL{Name: " + arg + ", Flags: LoadLibrarySearchSystem32}" + return "&LazyDLL{Name: " + arg + ", System: true}" } else { - return "&windows.LazyDLL{Name: " + arg + ", Flags: windows.LoadLibrarySearchSystem32}" + return "&windows.LazyDLL{Name: " + arg + ", System: true}" } } else { return syscalldot() + "NewLazyDLL(" + arg + ")"