From nobody Mon Jun 20 15:12:38 2022 X-Original-To: dev-commits-ports-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id D926A8679ED; Mon, 20 Jun 2022 15:12:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4LRY6b3w4Vz4h0y; Mon, 20 Jun 2022 15:12:39 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655737959; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=mucZ+Kn7LktQacYCcMMeO2l7NJsXRyxc9VJNvL3QhYI=; b=klx6uRaL24Zr8fdJ9izWnXK1IV3ty52m421vgGhhudmh0oI6qdc2NVTlbolmrfSGh9tEo7 yREVwN7HcB/ZnPMsh8RNgpWLDdG7oZIAJ19YPZdxFKQyl9p+CMgodDuDc/A0b5pS/QrnR1 WhiYOGkBJv4vg6mMJDXOX+SZI7+2gO35H83NiQF0nQPZGA9S02jc27skxwFGjHewNJq+Ng kxYQ0WiAj9doTU5PozMhIo2IRzVaFzxyr4A3Pinn8bLzg2h3m5LH96Xc58wtzFTb22hNhW SLkq/hryhbnEsZJQk/iKzpeI0tpdKUwd74J6vsPw0ohQSQ2oDOLQgUhTzf0D1w== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 267271FAD8; Mon, 20 Jun 2022 15:12:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 25KFCcnT003672; Mon, 20 Jun 2022 15:12:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 25KFCckW003671; Mon, 20 Jun 2022 15:12:38 GMT (envelope-from git) Date: Mon, 20 Jun 2022 15:12:38 GMT Message-Id: <202206201512.25KFCckW003671@gitrepo.freebsd.org> To: ports-committers@FreeBSD.org, dev-commits-ports-all@FreeBSD.org, dev-commits-ports-branches@FreeBSD.org From: Cy Schubert Subject: git: 84877d0e0252 - 2022Q2 - */{wpa_supplicant*,hostapd*}: Fix wpa 100% CPU when USB wlan NIC removed List-Id: Commit messages for all branches of the ports repository List-Archive: https://lists.freebsd.org/archives/dev-commits-ports-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-ports-all@freebsd.org X-BeenThere: dev-commits-ports-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: cy X-Git-Repository: ports X-Git-Refname: refs/heads/2022Q2 X-Git-Reftype: branch X-Git-Commit: 84877d0e0252072a222b3eb16a354f53b8f639fa Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655737959; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=mucZ+Kn7LktQacYCcMMeO2l7NJsXRyxc9VJNvL3QhYI=; b=XphkJwPGRUdTyPYVumcNZVagAKic4vE31vl646C+dHUAKNmjp5Y1jn9GRHL3lpMfkgc1ji /1RgeUMILxMNPrEnTBSSIDySh3K1PzVjIKBJwDxOecnAw5KUQnFwCO92Ek+F1Ers1SWcwm 8R1e6k3QZl52WzTUXayuOhEadIryqxwzRkJpHmjvbkdQbYlcQ+g3g2mMVG2Z7OWAID+HSc gtxygBSyCYGibDWrlzlLMRhgzurtlZajqJKFbeifckdB0ZPVtgY+exdbYI0u8RPTVn5YMf mT8rI6FZ3bUHwkZUjG07kEH5DnpAHi2tW3YhYJtSYvbUUYuMjBEbhbdD7ZixNw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1655737959; a=rsa-sha256; cv=none; b=DbpQsxh+Guei/4/z95JDknwUJ5jNJUkvebS+/jqUQogf/JprMvGQMr2vtKXsnpyDE0q2Hu tjBYdtirBHXBuaqruX+hP2e11UjBpdftvOl2DLWaGbsU6BchNaeK0Rk3+kCwaCrtVnFReJ kfkVW2OvMxE/7oOLgTeXh7yHBdWFjAuqmzDRGtXYYOfjULk6+AIj/zZA5CzeMf7brPdANn 6WHCdBPk8PWjIXKfhP9a614FnfCvf/E92KQ/jKoZ9aSWSqoIbinPD/314i4PjW2UPXKcTF vgAnNDBCHzceWQmst37Eor1JazygRseKR9J6VqKsqXcCnKLP83meLei4yzQnvA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch 2022Q2 has been updated by cy: URL: https://cgit.FreeBSD.org/ports/commit/?id=84877d0e0252072a222b3eb16a354f53b8f639fa commit 84877d0e0252072a222b3eb16a354f53b8f639fa Author: Cy Schubert AuthorDate: 2022-04-14 15:42:03 +0000 Commit: Cy Schubert CommitDate: 2022-06-20 15:11:56 +0000 */{wpa_supplicant*,hostapd*}: Fix wpa 100% CPU when USB wlan NIC removed hostapd calls pcap_next(3) to read the next packet off the wlan interface. pcap_next() returns a pointer to the packet header but does not indicate success or failure. Unfortunately this results in an infinite loop (100% CPU) when the wlan device disappears, i.e. when a USB wlan device is manually removed or a USB error results in the device removal. However pcap_next_ex(3) does return success or failure. To resolve this we use pcap_next_ex(), forcing hostapd to exit when the error is encountered. An error message is printed to syslog or stderr when debugging (-d flag) is enabled. Unfortunately wpa_printf() only works when debugging is enabled. PR: 253608 Reported by: Damjan Jovanovic , bz (privately) MFH: 2022Q2 (cherry picked from commit c586ac04eb662dea00ab81b226fa3e41a5110b21) --- net/hostapd-devel/Makefile | 1 + .../files/patch-src-l2_packet-l2_packet_freebsd.c | 37 ++++++++++++++++++++-- net/hostapd/Makefile | 1 + .../files/patch-src-l2_packet-l2_packet_freebsd.c | 37 ++++++++++++++++++++-- security/wpa_supplicant-devel/Makefile | 1 + .../patch-src_l2__packet_l2__packet__freebsd.c | 12 ++++--- security/wpa_supplicant/Makefile | 1 + .../patch-src_l2__packet_l2__packet__freebsd.c | 37 ++++++++++++++++++++-- 8 files changed, 116 insertions(+), 11 deletions(-) diff --git a/net/hostapd-devel/Makefile b/net/hostapd-devel/Makefile index d824e2b8785f..f65d26658412 100644 --- a/net/hostapd-devel/Makefile +++ b/net/hostapd-devel/Makefile @@ -2,6 +2,7 @@ PORTNAME= hostapd PORTVERSION= ${COMMIT_DATE} +PORTREVISION= 1 CATEGORIES= net PKGNAMESUFFIX= -devel diff --git a/net/hostapd-devel/files/patch-src-l2_packet-l2_packet_freebsd.c b/net/hostapd-devel/files/patch-src-l2_packet-l2_packet_freebsd.c index 8b34e0fbdd89..26ecb22c808c 100644 --- a/net/hostapd-devel/files/patch-src-l2_packet-l2_packet_freebsd.c +++ b/net/hostapd-devel/files/patch-src-l2_packet-l2_packet_freebsd.c @@ -1,5 +1,5 @@ ---- src/l2_packet/l2_packet_freebsd.c.orig 2014-06-04 13:26:14 UTC -+++ src/l2_packet/l2_packet_freebsd.c +--- src/l2_packet/l2_packet_freebsd.c.orig 2022-03-14 01:42:11.000000000 -0700 ++++ src/l2_packet/l2_packet_freebsd.c 2022-04-14 07:36:24.999713000 -0700 @@ -8,7 +8,10 @@ */ @@ -12,3 +12,36 @@ #include #endif /* __APPLE__ */ #include +@@ -76,24 +79,27 @@ + { + struct l2_packet_data *l2 = eloop_ctx; + pcap_t *pcap = sock_ctx; +- struct pcap_pkthdr hdr; ++ struct pcap_pkthdr *hdr; + const u_char *packet; + struct l2_ethhdr *ethhdr; + unsigned char *buf; + size_t len; + +- packet = pcap_next(pcap, &hdr); ++ if (pcap_next_ex(pcap, &hdr, &packet) == -1) { ++ wpa_printf(MSG_ERROR, "Error reading packet, has device disappeared?"); ++ eloop_terminate(); ++ } + +- if (!l2->rx_callback || !packet || hdr.caplen < sizeof(*ethhdr)) ++ if (!l2->rx_callback || !packet || hdr->caplen < sizeof(*ethhdr)) + return; + + ethhdr = (struct l2_ethhdr *) packet; + if (l2->l2_hdr) { + buf = (unsigned char *) ethhdr; +- len = hdr.caplen; ++ len = hdr->caplen; + } else { + buf = (unsigned char *) (ethhdr + 1); +- len = hdr.caplen - sizeof(*ethhdr); ++ len = hdr->caplen - sizeof(*ethhdr); + } + l2->rx_callback(l2->rx_callback_ctx, ethhdr->h_source, buf, len); + } diff --git a/net/hostapd/Makefile b/net/hostapd/Makefile index 97e774f07b94..26b97a5fd502 100644 --- a/net/hostapd/Makefile +++ b/net/hostapd/Makefile @@ -2,6 +2,7 @@ PORTNAME= hostapd PORTVERSION= 2.10 +PORTREVISION= 1 CATEGORIES= net MASTER_SITES= https://w1.fi/releases/ diff --git a/net/hostapd/files/patch-src-l2_packet-l2_packet_freebsd.c b/net/hostapd/files/patch-src-l2_packet-l2_packet_freebsd.c index 8b34e0fbdd89..c8be8a1c9c12 100644 --- a/net/hostapd/files/patch-src-l2_packet-l2_packet_freebsd.c +++ b/net/hostapd/files/patch-src-l2_packet-l2_packet_freebsd.c @@ -1,5 +1,5 @@ ---- src/l2_packet/l2_packet_freebsd.c.orig 2014-06-04 13:26:14 UTC -+++ src/l2_packet/l2_packet_freebsd.c +--- src/l2_packet/l2_packet_freebsd.c.orig 2022-01-16 12:51:29.000000000 -0800 ++++ src/l2_packet/l2_packet_freebsd.c 2022-04-14 07:35:30.668820000 -0700 @@ -8,7 +8,10 @@ */ @@ -12,3 +12,36 @@ #include #endif /* __APPLE__ */ #include +@@ -76,24 +79,27 @@ + { + struct l2_packet_data *l2 = eloop_ctx; + pcap_t *pcap = sock_ctx; +- struct pcap_pkthdr hdr; ++ struct pcap_pkthdr *hdr; + const u_char *packet; + struct l2_ethhdr *ethhdr; + unsigned char *buf; + size_t len; + +- packet = pcap_next(pcap, &hdr); ++ if (pcap_next_ex(pcap, &hdr, &packet) == -1) { ++ wpa_printf(MSG_ERROR, "Error reading packet, has device disappeared?"); ++ eloop_terminate(); ++ } + +- if (!l2->rx_callback || !packet || hdr.caplen < sizeof(*ethhdr)) ++ if (!l2->rx_callback || !packet || hdr->caplen < sizeof(*ethhdr)) + return; + + ethhdr = (struct l2_ethhdr *) packet; + if (l2->l2_hdr) { + buf = (unsigned char *) ethhdr; +- len = hdr.caplen; ++ len = hdr->caplen; + } else { + buf = (unsigned char *) (ethhdr + 1); +- len = hdr.caplen - sizeof(*ethhdr); ++ len = hdr->caplen - sizeof(*ethhdr); + } + l2->rx_callback(l2->rx_callback_ctx, ethhdr->h_source, buf, len); + } diff --git a/security/wpa_supplicant-devel/Makefile b/security/wpa_supplicant-devel/Makefile index a876ab9e9631..f2b41fe32440 100644 --- a/security/wpa_supplicant-devel/Makefile +++ b/security/wpa_supplicant-devel/Makefile @@ -1,5 +1,6 @@ PORTNAME= wpa_supplicant PORTVERSION= ${COMMIT_DATE} +PORTREVISION= 1 CATEGORIES= security net PKGNAMESUFFIX= -devel diff --git a/security/wpa_supplicant-devel/files/patch-src_l2__packet_l2__packet__freebsd.c b/security/wpa_supplicant-devel/files/patch-src_l2__packet_l2__packet__freebsd.c index 5bce58b36950..e256ee3860e1 100644 --- a/security/wpa_supplicant-devel/files/patch-src_l2__packet_l2__packet__freebsd.c +++ b/security/wpa_supplicant-devel/files/patch-src_l2__packet_l2__packet__freebsd.c @@ -1,12 +1,14 @@ ---- src/l2_packet/l2_packet_freebsd.c.orig 2018-12-02 11:34:59.000000000 -0800 -+++ src/l2_packet/l2_packet_freebsd.c 2018-12-05 23:18:27.612433000 -0800 -@@ -8,7 +8,8 @@ +--- src/l2_packet/l2_packet_freebsd.c.orig 2022-01-16 12:51:29.000000000 -0800 ++++ src/l2_packet/l2_packet_freebsd.c 2022-04-14 07:23:26.534960000 -0700 +@@ -8,7 +8,10 @@ */ #include "includes.h" -#if defined(__APPLE__) || defined(__GLIBC__) -+#include -+#if defined(__APPLE__) || defined(__GLIBC__) || defined(__FreeBSD_version) ++#if defined(__FreeBSD__) \ ++ || defined(__DragonFly__) \ ++ || defined(__APPLE__) \ ++ || defined(__GLIBC__) #include #endif /* __APPLE__ */ #include diff --git a/security/wpa_supplicant/Makefile b/security/wpa_supplicant/Makefile index 31acd83f3c14..aaeda909f826 100644 --- a/security/wpa_supplicant/Makefile +++ b/security/wpa_supplicant/Makefile @@ -1,5 +1,6 @@ PORTNAME= wpa_supplicant PORTVERSION= 2.10 +PORTREVISION= 1 CATEGORIES= security net MASTER_SITES= https://w1.fi/releases/ diff --git a/security/wpa_supplicant/files/patch-src_l2__packet_l2__packet__freebsd.c b/security/wpa_supplicant/files/patch-src_l2__packet_l2__packet__freebsd.c index 5bce58b36950..5a55ec96fc90 100644 --- a/security/wpa_supplicant/files/patch-src_l2__packet_l2__packet__freebsd.c +++ b/security/wpa_supplicant/files/patch-src_l2__packet_l2__packet__freebsd.c @@ -1,5 +1,5 @@ ---- src/l2_packet/l2_packet_freebsd.c.orig 2018-12-02 11:34:59.000000000 -0800 -+++ src/l2_packet/l2_packet_freebsd.c 2018-12-05 23:18:27.612433000 -0800 +--- src/l2_packet/l2_packet_freebsd.c.orig 2022-01-16 12:51:29.000000000 -0800 ++++ src/l2_packet/l2_packet_freebsd.c 2022-04-14 07:21:15.259934000 -0700 @@ -8,7 +8,8 @@ */ @@ -10,3 +10,36 @@ #include #endif /* __APPLE__ */ #include +@@ -76,24 +77,27 @@ + { + struct l2_packet_data *l2 = eloop_ctx; + pcap_t *pcap = sock_ctx; +- struct pcap_pkthdr hdr; ++ struct pcap_pkthdr *hdr; + const u_char *packet; + struct l2_ethhdr *ethhdr; + unsigned char *buf; + size_t len; + +- packet = pcap_next(pcap, &hdr); ++ if (pcap_next_ex(pcap, &hdr, &packet) == -1) { ++ wpa_printf(MSG_ERROR, "Error reading packet, has device disappeared?"); ++ eloop_terminate(); ++ } + +- if (!l2->rx_callback || !packet || hdr.caplen < sizeof(*ethhdr)) ++ if (!l2->rx_callback || !packet || hdr->caplen < sizeof(*ethhdr)) + return; + + ethhdr = (struct l2_ethhdr *) packet; + if (l2->l2_hdr) { + buf = (unsigned char *) ethhdr; +- len = hdr.caplen; ++ len = hdr->caplen; + } else { + buf = (unsigned char *) (ethhdr + 1); +- len = hdr.caplen - sizeof(*ethhdr); ++ len = hdr->caplen - sizeof(*ethhdr); + } + l2->rx_callback(l2->rx_callback_ctx, ethhdr->h_source, buf, len); + }