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>] [day] [month] [year] [list]
Message-ID:
 <TYUPR06MB6217CBC7A42AE66F2B7DAF9AD2692@TYUPR06MB6217.apcprd06.prod.outlook.com>
Date: Wed, 25 Sep 2024 06:29:32 +0000
From: 胡连勤 <hulianqin@...o.com>
To: "gregkh@...uxfoundation.org" <gregkh@...uxfoundation.org>
CC: Michael Nazzareno Trimarchi <michael@...rulasolutions.com>, Prashanth K
	<quic_prashk@...cinc.com>, "quic_jjohnson@...cinc.com"
	<quic_jjohnson@...cinc.com>, "linux-usb@...r.kernel.org"
	<linux-usb@...r.kernel.org>, "linux-kernel@...r.kernel.org"
	<linux-kernel@...r.kernel.org>, opensource.kernel
	<opensource.kernel@...o.com>, "akpm@...ux-foundation.org"
	<akpm@...ux-foundation.org>
Subject:
 答复: [PATCH v9] usb: gadget: u_serial: Add null pointer check in gs_read_complete & gs_write_complete

Hello linux community expert:

>> >> From: Lianqin Hu <hulianqin@...o.com>
>> >> 
>> >> Considering that in some extreme cases, when the unbind operation 
>> >> is being executed, gserial_disconnect has already cleared 
>> >> gser->ioport, triggering a gadget reconfiguration at this time and 
>> >> gs_read_complete gets called afterwards, which results in accessing 
>> >> null pointer, add a null pointer check to prevent this situation.
>> >> 
>> >> Added a static spinlock to prevent gser->ioport from becoming null 
>> >> after the newly added check.
>> 
>> >In looking at this further, shouldn't we just be moving around where we call usb_ep_disable() in gserial_disconnect()?
>> 
>> >Can't we shut down the endpoints _BEFORE_ we set the port structures to NULL?  After the endpoints are stopped, then we know that there is no outstanding i/o possible and then we can clean up properly?
>> 
>>> >Not to say that your change doesn't fix the race condition here, but cleaning up things in the proper order might be the better way as then there can not be any race conditions at all?
>> 
>> >Have you tried that?
>> 
>> Thank you for your guidance, we studied and tried.

>I'm confused, you tried what and what happened?
After this modification, our stress test problem no longer recurs.( I'm sorry for taking so long to reply. There have been many urgent issues in the project recently and I have invested a lot of time to support project issues.)

diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c
index b394105e55d6..1712e9cd08be 100644
--- a/drivers/usb/gadget/function/u_serial.c
+++ b/drivers/usb/gadget/function/u_serial.c
@@ -1395,6 +1395,10 @@ void gserial_disconnect(struct gserial *gser)
 	/* REVISIT as above: how best to track this? */
 	port->port_line_coding = gser->port_line_coding;
 
+	/* disable endpoints, aborting down any active I/O */
+	usb_ep_disable(gser->out);
+	usb_ep_disable(gser->in);
+
 	port->port_usb = NULL;
 	gser->ioport = NULL;
 	if (port->port.count > 0) {
@@ -1406,10 +1410,6 @@ void gserial_disconnect(struct gserial *gser)
 	spin_unlock(&port->port_lock);
 	spin_unlock_irqrestore(&serial_port_lock, flags);
 
-	/* disable endpoints, aborting down any active I/O */
-	usb_ep_disable(gser->out);
-	usb_ep_disable(gser->in);
-
 	/* finally, free any unused/unusable I/O buffers */
 	spin_lock_irqsave(&port->port_lock, flags);
 	if (port->port.count == 0)

Thanks

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ