From nobody Thu Apr 7 21:20:47 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 1DADD1A86147; Thu, 7 Apr 2022 21:20:48 +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 4KZDnW6Y6Zz3mJZ; Thu, 7 Apr 2022 21:20:47 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1649366448; 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=wKf0AmOylV4OBuiHiRfAZUrMiRH8i5bsKkFdIyflUrA=; b=AZvgjViUsi1624ctCtSJ6/d4Yv/EXRM0N3GbUWIkKmVaNvIqbwNusKktuefDDeIWO6r+v7 HNBO3RRsWuvef+jvTiTStRufyfWJDG7qiKT6D3zzM9+JwOPEmpTs2sTum2bZP0cBcAbjZZ vlr83Npwn9wuG4vF6VOrizDeiHKVpXwlBAz0DSLeF7/Ve8AcZ1Qog2cHeimfiqOcvqpXKl +yNxdiCJ5BL6vZjwnn1dP1zSmOccKONzdFVNjyuVmgfRgQvDdKh/9zBP8iFOEzK+6WSciL POdv1J1fr515j5DrhGB5871eXJIitVwzLs4iTiSBfZIyOPMYxIvLHfzNEhyyzg== 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 B36ED17DBC; Thu, 7 Apr 2022 21:20:47 +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 237LKlon066061; Thu, 7 Apr 2022 21:20:47 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 237LKlma066060; Thu, 7 Apr 2022 21:20:47 GMT (envelope-from git) Date: Thu, 7 Apr 2022 21:20:47 GMT Message-Id: <202204072120.237LKlma066060@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: 2010c5e3a379 - stable/12 - 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/12 X-Git-Reftype: branch X-Git-Commit: 2010c5e3a379c55d188909dcc6c0edb12272983b Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1649366448; 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=wKf0AmOylV4OBuiHiRfAZUrMiRH8i5bsKkFdIyflUrA=; b=kd5cW0o+4o85x6spa0ZGKXbkNNd7w6E/ommoueloJWSv4jXUhLPa7w9DnnaS8oS6uenVSk za5v0G6sgvO/mXKYRBAwI4tZEonOKg/AxCFZyxt6erdImoHtaMg3XXI0NOA04yisAhLKib ibt76bi2otN1aUHicjJje5hdNdiuV4vJIbFsGBvsGwJChWUck6gNZvCUSD13sUj15k/jPr TOrMg6n9MWkCIxp0QI+icsZOs7uPJKiy9X2As3PJBI41DsLB1PEAmbmoXLEwfiE5gCJRDi nmn4Y8MZbnzijzm+jTAWZIrZfrxHydYsHeQX2CdyGxr5XZQCMBpabj+PobJv0g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1649366448; a=rsa-sha256; cv=none; b=gMpy9M0SvoLhbUFGlAlzZvzcYpHGCLruL3W/qbAlp2OCsAPbSZ6ee/4KHInmSHe/Nhong9 dFbezimwbbT93gAOB2cwPgw65SvGdFv9Fh1IgOswKTHjFJwYSzStFSIk9IzMjX3FNYmMzM Fn1HMPxIEtEx8bFwgA1QcoUblcADpKxKBhMsgRc+jTd9hvIxUmWB3txlQvF5s89KSr4GUh yJP1JEdERHYFnBfIdQ4LEfYXlz1TAgvdqSBhZcK8ldT4txcvQM7l/7dP4aOQH/mkGmgjzf 496BrWiv7ufIDA6Ni3bfYLd1jzteajF69Yg++K4VHRvBD4EZuQlANWzGwVqkrQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by cy: URL: https://cgit.FreeBSD.org/src/commit/?id=2010c5e3a379c55d188909dcc6c0edb12272983b commit 2010c5e3a379c55d188909dcc6c0edb12272983b Author: Cy Schubert AuthorDate: 2022-04-03 03:54:50 +0000 Commit: Cy Schubert CommitDate: 2022-04-07 21:20:35 +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;