* [PATCH] mac80211: debugfs: bound queue state formatting to PAGE_SIZE
@ 2026-04-17 7:46 Pengpeng Hou
2026-04-17 7:56 ` Johannes Berg
0 siblings, 1 reply; 2+ messages in thread
From: Pengpeng Hou @ 2026-04-17 7:46 UTC (permalink / raw)
To: Johannes Berg; +Cc: linux-wireless, linux-kernel, Pengpeng Hou
queues_read() formats all queue state lines into a fixed stack buffer
that budgets only 20 bytes per queue and appends each line with
sprintf().
The queue-stop reason bitmap is printed with %#.8lx, whose width is not
capped on 64-bit builds, and the pending queue length field can add more
digits still. The cumulative output can therefore run past the end of
the fixed stack buffer.
Format the output into a PAGE_SIZE heap buffer with scnprintf() and stop
once the debugfs read buffer is full.
Fixes: db2e6bd4e966 ("mac80211: add queue debugfs file")
Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>
---
net/mac80211/debugfs.c | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
diff --git a/net/mac80211/debugfs.c b/net/mac80211/debugfs.c
index 5a1831b08677..2cf6342d28db 100644
--- a/net/mac80211/debugfs.c
+++ b/net/mac80211/debugfs.c
@@ -9,6 +9,7 @@
#include <linux/debugfs.h>
#include <linux/rtnetlink.h>
+#include <linux/slab.h>
#include <linux/vmalloc.h>
#include "ieee80211_i.h"
#include "driver-ops.h"
@@ -596,17 +597,24 @@ static ssize_t queues_read(struct file *file, char __user *user_buf,
{
struct ieee80211_local *local = file->private_data;
unsigned long flags;
- char buf[IEEE80211_MAX_QUEUES * 20];
- int q, res = 0;
+ char *buf;
+ int q, res = 0, ret;
+
+ buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
+ if (!buf)
+ return -ENOMEM;
spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
- for (q = 0; q < local->hw.queues; q++)
- res += sprintf(buf + res, "%02d: %#.8lx/%d\n", q,
- local->queue_stop_reasons[q],
- skb_queue_len(&local->pending[q]));
+ for (q = 0; q < local->hw.queues && res < PAGE_SIZE; q++)
+ res += scnprintf(buf + res, PAGE_SIZE - res,
+ "%02d: %#.8lx/%d\n", q,
+ local->queue_stop_reasons[q],
+ skb_queue_len(&local->pending[q]));
spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
- return simple_read_from_buffer(user_buf, count, ppos, buf, res);
+ ret = simple_read_from_buffer(user_buf, count, ppos, buf, res);
+ kfree(buf);
+ return ret;
}
DEBUGFS_READONLY_FILE_OPS(queues);
--
2.50.1 (Apple Git-155)
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] mac80211: debugfs: bound queue state formatting to PAGE_SIZE
2026-04-17 7:46 [PATCH] mac80211: debugfs: bound queue state formatting to PAGE_SIZE Pengpeng Hou
@ 2026-04-17 7:56 ` Johannes Berg
0 siblings, 0 replies; 2+ messages in thread
From: Johannes Berg @ 2026-04-17 7:56 UTC (permalink / raw)
To: Pengpeng Hou; +Cc: linux-wireless, linux-kernel
On Fri, 2026-04-17 at 15:46 +0800, Pengpeng Hou wrote:
> queues_read() formats all queue state lines into a fixed stack buffer
> that budgets only 20 bytes per queue and appends each line with
> sprintf().
>
> The queue-stop reason bitmap is printed with %#.8lx, whose width is not
> capped on 64-bit builds, and the pending queue length field can add more
> digits still. The cumulative output can therefore run past the end of
> the fixed stack buffer.
I'd agree the code isn't optimal, but this simply isn't true.
> Format the output into a PAGE_SIZE heap buffer with scnprintf() and stop
> once the debugfs read buffer is full.
And the fix is just strange.
> Fixes: db2e6bd4e966 ("mac80211: add queue debugfs file")
>
> Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>
There also should be no blank line there.
johannes
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-04-17 7:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-17 7:46 [PATCH] mac80211: debugfs: bound queue state formatting to PAGE_SIZE Pengpeng Hou
2026-04-17 7:56 ` Johannes Berg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox