From: Herve Codina <herve.codina@bootlin.com>
To: Yu Hao <yhao016@ucr.edu>
Cc: chunfeng.yun@mediatek.com, gregkh@linuxfoundation.org,
linux-usb@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org,
linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] usb: mtu3: Fix possible use-before-initialization bug
Date: Wed, 5 Jul 2023 08:06:25 +0200 [thread overview]
Message-ID: <20230705080625.02b2bac5@bootlin.com> (raw)
In-Reply-To: <CA+UBctDxfb6+70+hzuXJ-gwb65E0uoNzXYEhpJT92sXr2CE7OA@mail.gmail.com>
Hi Yu,
On Tue, 4 Jul 2023 16:25:50 -0700
Yu Hao <yhao016@ucr.edu> wrote:
> The struct usb_ctrlrequest setup should be initialized in the function
> ep0_read_setup(mtu, &setup). However, inside that function,
> the variable count could be 0 and the struct usb_ctrlrequest setup
> is not initialized. But there is a read for setup.bRequestType.
>
> Signed-off-by: Yu Hao <yhao016@ucr.edu>
> ---
> drivers/usb/mtu3/mtu3_gadget_ep0.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/usb/mtu3/mtu3_gadget_ep0.c
> b/drivers/usb/mtu3/mtu3_gadget_ep0.c
> index e4fd1bb14a55..67034fa515d0 100644
> --- a/drivers/usb/mtu3/mtu3_gadget_ep0.c
> +++ b/drivers/usb/mtu3/mtu3_gadget_ep0.c
> @@ -638,7 +638,7 @@ static int ep0_handle_setup(struct mtu3 *mtu)
> __releases(mtu->lock)
> __acquires(mtu->lock)
> {
> - struct usb_ctrlrequest setup;
> + struct usb_ctrlrequest setup = {};
> struct mtu3_request *mreq;
> int handled = 0;
>
Looks strange to me because, if ep0_read_setup() cannot read the setup data
why don't we simply abort the operation ?
With setup = {}, the following test is true:
if ((setup.bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD)
handled = handle_standard_request(mtu, &setup);
handle_standard_request() is called and supposes an USB_REQ_GET_STATUS
(0x00) request:
case USB_REQ_GET_STATUS:
handled = ep0_get_status(mtu, setup);
break;
Then ep0_get_status() supposes USB_RECIP_DEVICE (0x00) and performs some
operation sending the data related to the GET_STATUS.
All of these are not correct as the setup data that triggered this sequence
was never received.
Aborting the operation if ep0_read_setup() cannot read the setup data seems
better to me.
Best regards,
Hervé
--
Hervé Codina, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2023-07-05 6:07 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-04 23:25 [PATCH] usb: mtu3: Fix possible use-before-initialization bug Yu Hao
2023-07-05 6:06 ` Herve Codina [this message]
2023-07-10 0:48 ` Yu Hao
2023-07-10 6:25 ` Herve Codina
2023-07-11 8:48 ` Chunfeng Yun (云春峰)
2023-07-11 9:41 ` Herve Codina
2023-07-11 8:40 ` Chunfeng Yun (云春峰)
2023-07-05 7:16 ` 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=20230705080625.02b2bac5@bootlin.com \
--to=herve.codina@bootlin.com \
--cc=chunfeng.yun@mediatek.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-usb@vger.kernel.org \
--cc=yhao016@ucr.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;
as well as URLs for NNTP newsgroup(s).