* [PATCH] usb: core: Strengthen error handling in hub_hub_status()
@ 2026-07-14 9:04 Griffin Kroah-Hartman
2026-07-14 16:32 ` Alan Stern
0 siblings, 1 reply; 5+ messages in thread
From: Griffin Kroah-Hartman @ 2026-07-14 9:04 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: linux-usb, linux-kernel, Griffin Kroah-Hartman
Add additional error handling after the call to get_hub_status() in
hub_hub_status().
get_hub_status() uses usb_control_msg() which does not verify that the
message is the correct length, substituting it for
usb_control_msg_recv() would also solve this issue but increase memory
allocations.
Instead, error handling is copied from the method used in
hub_ext_port_status(), which shares the same flow of logic as
hub_hub_status().
Assisted-by: gkh_clanker_t1000
Signed-off-by: Griffin Kroah-Hartman <griffin@kroah.com>
---
drivers/usb/core/hub.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 5262e11c12cd..0d2166b8923a 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -991,10 +991,12 @@ static int hub_hub_status(struct usb_hub *hub,
mutex_lock(&hub->status_mutex);
ret = get_hub_status(hub->hdev, &hub->status->hub);
- if (ret < 0) {
+ if (ret < sizeof(hub->status->hub)) {
if (ret != -ENODEV)
dev_err(hub->intfdev,
"%s failed (err = %d)\n", __func__, ret);
+ if (ret >= 0)
+ ret = -EIO;
} else {
*status = le16_to_cpu(hub->status->hub.wHubStatus);
*change = le16_to_cpu(hub->status->hub.wHubChange);
---
base-commit: a13c140cc289c0b7b3770bce5b3ad42ab35074aa
change-id: 20260714-usb_core_patches_2-a3eb9d1b7b9e
Best regards,
--
Griffin Kroah-Hartman <griffin@kroah.com>
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] usb: core: Strengthen error handling in hub_hub_status()
2026-07-14 9:04 [PATCH] usb: core: Strengthen error handling in hub_hub_status() Griffin Kroah-Hartman
@ 2026-07-14 16:32 ` Alan Stern
2026-07-14 17:48 ` Oliver Neukum
2026-07-17 9:48 ` Greg Kroah-Hartman
0 siblings, 2 replies; 5+ messages in thread
From: Alan Stern @ 2026-07-14 16:32 UTC (permalink / raw)
To: Griffin Kroah-Hartman; +Cc: Greg Kroah-Hartman, linux-usb, linux-kernel
On Tue, Jul 14, 2026 at 11:04:33AM +0200, Griffin Kroah-Hartman wrote:
> Add additional error handling after the call to get_hub_status() in
> hub_hub_status().
>
> get_hub_status() uses usb_control_msg() which does not verify that the
> message is the correct length, substituting it for
> usb_control_msg_recv() would also solve this issue but increase memory
> allocations.
>
> Instead, error handling is copied from the method used in
> hub_ext_port_status(), which shares the same flow of logic as
> hub_hub_status().
>
> Assisted-by: gkh_clanker_t1000
> Signed-off-by: Griffin Kroah-Hartman <griffin@kroah.com>
> ---
> drivers/usb/core/hub.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
> index 5262e11c12cd..0d2166b8923a 100644
> --- a/drivers/usb/core/hub.c
> +++ b/drivers/usb/core/hub.c
> @@ -991,10 +991,12 @@ static int hub_hub_status(struct usb_hub *hub,
>
> mutex_lock(&hub->status_mutex);
> ret = get_hub_status(hub->hdev, &hub->status->hub);
> - if (ret < 0) {
> + if (ret < sizeof(hub->status->hub)) {
> if (ret != -ENODEV)
> dev_err(hub->intfdev,
> "%s failed (err = %d)\n", __func__, ret);
> + if (ret >= 0)
> + ret = -EIO;
It would be better to put these two lines above the preceding test.
That way it won't print confusing things like "hub_hub_status failed
(err = 2)".
Alan Stern
> } else {
> *status = le16_to_cpu(hub->status->hub.wHubStatus);
> *change = le16_to_cpu(hub->status->hub.wHubChange);
>
> ---
> base-commit: a13c140cc289c0b7b3770bce5b3ad42ab35074aa
> change-id: 20260714-usb_core_patches_2-a3eb9d1b7b9e
>
> Best regards,
> --
> Griffin Kroah-Hartman <griffin@kroah.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] usb: core: Strengthen error handling in hub_hub_status()
2026-07-14 16:32 ` Alan Stern
@ 2026-07-14 17:48 ` Oliver Neukum
2026-07-14 18:59 ` Alan Stern
2026-07-17 9:48 ` Greg Kroah-Hartman
1 sibling, 1 reply; 5+ messages in thread
From: Oliver Neukum @ 2026-07-14 17:48 UTC (permalink / raw)
To: Alan Stern, Griffin Kroah-Hartman
Cc: Greg Kroah-Hartman, linux-usb, linux-kernel
On 14.07.26 18:32, Alan Stern wrote:
>> diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
>> index 5262e11c12cd..0d2166b8923a 100644
>> --- a/drivers/usb/core/hub.c
>> +++ b/drivers/usb/core/hub.c
>> @@ -991,10 +991,12 @@ static int hub_hub_status(struct usb_hub *hub,
>>
>> mutex_lock(&hub->status_mutex);
>> ret = get_hub_status(hub->hdev, &hub->status->hub);
>> - if (ret < 0) {
>> + if (ret < sizeof(hub->status->hub)) {
>> if (ret != -ENODEV)
>> dev_err(hub->intfdev,
>> "%s failed (err = %d)\n", __func__, ret);
>> + if (ret >= 0)
>> + ret = -EIO;
>
> It would be better to put these two lines above the preceding test.
> That way it won't print confusing things like "hub_hub_status failed
> (err = 2)".
I am afraid I have to disagree. We would in effect say that get_hub_status()
has returned -EIO. That is simply not true.
Regards
Oliver
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] usb: core: Strengthen error handling in hub_hub_status()
2026-07-14 17:48 ` Oliver Neukum
@ 2026-07-14 18:59 ` Alan Stern
0 siblings, 0 replies; 5+ messages in thread
From: Alan Stern @ 2026-07-14 18:59 UTC (permalink / raw)
To: Oliver Neukum
Cc: Griffin Kroah-Hartman, Greg Kroah-Hartman, linux-usb,
linux-kernel
On Tue, Jul 14, 2026 at 07:48:14PM +0200, Oliver Neukum wrote:
> On 14.07.26 18:32, Alan Stern wrote:
>
> > > diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
> > > index 5262e11c12cd..0d2166b8923a 100644
> > > --- a/drivers/usb/core/hub.c
> > > +++ b/drivers/usb/core/hub.c
> > > @@ -991,10 +991,12 @@ static int hub_hub_status(struct usb_hub *hub,
> > > mutex_lock(&hub->status_mutex);
> > > ret = get_hub_status(hub->hdev, &hub->status->hub);
> > > - if (ret < 0) {
> > > + if (ret < sizeof(hub->status->hub)) {
> > > if (ret != -ENODEV)
> > > dev_err(hub->intfdev,
> > > "%s failed (err = %d)\n", __func__, ret);
> > > + if (ret >= 0)
> > > + ret = -EIO;
> >
> > It would be better to put these two lines above the preceding test.
> > That way it won't print confusing things like "hub_hub_status failed
> > (err = 2)".
> I am afraid I have to disagree. We would in effect say that get_hub_status()
> has returned -EIO. That is simply not true.
On the contrary: The message would say that hub_hub_status is returning
-EIO, which _is_ true.
Of course, the error message could instead be changed in the way you
suggest:
dev_err(hub->intfev,
"get_hub_status failed (%d)\n", ret);
Either my change or yours would be okay with me, but I don't like what
the patch does.
(Another question is whether this message deserves to be dev_err().
There isn't anything the user can do about it when it happens, so maybe
it should be dev_dbg() instead.)
Alan Stern
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] usb: core: Strengthen error handling in hub_hub_status()
2026-07-14 16:32 ` Alan Stern
2026-07-14 17:48 ` Oliver Neukum
@ 2026-07-17 9:48 ` Greg Kroah-Hartman
1 sibling, 0 replies; 5+ messages in thread
From: Greg Kroah-Hartman @ 2026-07-17 9:48 UTC (permalink / raw)
To: Alan Stern; +Cc: Griffin Kroah-Hartman, linux-usb, linux-kernel
On Tue, Jul 14, 2026 at 12:32:06PM -0400, Alan Stern wrote:
> On Tue, Jul 14, 2026 at 11:04:33AM +0200, Griffin Kroah-Hartman wrote:
> > Add additional error handling after the call to get_hub_status() in
> > hub_hub_status().
> >
> > get_hub_status() uses usb_control_msg() which does not verify that the
> > message is the correct length, substituting it for
> > usb_control_msg_recv() would also solve this issue but increase memory
> > allocations.
> >
> > Instead, error handling is copied from the method used in
> > hub_ext_port_status(), which shares the same flow of logic as
> > hub_hub_status().
> >
> > Assisted-by: gkh_clanker_t1000
> > Signed-off-by: Griffin Kroah-Hartman <griffin@kroah.com>
> > ---
> > drivers/usb/core/hub.c | 4 +++-
> > 1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
> > index 5262e11c12cd..0d2166b8923a 100644
> > --- a/drivers/usb/core/hub.c
> > +++ b/drivers/usb/core/hub.c
> > @@ -991,10 +991,12 @@ static int hub_hub_status(struct usb_hub *hub,
> >
> > mutex_lock(&hub->status_mutex);
> > ret = get_hub_status(hub->hdev, &hub->status->hub);
> > - if (ret < 0) {
> > + if (ret < sizeof(hub->status->hub)) {
> > if (ret != -ENODEV)
> > dev_err(hub->intfdev,
> > "%s failed (err = %d)\n", __func__, ret);
> > + if (ret >= 0)
> > + ret = -EIO;
>
> It would be better to put these two lines above the preceding test.
> That way it won't print confusing things like "hub_hub_status failed
> (err = 2)".
It is confusing, but it matches the other check for this same error in
hub_ext_port_status() as it's the same error condition. How about this
patch happens first int he series, which "unifies" them, and then fix up
both of the patterns at the same time to be more clear in a later patch
in the series?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-07-17 9:48 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-14 9:04 [PATCH] usb: core: Strengthen error handling in hub_hub_status() Griffin Kroah-Hartman
2026-07-14 16:32 ` Alan Stern
2026-07-14 17:48 ` Oliver Neukum
2026-07-14 18:59 ` Alan Stern
2026-07-17 9:48 ` Greg Kroah-Hartman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox