mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: Ginger Li <ginger.jzllee@gmail.com>
Cc: vz@mleia.com, piotr.wojtaszczyk@timesys.com,
	linux-usb@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] usb: gadget: lpc32xx_udc: Fix a race in lpc32xx_get_frame()
Date: Fri, 20 Nov 2026 15:20:51 +0100	[thread overview]
Message-ID: <2026112029-eloquent-slimy-c43f@gregkh> (raw)
In-Reply-To: <20260922065357.18103-1-ginger.jzllee@gmail.com>

On Tue, Sep 22, 2026 at 02:53:57PM +0800, Ginger Li wrote:
> lpc32xx_get_frame() tests udc->clocked before it takes udc->lock, but
> udc->clocked is cleared by udc_clk_set() with the lock held, for example from
> lpc32xx_vbus_session() when the session is disconnected, which also gates the
> UDC clock.
> 
> When the test passes on a stale value, udc_get_current_frame() then reads UDC
> registers whose clock has already been turned off.  Check udc->clocked inside
> the critical section so that the state can not change between the check and
> the register access.
> 
> Fixes: 24a28e428351 ("USB: gadget driver for LPC32xx")
> Signed-off-by: Ginger Li <ginger.jzllee@gmail.com>
> ---
>  drivers/usb/gadget/udc/lpc32xx_udc.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)

How was this found and tested?

> 
> diff --git a/drivers/usb/gadget/udc/lpc32xx_udc.c b/drivers/usb/gadget/udc/lpc32xx_udc.c
> --- a/drivers/usb/gadget/udc/lpc32xx_udc.c
> +++ b/drivers/usb/gadget/udc/lpc32xx_udc.c
> @@ -2403,10 +2403,12 @@ static int lpc32xx_get_frame(struct usb_gadget *gadget
>  	unsigned long flags;
>  	struct lpc32xx_udc *udc = to_udc(gadget);
>  
> -	if (!udc->clocked)
> -		return -EINVAL;
> +	spin_lock_irqsave(&udc->lock, flags);

guard()?

      reply	other threads:[~2026-11-20 14:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-22  6:53 Ginger Li
2026-11-20 14:20 ` Greg KH [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=2026112029-eloquent-slimy-c43f@gregkh \
    --to=greg@kroah.com \
    --cc=ginger.jzllee@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=piotr.wojtaszczyk@timesys.com \
    --cc=vz@mleia.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®