From: Oliver Neukum <oneukum@suse.com>
To: gregkh@linuxfoundation.org, stern@rowland.harvard.edu,
liulongfang@huawei.com, linux-usb@vger.kernel.org
Cc: Oliver Neukum <oneukum@suse.com>
Subject: [PATCH] USB: hub: make sure stale buffers are not enumerated
Date: Mon, 24 Jul 2023 14:40:57 +0200 [thread overview]
Message-ID: <20230724124057.12975-1-oneukum@suse.com> (raw)
Quoting Alan Stern on why we cannot just check errors:
The operation carried out here is deliberately unsafe (for full-speed
devices). It is made before we know the actual maxpacket size for ep0,
and as a result it might return an error code even when it works okay.
This shouldn't happen, but a lot of USB hardware is unreliable.
Therefore we must not ignore the result merely because r < 0. If we do
that, the kernel might stop working with some devices.
He is absolutely right. However, we must make sure that in case
we read nothing or a short answer, the buffer contains nothing
that can be misinterpreted as a valid answer.
So we have to zero it before we use it for IO.
Reported-by: liulongfang <liulongfang@huawei.com>
Signed-off-by: Oliver Neukum <oneukum@suse.com>
---
drivers/usb/core/hub.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index a739403a9e45..9772716925c3 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -4873,7 +4873,8 @@ hub_port_init(struct usb_hub *hub, struct usb_device *udev, int port1,
}
#define GET_DESCRIPTOR_BUFSIZE 64
- buf = kmalloc(GET_DESCRIPTOR_BUFSIZE, GFP_NOIO);
+ /* zeroed so we don't operate on a stale buffer on errors */
+ buf = kzalloc(GET_DESCRIPTOR_BUFSIZE, GFP_NOIO);
if (!buf) {
retval = -ENOMEM;
continue;
--
2.41.0
next reply other threads:[~2023-07-24 12:41 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-24 12:40 Oliver Neukum [this message]
2023-07-24 13:52 ` [PATCH] USB: hub: make sure stale buffers are not enumerated Johan Hovold
2023-07-24 14:24 ` Oliver Neukum
2023-07-24 14:29 ` Alan Stern
2023-07-24 14:31 ` Oliver Neukum
2023-07-24 15:10 ` Alan Stern
2023-07-24 14:13 ` Alan Stern
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=20230724124057.12975-1-oneukum@suse.com \
--to=oneukum@suse.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-usb@vger.kernel.org \
--cc=liulongfang@huawei.com \
--cc=stern@rowland.harvard.edu \
/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