From: Weigang He <geoffreyhe2@gmail.com>
To: mathias.nyman@intel.com, gregkh@linuxfoundation.org
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org, Weigang He <geoffreyhe2@gmail.com>
Subject: [PATCH] usb: xhci: fix missing null termination after copy_from_user()
Date: Sat, 17 Jan 2026 09:46:31 +0000 [thread overview]
Message-ID: <20260117094631.504232-1-geoffreyhe2@gmail.com> (raw)
The buffer 'buf' is filled by copy_from_user() but is not properly
null-terminated before being used with strncmp(). If userspace provides
fewer than 10 bytes, strncmp() may read beyond the copied data into
uninitialized stack memory.
Add explicit null termination after copy_from_user() to ensure the
buffer is always a valid C string before string operations.
Fixes: 87a03802184c ("xhci: debugfs: add debugfs interface to enable compliance mode for a port")
Cc: stable@vger.kernel.org
Signed-off-by: Weigang He <geoffreyhe2@gmail.com>
---
drivers/usb/host/xhci-debugfs.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/host/xhci-debugfs.c b/drivers/usb/host/xhci-debugfs.c
index c1eb1036ede95..1e2350de77775 100644
--- a/drivers/usb/host/xhci-debugfs.c
+++ b/drivers/usb/host/xhci-debugfs.c
@@ -347,11 +347,13 @@ static ssize_t xhci_port_write(struct file *file, const char __user *ubuf,
struct xhci_port *port = s->private;
struct xhci_hcd *xhci = hcd_to_xhci(port->rhub->hcd);
char buf[32];
+ size_t len = min_t(size_t, sizeof(buf) - 1, count);
u32 portsc;
unsigned long flags;
- if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
+ if (copy_from_user(&buf, ubuf, len))
return -EFAULT;
+ buf[len] = '\0';
if (!strncmp(buf, "compliance", 10)) {
/* If CTC is clear, compliance is enabled by default */
--
2.34.1
next reply other threads:[~2026-01-17 9:46 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-17 9:46 Weigang He [this message]
2026-01-17 9:58 ` [PATCH] usb: xhci: fix missing null termination after copy_from_user() Greg KH
[not found] ` <SE1P216MB1822A187820001789CB4EE3AF28AA@SE1P216MB1822.KORP216.PROD.OUTLOOK.COM>
2026-01-17 10:25 ` Greg KH
2026-01-17 12:06 ` David Laight
2026-01-17 12:17 ` Greg KH
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=20260117094631.504232-1-geoffreyhe2@gmail.com \
--to=geoffreyhe2@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mathias.nyman@intel.com \
--cc=stable@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