From: Pengpeng Hou <pengpeng@iscas.ac.cn>
To: Johannes Berg <johannes@sipsolutions.net>
Cc: linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org,
Pengpeng Hou <pengpeng@iscas.ac.cn>
Subject: [PATCH] mac80211: debugfs: bound queue state formatting to PAGE_SIZE
Date: Fri, 17 Apr 2026 15:46:04 +0800 [thread overview]
Message-ID: <20260417074604.18976-1-pengpeng@iscas.ac.cn> (raw)
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)
next reply other threads:[~2026-04-17 7:46 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-17 7:46 Pengpeng Hou [this message]
2026-04-17 7:56 ` [PATCH] mac80211: debugfs: bound queue state formatting to PAGE_SIZE Johannes Berg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260417074604.18976-1-pengpeng@iscas.ac.cn \
--to=pengpeng@iscas.ac.cn \
--cc=johannes@sipsolutions.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-wireless@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox