Use shared netlock to protect if_list and ifa_list walkthrough and ifnet
authormvs <mvs@openbsd.org>
Sat, 23 Sep 2023 13:01:12 +0000 (13:01 +0000)
committermvs <mvs@openbsd.org>
Sat, 23 Sep 2023 13:01:12 +0000 (13:01 +0000)
data access within kvp_get_ip_info().

ok bluhm

sys/dev/pv/hypervic.c

index b3ce2d9..e74ef50 100644 (file)
@@ -846,7 +846,7 @@ kvp_get_ip_info(struct hv_kvp *kvp, const uint8_t *mac, uint8_t *family,
        struct sockaddr_in6 *sin6, sa6;
        uint8_t enaddr[ETHER_ADDR_LEN];
        uint8_t ipaddr[INET6_ADDRSTRLEN];
-       int i, j, lo, hi, s, af;
+       int i, j, lo, hi, af;
 
        /* Convert from the UTF-16LE string format to binary */
        for (i = 0, j = 0; j < ETHER_ADDR_LEN; i += 6) {
@@ -870,16 +870,14 @@ kvp_get_ip_info(struct hv_kvp *kvp, const uint8_t *mac, uint8_t *family,
                return (-1);
        }
 
-       KERNEL_LOCK();
-       s = splnet();
+       NET_LOCK_SHARED();
 
        TAILQ_FOREACH(ifp, &ifnetlist, if_list) {
                if (!memcmp(LLADDR(ifp->if_sadl), enaddr, ETHER_ADDR_LEN))
                        break;
        }
        if (ifp == NULL) {
-               splx(s);
-               KERNEL_UNLOCK();
+               NET_UNLOCK_SHARED();
                return (-1);
        }
 
@@ -919,8 +917,7 @@ kvp_get_ip_info(struct hv_kvp *kvp, const uint8_t *mac, uint8_t *family,
                else if (ifa6ll != NULL)
                        ifa = ifa6ll;
                else {
-                       splx(s);
-                       KERNEL_UNLOCK();
+                       NET_UNLOCK_SHARED();
                        return (-1);
                }
        }
@@ -956,8 +953,7 @@ kvp_get_ip_info(struct hv_kvp *kvp, const uint8_t *mac, uint8_t *family,
                break;
        }
 
-       splx(s);
-       KERNEL_UNLOCK();
+       NET_UNLOCK_SHARED();
 
        return (0);
 }