summaryrefslogtreecommitdiffhomepage
path: root/tun/wintun/wintun_windows.go
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-09-01 21:32:28 -0600
committerJason A. Donenfeld <Jason@zx2c4.com>2019-09-01 21:32:28 -0600
commit73d3bd9cd5e425c7422084172e63ed2eaa87d8ec (patch)
tree17a83e9ab3402ed787fcef419d9455659164c951 /tun/wintun/wintun_windows.go
parentf3dba4c1948e7225c61e8561abb50d0a876bd737 (diff)
wintun: take mutex first always
This prevents an ABA deadlock with setupapi's internal locks.
Diffstat (limited to 'tun/wintun/wintun_windows.go')
-rw-r--r--tun/wintun/wintun_windows.go18
1 files changed, 9 insertions, 9 deletions
diff --git a/tun/wintun/wintun_windows.go b/tun/wintun/wintun_windows.go
index c654b02..e2348c0 100644
--- a/tun/wintun/wintun_windows.go
+++ b/tun/wintun/wintun_windows.go
@@ -196,6 +196,15 @@ func (pool Pool) GetInterface(ifname string) (*Interface, error) {
// interesting complications with its usage. This function returns the network
// interface ID and a flag if reboot is required.
func (pool Pool) CreateInterface(ifname string, requestedGUID *windows.GUID) (wintun *Interface, rebootRequired bool, err error) {
+ mutex, err := pool.takeNameMutex()
+ if err != nil {
+ return
+ }
+ defer func() {
+ windows.ReleaseMutex(mutex)
+ windows.CloseHandle(mutex)
+ }()
+
// Create an empty device info set for network adapter device class.
devInfoList, err := setupapi.SetupDiCreateDeviceInfoListEx(&deviceClassNetGUID, 0, "")
if err != nil {
@@ -281,15 +290,6 @@ func (pool Pool) CreateInterface(ifname string, requestedGUID *windows.GUID) (wi
return
}
- mutex, err := pool.takeNameMutex()
- if err != nil {
- return
- }
- defer func() {
- windows.ReleaseMutex(mutex)
- windows.CloseHandle(mutex)
- }()
-
defer func() {
if err != nil {
// The interface failed to install, or the interface ID was unobtainable. Clean-up.