Some other bug causes my USB bus to sporadically undergo some kind of reset, making all USB devices appear to disconnect and then reconnect. One of my USB devices is a WiFi dongle, which hostapd is running with. When it disconnects, hostapd CPU usage jumps to 100%, and stays there until manually killed: # truss -s 1024 -f -p 34705 34705: read(5,0x80121f2c0,524288) ERR#6 'Device not configured' 34705: select(7,{ 4 5 6 },{ },{ },{ 2.635212 }) = 1 (0x1) 34705: read(5,0x80121f2c0,524288) ERR#6 'Device not configured' 34705: select(7,{ 4 5 6 },{ },{ },{ 2.635171 }) = 1 (0x1) 34705: read(5,0x80121f2c0,524288) ERR#6 'Device not configured' 34705: select(7,{ 4 5 6 },{ },{ },{ 2.635120 }) = 1 (0x1) 34705: read(5,0x80121f2c0,524288) ERR#6 'Device not configured' 34705: select(7,{ 4 5 6 },{ },{ },{ 2.635069 }) = 1 (0x1) 34705: read(5,0x80121f2c0,524288) ERR#6 'Device not configured' 34705: select(7,{ 4 5 6 },{ },{ },{ 2.635001 }) = 1 (0x1) # lsof -n |grep hostapd hostapd 34705 root cwd VDIR 2669942718,3349274250 36 4 / hostapd 34705 root rtd VDIR 2669942718,3349274250 36 4 / hostapd 34705 root 0u VCHR 0,16 0t0 16 /dev/null hostapd 34705 root 1u VCHR 0,16 0t0 16 /dev/null hostapd 34705 root 2u VCHR 0,16 0t0 16 /dev/null hostapd 34705 root 3u IPv4 0xfffff80016a2b040 0t0 UDP *:* hostapd 34705 root 4u rte 0xfffff8001334b1e0 0t0 hostapd 34705 root 5u VCHR 0,40 0t0 40 /dev/bpf hostapd 34705 root 6u unix 0xfffff8011139e000 0t0 /var/run/hostapd/wlan0 hostapd 34705 root 7r VDIR 2669942718,3349274250 43 712 /var/run hostapd 34705 root 8w VREG 2669942718,3349274250 5 262304 /var/run/hostapd.pid I consider this a hostapd bug, because the WiFi dongle could also get unplugged manually to reproduce it. When a WiFi device disappears, hostapd should do something better than get stuck in an infinite loop.
Created attachment 232913 [details] Use pcap call that returns a return code Can you try this patch, please.
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=6e5d01124fd4dd57899ddd9260c76dbb43543aa7 commit 6e5d01124fd4dd57899ddd9260c76dbb43543aa7 Author: Cy Schubert <cy@FreeBSD.org> AuthorDate: 2022-04-03 03:54:50 +0000 Commit: Cy Schubert <cy@FreeBSD.org> 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 <damjan.jov@gmail.com>, bz (privately) MFC after: 3 days contrib/wpa/src/l2_packet/l2_packet_freebsd.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
A commit in branch stable/13 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=64d0220f45f93fdaab29caec095d292341e37c4e commit 64d0220f45f93fdaab29caec095d292341e37c4e Author: Cy Schubert <cy@FreeBSD.org> AuthorDate: 2022-04-03 03:54:50 +0000 Commit: Cy Schubert <cy@FreeBSD.org> 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 <damjan.jov@gmail.com>, bz (privately) (cherry picked from commit 6e5d01124fd4dd57899ddd9260c76dbb43543aa7) contrib/wpa/src/l2_packet/l2_packet_freebsd.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
A commit in branch stable/12 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=2010c5e3a379c55d188909dcc6c0edb12272983b commit 2010c5e3a379c55d188909dcc6c0edb12272983b Author: Cy Schubert <cy@FreeBSD.org> AuthorDate: 2022-04-03 03:54:50 +0000 Commit: Cy Schubert <cy@FreeBSD.org> 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 <damjan.jov@gmail.com>, bz (privately) (cherry picked from commit 6e5d01124fd4dd57899ddd9260c76dbb43543aa7) contrib/wpa/src/l2_packet/l2_packet_freebsd.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/ports/commit/?id=c586ac04eb662dea00ab81b226fa3e41a5110b21 commit c586ac04eb662dea00ab81b226fa3e41a5110b21 Author: Cy Schubert <cy@FreeBSD.org> AuthorDate: 2022-04-14 15:42:03 +0000 Commit: Cy Schubert <cy@FreeBSD.org> 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 <damjan.jov@gmail.com>, 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(-)
A commit in branch 2022Q2 references this bug: URL: https://cgit.FreeBSD.org/ports/commit/?id=84877d0e0252072a222b3eb16a354f53b8f639fa commit 84877d0e0252072a222b3eb16a354f53b8f639fa Author: Cy Schubert <cy@FreeBSD.org> AuthorDate: 2022-04-14 15:42:03 +0000 Commit: Cy Schubert <cy@FreeBSD.org> 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 <damjan.jov@gmail.com>, 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(-)
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/ports/commit/?id=5da13f40eeaa4b39b3a9fd41e58d082e954acce6 commit 5da13f40eeaa4b39b3a9fd41e58d082e954acce6 Author: Cy Schubert <cy@FreeBSD.org> AuthorDate: 2023-09-12 05:08:11 +0000 Commit: Cy Schubert <cy@FreeBSD.org> CommitDate: 2023-09-12 05:51:07 +0000 security/wpa_supplicant-devel: Reapply c586ac04eb66 Reapply "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, 273696 Obtained from: src 6e5d01124fd4 Reported by: Damjan Jovanovic <damjan.jov@gmail.com>, bz (privately) MFH: 2023Q3 security/wpa_supplicant-devel/Makefile | 2 +- .../files/patch-src_l2__packet_l2__packet__freebsd.c | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-)
A commit in branch 2023Q3 references this bug: URL: https://cgit.FreeBSD.org/ports/commit/?id=7233b4d8b95baff0f2f2915a8e93a5df2b6e5c4b commit 7233b4d8b95baff0f2f2915a8e93a5df2b6e5c4b Author: Cy Schubert <cy@FreeBSD.org> AuthorDate: 2023-09-12 05:08:11 +0000 Commit: Cy Schubert <cy@FreeBSD.org> CommitDate: 2023-09-15 14:07:43 +0000 security/wpa_supplicant-devel: Reapply c586ac04eb66 Reapply "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, 273696 Obtained from: src 6e5d01124fd4 Reported by: Damjan Jovanovic <damjan.jov@gmail.com>, bz (privately) (cherry picked from commit 5da13f40eeaa4b39b3a9fd41e58d082e954acce6) security/wpa_supplicant-devel/Makefile | 2 +- .../files/patch-src_l2__packet_l2__packet__freebsd.c | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-)