lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CA+fCnZd2GoU6LVvT4eBT3w7TigRrp_9XcAGyL55K5nbi3yt4sA@mail.gmail.com>
Date:   Thu, 10 Mar 2022 00:59:29 +0100
From:   Andrey Konovalov <andreyknvl@...il.com>
To:     Wei Ming Chen <jj251510319013@...il.com>
Cc:     LKML <linux-kernel@...r.kernel.org>,
        Felipe Balbi <balbi@...nel.org>,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        USB list <linux-usb@...r.kernel.org>
Subject: Re: [PATCH] usb: gadget: return -EINVAL if no proper ep address available

On Tue, Mar 8, 2022 at 12:31 PM Wei Ming Chen <jj251510319013@...il.com> wrote:
>

Hi,

The commit name should be prefixed with "usb: raw-gadget:".

> If we try to use raw_ioctl_ep_enable() for ep5in on a hardware that
> only support from ep1-ep4 for both in and out direction, it will return
> -EBUSY originally.
>
> I think it will be more intuitive if we return -EINVAL, Cuz -EBUSY sounds
> like ep5in is not available now, but might be available in the future.

Cuz -> because

>
> Signed-off-by: Wei Ming Chen <jj251510319013@...il.com>
> ---
>  drivers/usb/gadget/legacy/raw_gadget.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/drivers/usb/gadget/legacy/raw_gadget.c b/drivers/usb/gadget/legacy/raw_gadget.c
> index d86c3a36441e..b4cc083a7ca6 100644
> --- a/drivers/usb/gadget/legacy/raw_gadget.c
> +++ b/drivers/usb/gadget/legacy/raw_gadget.c
> @@ -758,6 +758,7 @@ static int raw_ioctl_ep_enable(struct raw_dev *dev, unsigned long value)
>         unsigned long flags;
>         struct usb_endpoint_descriptor *desc;
>         struct raw_ep *ep;
> +       bool ep_num_matched = false;
>
>         desc = memdup_user((void __user *)value, sizeof(*desc));
>         if (IS_ERR(desc))
> @@ -792,6 +793,7 @@ static int raw_ioctl_ep_enable(struct raw_dev *dev, unsigned long value)
>                 if (ep->addr != usb_endpoint_num(desc) &&
>                                 ep->addr != USB_RAW_EP_ADDR_ANY)
>                         continue;
> +               ep_num_matched = true;
>                 if (!usb_gadget_ep_match_desc(dev->gadget, ep->ep, desc, NULL))
>                         continue;
>                 ep->ep->desc = desc;
> @@ -815,6 +817,12 @@ static int raw_ioctl_ep_enable(struct raw_dev *dev, unsigned long value)
>                 goto out_unlock;
>         }
>
> +       if (!ep_num_matched) {
> +               dev_dbg(&dev->gadget->dev, "fail, no proper ep address available\n");
> +               ret = -EINVAL;
> +               goto out_free;
> +       }

Thinking more about this, we should cover the following cases:

1. If there are no endpoints that match the provided descriptor, return EINVAL.

2. If there are matching endpoints, but they are all already enabled,
return EBUSY.

A draft change is attached.

What do you think?

If the suggested change looks good, feel free to incorporate it into
the version 2 of your patch.

> +
>         dev_dbg(&dev->gadget->dev, "fail, no gadget endpoints available\n");
>         ret = -EBUSY;
>
> --
> 2.25.1
>

Thanks!

View attachment "raw-gadget-retval.patch" of type "text/x-patch" (1208 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ