* [PATCH] usb: mtu3: fix possible NULL pointer dereference in ep0_rx_state()
@ 2025-10-27 19:31 Pavel Zhigulin
2025-10-28 9:07 ` Greg Kroah-Hartman
0 siblings, 1 reply; 2+ messages in thread
From: Pavel Zhigulin @ 2025-10-27 19:31 UTC (permalink / raw)
To: Chunfeng Yun
Cc: Pavel Zhigulin, Greg Kroah-Hartman, linux-usb, linux-arm-kernel,
linux-mediatek, linux-kernel, lvc-project
The function 'ep0_rx_state()' accessed 'mreq->request' before verifying
that mreq was valid. If 'next_ep0_request()' returned NULL, this could
lead to a NULL pointer dereference. The return value of
'next_ep0_request()' is checked in every other code path except
here. It appears that the intended 'if (mreq)' check was mistakenly
written as 'if (req)', since the req pointer cannot be NULL when mreq
is not NULL.
Initialize 'mreq' and 'req' to NULL by default, and switch 'req'
NULL-checking to 'mreq' non-NULL check to prevent invalid memory access.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
Fixes: df2069acb005 ("usb: Add MediaTek USB3 DRD driver")
Signed-off-by: Pavel Zhigulin <Pavel.Zhigulin@kaspersky.com>
---
drivers/usb/mtu3/mtu3_gadget_ep0.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/usb/mtu3/mtu3_gadget_ep0.c b/drivers/usb/mtu3/mtu3_gadget_ep0.c
index e4fd1bb14a55..ee7466ca4d99 100644
--- a/drivers/usb/mtu3/mtu3_gadget_ep0.c
+++ b/drivers/usb/mtu3/mtu3_gadget_ep0.c
@@ -508,8 +508,8 @@ static int handle_standard_request(struct mtu3 *mtu,
/* receive an data packet (OUT) */
static void ep0_rx_state(struct mtu3 *mtu)
{
- struct mtu3_request *mreq;
- struct usb_request *req;
+ struct mtu3_request *mreq = NULL;
+ struct usb_request *req = NULL;
void __iomem *mbase = mtu->mac_base;
u32 maxp;
u32 csr;
@@ -519,10 +519,11 @@ static void ep0_rx_state(struct mtu3 *mtu)
csr = mtu3_readl(mbase, U3D_EP0CSR) & EP0_W1C_BITS;
mreq = next_ep0_request(mtu);
- req = &mreq->request;
/* read packet and ack; or stall because of gadget driver bug */
- if (req) {
+ if (mreq) {
+ req = &mreq->request;
+
void *buf = req->buf + req->actual;
unsigned int len = req->length - req->actual;
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] usb: mtu3: fix possible NULL pointer dereference in ep0_rx_state()
2025-10-27 19:31 [PATCH] usb: mtu3: fix possible NULL pointer dereference in ep0_rx_state() Pavel Zhigulin
@ 2025-10-28 9:07 ` Greg Kroah-Hartman
0 siblings, 0 replies; 2+ messages in thread
From: Greg Kroah-Hartman @ 2025-10-28 9:07 UTC (permalink / raw)
To: Pavel Zhigulin
Cc: Chunfeng Yun, linux-usb, linux-arm-kernel, linux-mediatek,
linux-kernel, lvc-project
On Mon, Oct 27, 2025 at 10:31:50PM +0300, Pavel Zhigulin wrote:
> The function 'ep0_rx_state()' accessed 'mreq->request' before verifying
> that mreq was valid. If 'next_ep0_request()' returned NULL, this could
> lead to a NULL pointer dereference. The return value of
> 'next_ep0_request()' is checked in every other code path except
> here. It appears that the intended 'if (mreq)' check was mistakenly
> written as 'if (req)', since the req pointer cannot be NULL when mreq
> is not NULL.
>
> Initialize 'mreq' and 'req' to NULL by default, and switch 'req'
> NULL-checking to 'mreq' non-NULL check to prevent invalid memory access.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Fixes: df2069acb005 ("usb: Add MediaTek USB3 DRD driver")
> Signed-off-by: Pavel Zhigulin <Pavel.Zhigulin@kaspersky.com>
> ---
> drivers/usb/mtu3/mtu3_gadget_ep0.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/usb/mtu3/mtu3_gadget_ep0.c b/drivers/usb/mtu3/mtu3_gadget_ep0.c
> index e4fd1bb14a55..ee7466ca4d99 100644
> --- a/drivers/usb/mtu3/mtu3_gadget_ep0.c
> +++ b/drivers/usb/mtu3/mtu3_gadget_ep0.c
> @@ -508,8 +508,8 @@ static int handle_standard_request(struct mtu3 *mtu,
> /* receive an data packet (OUT) */
> static void ep0_rx_state(struct mtu3 *mtu)
> {
> - struct mtu3_request *mreq;
> - struct usb_request *req;
> + struct mtu3_request *mreq = NULL;
> + struct usb_request *req = NULL;
> void __iomem *mbase = mtu->mac_base;
> u32 maxp;
> u32 csr;
> @@ -519,10 +519,11 @@ static void ep0_rx_state(struct mtu3 *mtu)
>
> csr = mtu3_readl(mbase, U3D_EP0CSR) & EP0_W1C_BITS;
> mreq = next_ep0_request(mtu);
> - req = &mreq->request;
>
> /* read packet and ack; or stall because of gadget driver bug */
> - if (req) {
> + if (mreq) {
> + req = &mreq->request;
> +
> void *buf = req->buf + req->actual;
> unsigned int len = req->length - req->actual;
>
> --
> 2.43.0
>
>
Hi,
This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him
a patch that has triggered this response. He used to manually respond
to these common problems, but in order to save his sanity (he kept
writing the same thing over and over, yet to different people), I was
created. Hopefully you will not take offence and will fix the problem
in your patch and resubmit it so that it can be accepted into the Linux
kernel tree.
You are receiving this message because of the following common error(s)
as indicated below:
- You have marked a patch with a "Fixes:" tag for a commit that is in an
older released kernel, yet you do not have a cc: stable line in the
signed-off-by area at all, which means that the patch will not be
applied to any older kernel releases. To properly fix this, please
follow the documented rules in the
Documentation/process/stable-kernel-rules.rst file for how to resolve
this.
If you wish to discuss this problem further, or you have questions about
how to resolve this issue, please feel free to respond to this email and
Greg will reply once he has dug out from the pending patches received
from other developers.
thanks,
greg k-h's patch email bot
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-10-28 9:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-27 19:31 [PATCH] usb: mtu3: fix possible NULL pointer dereference in ep0_rx_state() Pavel Zhigulin
2025-10-28 9:07 ` 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;
as well as URLs for NNTP newsgroup(s).