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: <20240622142308.1929531-1-make24@iscas.ac.cn>
Date: Sat, 22 Jun 2024 22:23:08 +0800
From: Ma Ke <make24@...as.ac.cn>
To: gregkh@...uxfoundation.org,
	u.kleine-koenig@...gutronix.de,
	make24@...as.ac.cn
Cc: linux-usb@...r.kernel.org,
	linux-kernel@...r.kernel.org
Subject: [PATCH] usb: gadget: r8a66597-udc: validate endpoint index for r8a66597 udc

We should verify the bound of the array to assure that host
may not manipulate the index to point past endpoint array.

Signed-off-by: Ma Ke <make24@...as.ac.cn>
---
 drivers/usb/gadget/udc/r8a66597-udc.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/gadget/udc/r8a66597-udc.c b/drivers/usb/gadget/udc/r8a66597-udc.c
index db4a10a979f9..93fc4201c0ae 100644
--- a/drivers/usb/gadget/udc/r8a66597-udc.c
+++ b/drivers/usb/gadget/udc/r8a66597-udc.c
@@ -1173,7 +1173,11 @@ __acquires(r8a66597->lock)
 		status = 0;
 		break;
 	case USB_RECIP_ENDPOINT:
-		ep = r8a66597->epaddr2ep[w_index & USB_ENDPOINT_NUMBER_MASK];
+		int pipe = w_index & USB_ENDPOINT_NUMBER_MASK;
+
+		if (pipe >= USB_MAX_ENDPOINTS)
+			break;
+		ep = r8a66597->epaddr2ep[pipe];
 		pid = control_reg_get_pid(r8a66597, ep->pipenum);
 		if (pid == PID_STALL)
 			status = 1 << USB_ENDPOINT_HALT;
@@ -1208,8 +1212,11 @@ static void clear_feature(struct r8a66597 *r8a66597,
 		struct r8a66597_ep *ep;
 		struct r8a66597_request *req;
 		u16 w_index = le16_to_cpu(ctrl->wIndex);
+		int pipe = w_index & USB_ENDPOINT_NUMBER_MASK;
 
-		ep = r8a66597->epaddr2ep[w_index & USB_ENDPOINT_NUMBER_MASK];
+		if (pipe >= USB_MAX_ENDPOINTS)
+			break;
+		ep = r8a66597->epaddr2ep[pipe];
 		if (!ep->wedge) {
 			pipe_stop(r8a66597, ep->pipenum);
 			control_reg_sqclr(r8a66597, ep->pipenum);
@@ -1268,8 +1275,11 @@ static void set_feature(struct r8a66597 *r8a66597, struct usb_ctrlrequest *ctrl)
 	case USB_RECIP_ENDPOINT: {
 		struct r8a66597_ep *ep;
 		u16 w_index = le16_to_cpu(ctrl->wIndex);
+		int pipe = w_index & USB_ENDPOINT_NUMBER_MASK;
 
-		ep = r8a66597->epaddr2ep[w_index & USB_ENDPOINT_NUMBER_MASK];
+		if (pipe >= USB_MAX_ENDPOINTS)
+			break;
+		ep = r8a66597->epaddr2ep[pipe];
 		pipe_stall(r8a66597, ep->pipenum);
 
 		control_end(r8a66597, 1);
-- 
2.25.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ