mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Sonali Pradhan <sonalipradhan@google.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Neill Kapron <nkapron@google.com>, Takashi Iwai <tiwai@suse.de>,
	Christophe JAILLET <christophe.jaillet@wanadoo.fr>,
	Fan Wu <fanwu01@zju.edu.cn>,
	Victor Krawiec <victor.krawiec@arturia.com>,
	Felipe Balbi <balbi@ti.com>,
	"Felipe F. Tonello" <eu@felipetonello.com>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH RESEND] usb: gadget: f_midi: fix UAF race during IN request handling
Date: Tue, 20 Oct 2026 11:06:57 +0200	[thread overview]
Message-ID: <87a4o8ivv2.wl-tiwai@suse.de> (raw)
In-Reply-To: <20261019135701.2767078-1-sonalipradhan@google.com>

On Mon, 19 Oct 2026 15:57:01 +0200,
Sonali Pradhan wrote:
> 
> f_midi_disable() frees pre-allocated IN requests from in_req_fifo
> without holding midi->transmit_lock. Concurrent f_midi_transmit() or
> f_midi_complete() calls can then access these request buffers after they
> are freed, leading to a use-after-free.
> 
> Fix this by acquiring midi->transmit_lock in f_midi_disable() while
> releasing IN requests, and checking ep->enabled under midi->transmit_lock
> in f_midi_transmit() and f_midi_complete() before modifying requests.
> 
> Fixes: e1e3d7ec5da3 ("usb: gadget: f_midi: pre-allocate IN requests")
> Cc: stable@vger.kernel.org
> Signed-off-by: Sonali Pradhan <sonalipradhan@google.com>
> ---
> Resending and rebasing on latest linux-next as I haven't received
> feedback on my initial submission:
> https://lore.kernel.org/all/20260819102709.212646-1-sonalipradhan@google.com/
> 
>  drivers/usb/gadget/function/f_midi.c | 19 ++++++++++++++++---
>  1 file changed, 16 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/usb/gadget/function/f_midi.c b/drivers/usb/gadget/function/f_midi.c
> index 63fb6ee70a3d..c26d04eb9209 100644
> --- a/drivers/usb/gadget/function/f_midi.c
> +++ b/drivers/usb/gadget/function/f_midi.c
> @@ -280,9 +280,18 @@ f_midi_complete(struct usb_ep *ep, struct usb_request *req)
>  			/* We received stuff. req is queued again, below */
>  			f_midi_handle_out_data(ep, req);
>  		} else if (ep == midi->in_ep) {
> +			unsigned long flags;
> +
>  			/* Our transmit completed. See if there's more to go.
>  			 * f_midi_transmit eats req, don't queue it again. */
> +			spin_lock_irqsave(&midi->transmit_lock, flags);
> +			if (!ep->enabled) {
> +				spin_unlock_irqrestore(&midi->transmit_lock, flags);
> +				return;
> +			}
>  			req->length = 0;
> +			spin_unlock_irqrestore(&midi->transmit_lock, flags);
> +

Does this transmit_lock help here?  As far as I see, the ep
enable/disable itself is done outside the lock.

> @@ -678,10 +690,11 @@ static void f_midi_transmit(struct f_midi *midi)
>  	unsigned long flags;
>  
>  	/* We only care about USB requests if IN endpoint is enabled */
> -	if (!ep || !ep->enabled)
> -		goto drop_out;
> -
>  	spin_lock_irqsave(&midi->transmit_lock, flags);
> +	if (!ep || !ep->enabled) {
> +		spin_unlock_irqrestore(&midi->transmit_lock, flags);
> +		goto drop_out;
> +	}

Ditto.


thanks,

Takashi

      reply	other threads:[~2026-10-20  9:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-19 13:57 Sonali Pradhan
2026-10-20  9:06 ` Takashi Iwai [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=87a4o8ivv2.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=balbi@ti.com \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=eu@felipetonello.com \
    --cc=fanwu01@zju.edu.cn \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=nkapron@google.com \
    --cc=sonalipradhan@google.com \
    --cc=stable@vger.kernel.org \
    --cc=victor.krawiec@arturia.com \
    /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

all inboxes | Powered by JetHome®