wifi: mac80211: reject zero or oversized fq_quantum in aqm debugfs
PATCH 1/1 wifi: mac80211: reject zero or oversized fq_quantum in aqm debugfs
The aqm debugfs file lets you set fq.quantum, the byte budget a flow gets each round in the transmit scheduler. aqm_write() accepts any u32 with no check.
The scheduler keeps draining a flow until its budget runs out. A quantum of 0, or one above INT_MAX, makes that budget never go positive -- it stays 0, or wraps negative in the signed counter. The loop then never moves on: it spins forever holding fq->lock, and the first frame sent hangs the CPU:
watchdog: BUG: soft lockup - CPU#1 stuck for 145s! [kworker/1:1] CPU: 1 PID: 22249 Comm: kworker/1:1 Workqueue: mld mld_ifc_work RIP: 0010:__list_del_entry_valid+0x21/0x100 Call Trace: fq_tin_dequeue.constprop.0+0x426/0x8d0 [mac80211] ieee80211_tx_dequeue+0x817/0x15d0 [mac80211] ieee80211_handle_wake_tx_queue+0x1ae/0x2a0 [mac80211] drv_wake_tx_queue+0x1a3/0x350 [mac80211] ieee80211_queue_skb+0x302/0x610 [mac80211] ieee80211_tx+0x261/0x3e0 [mac80211] ieee80211_xmit+0x18c/0x280 [mac80211] __ieee80211_subif_start_xmit+0x5a3/0xb90 [mac80211] ieee80211_subif_start_xmit+0xe2/0x7f0 [mac80211] dev_hard_start_xmit+0x157/0x420 __dev_queue_xmit+0x1116/0x1770 neigh_resolve_output+0x472/0x9c0 ip6_finish_output2+0x87f/0x1320 ip6_output+0x1dd/0x630 mld_sendpack+0x94c/0xd40 mld_ifc_work+0x42/0x270 process_one_work+0x830/0x1330 worker_thread+0x4f3/0xb40 kthread+0x32a/0x410 ret_from_fork+0x2c/0x50
The same lockup was fixed for the netlink knob by d1cba2ea8121, which caps it at INT_MAX; the debugfs knob was left unchecked (netlink also cannot set 0, where 0 means "keep"). The file is root-only (0600), so this is hardening.
Fix: read the value into a local and accept only 1..INT_MAX.
---
Found while reviewing a backport.
Reproduced on almalinux9 5.14.0-503.11.1 debug over mac80211_hwsim: writing 'fq_quantum 0' is accepted and the next TX wedges a CPU as above; with the fix 'fq_quantum 0' and 2147483648 both return -EINVAL and TX keeps running.
net/mac80211/debugfs.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
net/mac80211/debugfs.c +6 -1
@@ -117,6 +117,7 @@ {struct ieee80211_local *local = file->private_data;char buf[100 ]; +u32 quantum;if (count >=sizeof (buf))return -EINVAL ;
@@ -133,8 +134,12 @@return count; else if (sscanf(buf, "fq_memory_limit %u", &local->fq.memory_limit) == 1)return count; - else if (sscanf(buf, "fq_quantum %u", &local->fq.quantum) == 1) + else if (sscanf(buf, "fq_quantum %u", &quantum) == 1) { +if (!quantum || quantum >INT_MAX ) +return -EINVAL ; + local->fq.quantum = quantum;return count; + }return -EINVAL ; }