From nobody Mon Apr 04 13:12:13 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 626E71A91E94; Mon, 4 Apr 2022 13:12:14 +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 4KXB5B1CzVz4W1F; Mon, 4 Apr 2022 13:12:14 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1649077934; 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=5koiBFVrPNezyxPI6JlqBcx/iP1IfaXrh+7EoUlgdHQ=; b=RNrNalK0fuwng2/rhDx8gPDEUcFNZ4u1Dgau37c+N4QVGKI2vVA7RmL2J/5rylJnw7UUaK 3s6dRltqk1H2atCbWXpcWruJpmtIrEFnHFR+Go9CeTGqfwMx504m0pj9TbTBsy8Vf1j9Dl wi03gKfTxshrDieiu/MHVjY/YEOxSe/I3zdbEYyz5Cy2vso8M6GdllTp7TmHUT57bbFPZf EtINaO+oXypwvB+KOd5vcyJDqb5cS1W1jM9tZ9J9Q9bthHxQI+cIKgxhwZ+Xn3NB/rs+iV 57xEUTNsJ+jFU4BU7QmtX4jbbG6hUplRiww74HTEkY5IyVvS35uCLdQ+FI6Qbw== 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 EFF86129E4; Mon, 4 Apr 2022 13:12:13 +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 234DCDV9064245; Mon, 4 Apr 2022 13:12:13 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 234DCDdE064244; Mon, 4 Apr 2022 13:12:13 GMT (envelope-from git) Date: Mon, 4 Apr 2022 13:12:13 GMT Message-Id: <202204041312.234DCDdE064244@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Cy Schubert Subject: git: 6e5d01124fd4 - main - 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/main X-Git-Reftype: branch X-Git-Commit: 6e5d01124fd4dd57899ddd9260c76dbb43543aa7 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1649077934; 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=5koiBFVrPNezyxPI6JlqBcx/iP1IfaXrh+7EoUlgdHQ=; b=XtxgiO/HWW1T9Did5BoH74i96AY2XdUxAhbgyh2/BSl8793SEVh4Nf5h26bMKN6nEXKUKH 4KSS06l+RGEap+knlXrQpOjkgKKj0E7olVmhiOun/KX5zfEb4NzSqP7pr3Ry+DQJ4Hndyr 1ldPpA6RsMxYbccJb+liQz8OjFdkyVOEWdzmuYWTbvqJMys7Q0vDKLmjfBThzlIdO4bloG 2PmEQt/N+1ikOgL/RTXtF4M91kDSWQ1wsEDO7R3vS2x7hpWgKITt7ryy25gREtNEfggf5J +5PiDRNH4Vm6tIBPdPxR/WCLNMGajvlbJWjbgmPwDQ0lIS+IwkHjJ0IyztL6fQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1649077934; a=rsa-sha256; cv=none; b=n9Lac+OXZ20WUHB3uMfFAE1iYA3JgWzG57QquacQCYTm2P52vw+StOD6j54e8FjPo7JiLN nfpjnWDzySwQnVBUCH627/ftVmKbzo6Tc8YgA8hACBhKeu8F5goyTqsqZfMrDxGAJ5QUly 4HYg5tKSuJquhwm34yX2RxlRJ8Au3mMN1QBELHAHSrxVuxYGBG5Y3wFCU+1PALwEH9gNQe 8SSc30VaK7BH9T5IXd7nhQzMKbzaQ87L/D1HWfVhC5CaK9TrzVgMiV8Q3cUCPw9fB/bZ39 0uUpu0+UNyZmvCHzqUqkLPzt+YajdfL10X9kqGUzLkFC6TkKmQsGHNKFDWP/ng== 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/src/commit/?id=6e5d01124fd4dd57899ddd9260c76dbb43543aa7 commit 6e5d01124fd4dd57899ddd9260c76dbb43543aa7 Author: Cy Schubert AuthorDate: 2022-04-03 03:54:50 +0000 Commit: Cy Schubert CommitDate: 2022-04-04 13:11:28 +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) MFC after: 3 days --- 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;