]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
wintun: make remaining HWID comparisons case insensitive
authorSimon Rozman <simon@rozman.si>
Sat, 2 May 2020 06:49:35 +0000 (08:49 +0200)
committerJason A. Donenfeld <Jason@zx2c4.com>
Sat, 2 May 2020 07:50:47 +0000 (01:50 -0600)
c85e4a410f27986a2967a49c0155633c716bf3ca introduced preliminary HWID
checking to speed up Wintun adapter enumeration. However, all HWID are
case insensitive by Windows convention.

Furthermore, a device might have multiple HWIDs. When DevInfo's
DeviceRegistryProperty(SPDRP_HARDWAREID) method returns []string, all
strings returned should be checked against given hardware ID.

This issue was discovered when researching Wintun and wireguard-go on
Windows 10 ARM64. The Wintun adapter was created using devcon.exe
utility with "wintun" hardware ID, causing wireguard-go fail to
enumerate the adapter properly.

Signed-off-by: Simon Rozman <simon@rozman.si>
tun/wintun/wintun_windows.go

index 4c12d97742a8a2a4bc65ba576f5ef872fadb8dad..3aada08cf53ae1b5deab6225e55586a05dc50bfd 100644 (file)
@@ -136,7 +136,7 @@ func (pool Pool) GetInterface(ifname string) (*Interface, error) {
                if err != nil {
                        continue
                }
-               if hwids, ok := property.([]string); ok && len(hwids) > 0 && hwids[0] != hardwareID {
+               if !isOurHardwareID(property) {
                        continue
                }
 
@@ -508,7 +508,7 @@ func (pool Pool) DeleteMatchingInterfaces(matches func(wintun *Interface) bool)
                if err != nil {
                        continue
                }
-               if hwids, ok := property.([]string); ok && len(hwids) > 0 && hwids[0] != hardwareID {
+               if !isOurHardwareID(property) {
                        continue
                }
 
@@ -801,3 +801,20 @@ func (wintun *Interface) GUID() windows.GUID {
 func (wintun *Interface) LUID() uint64 {
        return ((uint64(wintun.luidIndex) & ((1 << 24) - 1)) << 24) | ((uint64(wintun.ifType) & ((1 << 16) - 1)) << 48)
 }
+
+func isOurHardwareID(property interface{}) bool {
+       hwidLC := strings.ToLower(hardwareID)
+
+       if hwids, ok := property.([]string); ok && len(hwids) > 0 {
+               for i := range hwids {
+                       if strings.ToLower(hwids[i]) == hwidLC {
+                               return true
+                       }
+               }
+       }
+       if hwid, ok := property.(string); ok && strings.ToLower(hwid) == hwidLC {
+               return true
+       }
+
+       return false
+}