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-next>] [day] [month] [year] [list]
Message-ID: <20251027193152.3906497-1-Pavel.Zhigulin@kaspersky.com>
Date: Mon, 27 Oct 2025 22:31:50 +0300
From: Pavel Zhigulin <Pavel.Zhigulin@...persky.com>
To: Chunfeng Yun <chunfeng.yun@...iatek.com>
CC: Pavel Zhigulin <Pavel.Zhigulin@...persky.com>, Greg Kroah-Hartman
	<gregkh@...uxfoundation.org>, <linux-usb@...r.kernel.org>,
	<linux-arm-kernel@...ts.infradead.org>, <linux-mediatek@...ts.infradead.org>,
	<linux-kernel@...r.kernel.org>, <lvc-project@...uxtesting.org>
Subject: [PATCH] usb: mtu3: fix possible NULL pointer dereference in ep0_rx_state()

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@...persky.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


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ