linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Daehwan Jung" <dh10.jung@samsung.com>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH v4] usb: gadget: u_serial: fix stale req->dep warn on disconnect/reconnect
Date: Mon, 12 Oct 2026 08:10:52 +0000	[thread overview]
Message-ID: <sashiko-outbox-167825@kernel.org> (raw)
In-Reply-To: <1860250540.01791791282424.JavaMail.epsvc@epcpadp2new>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] usb: cdns3: use-after-free on request->buf in gadget giveback
--

commit 8f8778218c9b936c4a5d0fa16a09a9091afc687a
Author: Daehwan Jung <dh10.jung@samsung.com>

usb: gadget: u_serial: fix stale req->dep warn on disconnect/reconnect

When DWC3_EP_DELAY_STOP defers ENDXFER, giveback of -ESHUTDOWN requests
arrives after gserial_disconnect(). This commit frees the stale request
in gs_read_complete() when the port is already disconnected to prevent
subsequent warnings.

Link to v3: https://lore.kernel.org/all/20260727051335.1745955-1-dh10.jung@samsung.com/

> diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c
> index cdd1dfc666c4f..ba6af7127fc47 100644
> --- a/drivers/usb/gadget/function/u_serial.c
> +++ b/drivers/usb/gadget/function/u_serial.c
> @@ -459,10 +459,21 @@ static void gs_read_complete(struct usb_ep *ep, struct usb_request *req)
>  {
>  	struct gs_port	*port = ep->driver_data;
>  
> -	/* Queue all received data until the tty layer is ready for it. */
>  	spin_lock(&port->port_lock);
> -	list_add_tail(&req->list, &port->read_queue);
> -	schedule_delayed_work(&port->push, 0);
> +	if (!port->port_usb) {
> +		/*
> +		 * The port was disconnected: gserial_disconnect() has already
> +		 * freed read_pool/read_queue and reset the request counters.
> +		 * Free this request now instead of queueing it, otherwise
> +		 * gs_rx_push() would return it to read_pool and the next
> +		 * gserial_connect() would submit it on the new OUT endpoint.
> +		 */
> +		gs_free_req(ep, req);

[Severity: High]
Does this cause a use-after-free when used with the cdns3 USB controller?

The cdns3 driver evaluates request->buf after calling the giveback handler:

drivers/usb/cdns3/cdns3-gadget.c:cdns3_gadget_giveback() {
    ...
		usb_gadget_giveback_request(&priv_ep->endpoint,
					    request);
		spin_lock(&priv_dev->lock);
	}

	if (request->buf == priv_dev->zlp_buf)
		cdns3_gadget_ep_free_request(&priv_ep->endpoint, request);
    ...
}

If gs_read_complete() synchronously frees the request via gs_free_req() when
the port is disconnected, will the subsequent check in cdns3_gadget_giveback()
dereference the freed request pointer?

> +	} else {
> +		/* Queue all received data until the tty layer is ready for it. */
> +		list_add_tail(&req->list, &port->read_queue);
> +		schedule_delayed_work(&port->push, 0);
> +	}
>  	spin_unlock(&port->port_lock);
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/1860250540.01791791282424.JavaMail.epsvc@epcpadp2new?part=1

      reply	other threads:[~2026-10-12  8:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20261012060557epcas2p4ce5468f159a857c5caf2c81b59cc3f60@epcas2p4.samsung.com>
2026-10-12  6:01 ` [PATCH v4] usb: gadget: u_serial: fix stale req->dep warn on disconnect/reconnect Daehwan Jung
2026-10-12  8:10   ` sashiko-bot [this message]

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=sashiko-outbox-167825@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dh10.jung@samsung.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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).