From nobody Thu Apr 07 21:18:42 2022 X-Original-To: dev-commits-src-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 8903F1A85AA3; Thu, 7 Apr 2022 21:18:43 +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 4KZDl70f85z3lj6; Thu, 7 Apr 2022 21:18:43 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1649366323; 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=De95ALZ0KHGPp+/qcJoQpCZZNVmF1kxZdpDWxcrUTuE=; b=T8b0AQHrFKk7ASDON3rscFQDJc0+PdwAd7g/wT/aHZsKKC7vOyIdKx7Ugp+3kcHnlQueek m3GNweH89CrZIDYSVbR9+OcMlAxYTsfpwU0i1xAmd9QTplDlrMbGV7iRfKnt3cvacMxkDG ZAxsdRpYytcv8ZwXIllvc2zxWZNC25vo+BDz8DAP36MIo6he4IBz5K6Wm9/+uh0fUOUr3c gUkZaHKkhdNsrBsgc/amE8rsL0ct6DbR0tQu2yfgYo9Mf/rV2KY+/sznxqqi696vK8MLpG +kSr3YkYuHlSLGhWtiIjBwXRPso0vwmEPPTqJKCYT9xRgo1qRT00dIOpt+iXMw== 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 DA41617D17; Thu, 7 Apr 2022 21:18:42 +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 237LIgCM056746; Thu, 7 Apr 2022 21:18:42 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 237LIgIo056745; Thu, 7 Apr 2022 21:18:42 GMT (envelope-from git) Date: Thu, 7 Apr 2022 21:18:42 GMT Message-Id: <202204072118.237LIgIo056745@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Cy Schubert Subject: git: 64d0220f45f9 - stable/13 - wpa/hostapd: Fix 100% CPU when USB wlan NIC removed List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-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: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 64d0220f45f93fdaab29caec095d292341e37c4e Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1649366323; 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=De95ALZ0KHGPp+/qcJoQpCZZNVmF1kxZdpDWxcrUTuE=; b=vF+zPzZb8wT+veOTjdOji+c2TyZgMASvxzI6xxcAC2fOM3sCfO/TnAmdI7lVNlMzheyM7o MPQ3pbGKh3JjtxsV2mKRvag9yVuK3v/bZUgs3yxNUtSDm+BjmX87TXz0qgAYfuCS6xzFBd +bCC0DsRpnw8Zr7tpyY5td0J2ToYOpXCZf2tJMZqS/+Vg3tWDqG8SoC7+v3htlOsi4f1CQ lfnqoo5roOjZxjahvy5yrWHqmxWnUPJDf7yvjl6sBAwP9ixSWVLiwvRLcSvhj3wqzdLRw/ 7bYb+ibTWOCCrVl9dW6ciA95EVuFa3U4tIQyxOl+Oq3L3zRCZipRBcLpx9SlYg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1649366323; a=rsa-sha256; cv=none; b=SxLTSSXZFd1OZEFd9nHp23dcJNpnJ1sQ2GFNdpzfitnsK7WqzH2XHK9SFv4xU5Y+HhHR/5 3ET3Iw1p0i94nnth/KX/kIGiV35Ux/x4qAjSgbgUtSlTreNFboigf7h9iPGP3jEsExB3Xf NkTbtbM50vtilpuACUVpmO3N+JyQMrxCFWs6Ylugxz1XNQa2mre28d4YSV68Q+YAHb5fGb P8enLZ9uoKLBabflnWvp9gO6zak/y+P5c/KFJwO+S4Fc7L7j7z5sMbF5tLNKHKucpb4tVj C1+EKfgr9jwkRtcGxEeteDebns3EUusZDFtDhmYDl52gjXQX2mX/k7h7girTPg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by cy: URL: https://cgit.FreeBSD.org/src/commit/?id=64d0220f45f93fdaab29caec095d292341e37c4e commit 64d0220f45f93fdaab29caec095d292341e37c4e Author: Cy Schubert AuthorDate: 2022-04-03 03:54:50 +0000 Commit: Cy Schubert CommitDate: 2022-04-07 21:18:04 +0000 wpa/hostapd: Fix 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) (cherry picked from commit 6e5d01124fd4dd57899ddd9260c76dbb43543aa7) --- contrib/wpa/src/l2_packet/l2_packet_freebsd.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/contrib/wpa/src/l2_packet/l2_packet_freebsd.c b/contrib/wpa/src/l2_packet/l2_packet_freebsd.c index 48e18fffba57..da742f432120 100644 --- a/contrib/wpa/src/l2_packet/l2_packet_freebsd.c +++ b/contrib/wpa/src/l2_packet/l2_packet_freebsd.c @@ -83,7 +83,10 @@ static void l2_packet_receive(int sock, void *eloop_ctx, void *sock_ctx) 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)) return;