From nobody Sat Apr 16 15:56:09 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 8C7B9CF85AC; Sat, 16 Apr 2022 15:56:09 +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 4Kgd8n3X2Kz3sZP; Sat, 16 Apr 2022 15:56:09 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1650124569; 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=qUyO2o72IjqZ4gHoHPy2aWXWC5xS/BhjNALjP6h2sWY=; b=IkZo95/gNNtmwws3tlj67XHsFPj59Bgl85nN5MdFrgugfR9KixkDNRZPgi8rSZ1QpKv0Xg A+sWzGnjX6ZQdf7DLs/WjoomBDNeqf48W1Xp4Bl3O3tUILyVR8hRQ9ZFnml0BrBCCvrbRm zWaBZL3tMpfClvn5Sa2ToztjTpjleuoWZZH5Y2gf2fGV4Fq8XWjc8pTW3gZTaor53mxOW9 lfRpN3WugNfK254vO/RkajNcCcRAhVUho16Wqw1y5JGMRNA5ZWA1hiYqxh1BBE81f09ySD dG4woSdPOK3JOAKfaY+Cr0Vg4tDKbdHxa0sshdYvN+sA3F6ccSXcdrwIwih+KA== 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 5861B49CF; Sat, 16 Apr 2022 15:56:09 +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 23GFu95M038964; Sat, 16 Apr 2022 15:56:09 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 23GFu9e5038963; Sat, 16 Apr 2022 15:56:09 GMT (envelope-from git) Date: Sat, 16 Apr 2022 15:56:09 GMT Message-Id: <202204161556.23GFu9e5038963@gitrepo.freebsd.org> To: ports-committers@FreeBSD.org, dev-commits-ports-all@FreeBSD.org, dev-commits-ports-main@FreeBSD.org From: Cy Schubert Subject: git: c586ac04eb66 - main - */{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/main X-Git-Reftype: branch X-Git-Commit: c586ac04eb662dea00ab81b226fa3e41a5110b21 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1650124569; 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=qUyO2o72IjqZ4gHoHPy2aWXWC5xS/BhjNALjP6h2sWY=; b=hT+q4nzp0VUoBqylI2YOJCgrYGD/Ur3RkIxWzKvB0d392N+IC0g/xoJw0AJTXb4sO1gO6z zjh5urOPK+81iFdSqqtpHAUEuXBno09qio/W4XNfNpxL1q8aDRjd0AoqUruyVWlGSHvs6Q 0oGlXA5l5JDSn10jmyK9SaoIbpqtKQ6xJReJw9UQCFSengewq1hnrmmxttJ69qla/xOJRz nUtsYY3UKgXTy/1xY+RGMPOLJKRE+OjSUDycrs7cEfBFztH40Fx5C/FI/B0BP3Hfiv9OB2 0JRWMVNFj27zNdsyH3DD6h+V34rMNslBGdxUotAHjfAU7pxnvyYz3BLAqIy3kg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1650124569; a=rsa-sha256; cv=none; b=ThjrRrElXjUEu/dVzAjAKK+EMObPjvaYRwYX3MY3ogIsQiCmDJWBOAwTTsdcRedjz+MV7Q YQ5KCmBnc4uaHyAPB6StYyfHbw7t4FhYxZkE9SDxnCikb/pZQtHeT0MCZ9fIfIMlqWex1N 5ymojReiiTWGJs86yPXNgMUOa833sUm+OcPEmrNU442sxjy6pvosbMTVImC20WH/F0dv7w bydadgMK6iojPXr3ArSauEwmfI1dVRL5SV2+G/zKyqqYomf06a06Y9d7WpaMwZZWGvIPCg 1pHPG7g04hnt7EkorEW18C13hf8sU5qGVX2B9YohQ8z4+kI7UI2EK7PNKzuYRQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by cy: URL: https://cgit.FreeBSD.org/ports/commit/?id=c586ac04eb662dea00ab81b226fa3e41a5110b21 commit c586ac04eb662dea00ab81b226fa3e41a5110b21 Author: Cy Schubert AuthorDate: 2022-04-14 15:42:03 +0000 Commit: Cy Schubert CommitDate: 2022-04-16 15:55: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 --- 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); + }