Thread View: linux.kernel.netdev
1 messages
1 total messages
Started by Weidong Wang via B4 Relay
Sun, 29 Nov 2026 03:17
[PATCH net] cxgb4: reject zero-length write to the MPS trace debugfs files
Author: Weidong Wang via B4 Relay
Date: Sun, 29 Nov 2026 03:17
Date: Sun, 29 Nov 2026 03:17
67 lines
12966 bytes
12966 bytes
From: Weidong Wang <weidongw@illinois.edu>
mps_trc_write(), the write handler of the trace0..trace3 debugfs files,
only rejects writes longer than 1024 bytes. For a zero-length write it
allocates count + 1 = 1 byte, copies nothing and then strips a trailing
newline with:
if (s[count - 1] == '\n')
s[count - 1] = '\0';
With count == 0 this reads s[-1], one byte before the allocation, and
writes a NUL there if that byte happens to be a newline. vfs_write() and
the debugfs proxy pass a zero count through to the handler.
Return -EINVAL for a zero-length write, as mbox_write() in the same file
already does. An empty string is not a valid trace filter anyway: with
no port given the parser ends at the inval label and returns -EINVAL.
The files are mode 0600, so only root can trigger this.
Found by code inspection with an AI-assisted source scanner.
The fix and this changelog were drafted with AI assistance (Claude Code,
with a second review by OpenAI Codex), then reviewed by the submitter.
Fixes: 8e3d04fd7d70 ("cxgb4: Add MPS tracing support")
Signed-off-by: Weidong Wang <weidongw@illinois.edu>
---
Design choice: reject count == 0 with -EINVAL instead of guarding the
newline strip with "count &&". mbox_write() in the same file already
does this, and an empty filter string fails with -EINVAL later anyway
(tp.port stays TRC_PORT_NONE). The one visible difference is that an
empty write no longer writes MPS_TRC_CFG_A before failing.
The pending net-next "cxgb4: extend debugfs support for T7 adapters"
touches the top of mps_trc_write() but not these lines.
Testing:
- Compile-tested on x86_64 (allmodconfig, W=1):
drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.o; no new warnings.
- checkpatch.pl --strict: no errors or warnings.
---
drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c
index f521737d1275..7ffe818ee000 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c
@@ -1429,6 +1429,8 @@ static ssize_t mps_trc_write(struct file *file, const char __user *buf,
*/
if (count > 1024)
return -EFBIG;
+ if (!count)
+ return -EINVAL;
p = s = kzalloc(count + 1, GFP_USER);
if (!s)
return -ENOMEM;
---
base-commit: 28a371228d4eb4857cc31eeb1a0d7d01e9c3ea2f
change-id: 20261128-kbug-l007-bb65998a9910
Best regards,
--
Weidong Wang <weidongw@illinois.edu>
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