From: Jack Pham <jackp@codeaurora.org>
To: William Wu <william.wu@rock-chips.com>
Cc: gregkh@linuxfoundation.org, felipe.balbi@linux.intel.com,
linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org,
linux-rockchip@lists.infradead.org, frank.wang@rock-chips.com,
huangtao@rock-chips.com, daniel.meng@rock-chips.com,
fml@rock-chips.com
Subject: Re: [PATCH] usb: gadget: f_fs: get the correct address of comp_desc
Date: Mon, 5 Feb 2018 10:17:58 -0800 [thread overview]
Message-ID: <20180205181758.GA22738@usblab-sd-06.qualcomm.com> (raw)
In-Reply-To: <1517830418-2648-1-git-send-email-william.wu@rock-chips.com>
Hi William,
On Mon, Feb 05, 2018 at 07:33:38PM +0800, William Wu wrote:
> Refer to the USB 3.0 spec '9.6.7 SuperSpeed Endpoint Companion',
> the companion descriptor follows the standard endpoint descriptor.
> This descriptor is only defined for SuperSpeed endpoints. The
> f_fs driver gets the address of the companion descriptor via
> 'ds + USB_DT_ENDPOINT_SIZE', and actually, the ds variable is
> a pointer to the struct usb_endpoint_descriptor, so the offset
> of the companion descriptor which we get is USB_DT_ENDPOINT_SIZE *
> sizeof(struct usb_endpoint_descriptor), the wrong offset is 63
> bytes. This cause out-of-bound with the following error log if
> CONFIG_KASAN and CONFIG_SLUB_DEBUG is enabled on Rockchip RK3399
> Evaluation Board.
>
> android_work: sent uevent USB_STATE=CONNECTED
> configfs-gadget gadget: super-speed config #1: b
> ==================================================================
> BUG: KASAN: slab-out-of-bounds in ffs_func_set_alt+0x230/0x398
> Read of size 1 at addr ffffffc0ce2d0b10 by task irq/224-dwc3/364
> Memory state around the buggy address:
> ffffffc0ce2d0a00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
> ffffffc0ce2d0a80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
> >ffffffc0ce2d0b00: 00 04 fc fc fc fc fc fc fc fc fc fc fc fc fc fc
> ^
> ffffffc0ce2d0b80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
> ffffffc0ce2d0c00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
> ==================================================================
> Disabling lock debugging due to kernel taint
> android_work: sent uevent USB_STATE=CONFIGURED
>
> This patch adds struct usb_endpoint_descriptor * -> u8 * type conversion
> for ds variable, then we can get the correct address of comp_desc
> with offset USB_DT_ENDPOINT_SIZE bytes.
>
> Signed-off-by: William Wu <william.wu@rock-chips.com>
> ---
> drivers/usb/gadget/function/f_fs.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
> index 6756472..f13ead0 100644
> --- a/drivers/usb/gadget/function/f_fs.c
> +++ b/drivers/usb/gadget/function/f_fs.c
> @@ -1882,8 +1882,8 @@ static int ffs_func_eps_enable(struct ffs_function *func)
> ep->ep->desc = ds;
>
> if (needs_comp_desc) {
> - comp_desc = (struct usb_ss_ep_comp_descriptor *)(ds +
> - USB_DT_ENDPOINT_SIZE);
> + comp_desc = (struct usb_ss_ep_comp_descriptor *)
> + ((u8 *)ds + USB_DT_ENDPOINT_SIZE);
> ep->ep->maxburst = comp_desc->bMaxBurst + 1;
> ep->ep->comp_desc = comp_desc;
> }
Please see my alternative fix for this. I proposed changing this
function to use config_ep_by_speed() instead.
https://www.spinics.net/lists/linux-usb/msg165149.html
Jack
--
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
next prev parent reply other threads:[~2018-02-05 18:17 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-05 11:33 [PATCH] usb: gadget: f_fs: get the correct address of comp_desc William Wu
2018-02-05 18:17 ` Jack Pham [this message]
2018-02-06 14:10 ` wlf
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=20180205181758.GA22738@usblab-sd-06.qualcomm.com \
--to=jackp@codeaurora.org \
--cc=daniel.meng@rock-chips.com \
--cc=felipe.balbi@linux.intel.com \
--cc=fml@rock-chips.com \
--cc=frank.wang@rock-chips.com \
--cc=gregkh@linuxfoundation.org \
--cc=huangtao@rock-chips.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=linux-usb@vger.kernel.org \
--cc=william.wu@rock-chips.com \
/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