Skip to content

Commit

Permalink
security/wpa_supplicant-devel: Reapply c586ac0
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cschuber committed Sep 12, 2023
1 parent 1da2ce6 commit 5da13f4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion security/wpa_supplicant-devel/Makefile
@@ -1,6 +1,6 @@
PORTNAME= wpa_supplicant
PORTVERSION= ${COMMIT_DATE}
PORTREVISION= 1
PORTREVISION= 2
CATEGORIES= security net
PKGNAMESUFFIX= -devel

Expand Down
@@ -1,5 +1,5 @@
--- 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
--- src/l2_packet/l2_packet_freebsd.c.orig 2023-09-05 10:38:47.000000000 -0700
+++ src/l2_packet/l2_packet_freebsd.c 2023-09-11 22:06:24.154851000 -0700
@@ -8,7 +8,10 @@
*/

Expand All @@ -12,3 +12,15 @@
#include <net/bpf.h>
#endif /* __APPLE__ */
#include <pcap.h>
@@ -82,7 +85,10 @@
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;

0 comments on commit 5da13f4

Please sign in to comment.