🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
3 messages
3 total messages Started by Aibing Chen Fri, 20 Nov 2026 07:50
[PATCH net] net/mlx5: fix a stack over-read in the QP debugfs files
#19679
Author: Aibing Chen
Date: Fri, 20 Nov 2026 07:50
47 lines
10436 bytes
dbg_read() formats the field into char tbuf[18] and passes the return
value of snprintf() to simple_read_from_buffer() as the number of
available bytes.  snprintf() returns the length the output would have
had, not the number of bytes written, so when the string does not fit
that value is larger than the buffer: the longest QP transport string is
"Invalid transport type" (22 characters), so with the trailing newline
the function returns 23 while only 18 bytes were written.

simple_read_from_buffer() uses that length to bound the copy to
userspace, so reading .../qp/<qpn>/transport copies up to 23 bytes out of
the 18 byte stack array, leaking 5 bytes of stack.

Enlarge the buffer so the longest string fits and use scnprintf(), which
returns the number of bytes actually written.

Signed-off-by: Aibing Chen <chenaibing@cmss.chinamobile.com>
---
 drivers/net/ethernet/mellanox/mlx5/core/debugfs.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/debugfs.c b/drivers/net/ethernet/mellanox/mlx5/core/debugfs.c
index 30be2b631..3e75f66f7 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/debugfs.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/debugfs.c
@@ -496,7 +496,7 @@ static ssize_t dbg_read(struct file *filp, char __user *buf, size_t count,
 {
 	struct mlx5_field_desc *desc;
 	struct mlx5_rsc_debug *d;
-	char tbuf[18];
+	char tbuf[24];
 	int is_str = 0;
 	u64 field;
 	int ret;
@@ -522,9 +522,10 @@ static ssize_t dbg_read(struct file *filp, char __user *buf, size_t count,
 	}
 
 	if (is_str)
-		ret = snprintf(tbuf, sizeof(tbuf), "%s\n", (const char *)(unsigned long)field);
+		ret = scnprintf(tbuf, sizeof(tbuf), "%s\n",
+				(const char *)(unsigned long)field);
 	else
-		ret = snprintf(tbuf, sizeof(tbuf), "0x%llx\n", field);
+		ret = scnprintf(tbuf, sizeof(tbuf), "0x%llx\n", field);
 
 	return simple_read_from_buffer(buf, count, pos, tbuf, ret);
 }
Re: [PATCH net] net/mlx5: fix a stack over-read in the QP debugfs files
#19680
Author: netdev-bot+sinfo
Date: Fri, 20 Nov 2026 07:53
27 lines
9049 bytes
Hi!

This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:

 - How the issue was discovered, e.g. hit in production, hit during
   development, syzbot report, manual code inspection, LLM or static
   analysis tool scan.

 - Whether the issue was actually triggered, or is only theoretical
   (e.g. found by LLM and not proven at runtime). If it was triggered
   please include the symptoms, like the stack trace or kernel messages.

 - What hardware the change was tested on. For driver fixes please
   mention the device (and if relevant firmware version) used for
   testing, or say that the change was not tested on real hardware.

Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
-- 
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
Re: [PATCH net] net/mlx5: fix a stack over-read in the QP debugfs files
#19734
Author: Aibing Chen
Date: Fri, 20 Nov 2026 09:53
22 lines
9727 bytes
Hi,

How it was found: by code inspection, not from a report or a tool - while
looking at how the mlx5 debugfs field readers use the return value of
snprintf().

Was it triggered: no, I did not reproduce it at runtime.  It is statically
decidable from the code: snprintf() returns the length the output would
have had (23 for "Invalid transport type" plus the newline) instead of the
number of bytes written (18), and simple_read_from_buffer() uses that
value to bound the copy to userspace.  It is only reachable when the
device reports a QP transport value that mlx5_qp_type_str() does not name.

Hardware: not tested on real hardware, I do not have mlx5 hardware
available.  The change only uses scnprintf() so that the length passed to
simple_read_from_buffer() can no longer exceed the buffer, and enlarges
the buffer so that the longest string still fits; neither needs device
specific behaviour.

Thanks,
Aibing Chen
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads