Linux USB
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Guangshuo Li" <liguangshuo@mail.sdu.edu.cn>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH] usb: gadget: max3420: Fix potential thread leak on probe failure
Date: Fri, 20 Nov 2026 17:48:33 +0000	[thread overview]
Message-ID: <sashiko-outbox-225719@kernel.org> (raw)
In-Reply-To: <20261120173512.3923833-1-liguangshuo@mail.sdu.edu.cn>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] usb: gadget: max3420: UAF of udc->dev in max3420_probe()
  stop_thread path
--

commit 1aa81e8a2fed8c598f135d63a9ff28aff8ed2d0f
Author: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>

usb: gadget: max3420: Fix potential thread leak on probe failure

This commit disables the UDC interrupt and stops the SPI worker thread if
requesting the VBUS interrupt fails during probe.

> diff --git a/drivers/usb/gadget/udc/max3420_udc.c b/drivers/usb/gadget/udc/max3420_udc.c
> index 11fd61cba5af9..84309229216b9 100644
> --- a/drivers/usb/gadget/udc/max3420_udc.c
> +++ b/drivers/usb/gadget/udc/max3420_udc.c

[ ... ]

> @@ -1283,11 +1283,17 @@ static int max3420_probe(struct spi_device *spi)
>  		err = devm_request_irq(&spi->dev, irq,
>  				       max3420_vbus_handler, 0, "vbus", udc);
>  		if (err < 0)
> -			goto del_gadget;
> +			goto stop_thread;
>  	}
>  
>  	return 0;
>  
> +stop_thread:
> +	usb_del_gadget_udc(&udc->gadget);
> +	disable_irq(udc_irq);
> +	kthread_stop(udc->thread_task);
> +	return err;
> +
>  del_gadget:
>  	usb_del_gadget_udc(&udc->gadget);
>  	return err;

[Severity: Medium]
Can calling usb_del_gadget_udc() before stopping udc->thread_task cause a
use-after-free of udc->dev->kobj.name when max3420_thread() exits?

udc->dev aliases &udc->gadget.dev without taking an extra reference.
usb_del_gadget_udc() can wake udc->thread_task via max3420_udc_stop() (or
max3420_irq_handler() can wake it while udc_irq is still enabled) and
then drops the final reference on udc->gadget.dev via usb_put_gadget(),
freeing udc->gadget.dev.kobj.name.  When kthread_stop() runs next,
max3420_thread() logs its exit with dev_info(udc->dev, ...), reading the
freed name:

drivers/usb/gadget/udc/max3420_udc.c:max3420_thread() {
	...
	set_current_state(TASK_RUNNING);
	dev_info(udc->dev, "SPI thread exiting\n");
	return 0;
}

Disabling udc_irq and stopping udc->thread_task before calling
usb_del_gadget_udc() (or falling through to del_gadget) would avoid this.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261120173512.3923833-1-liguangshuo@mail.sdu.edu.cn?part=1

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

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 17:35 [PATCH] usb: gadget: max3420: Fix potential thread leak on probe failure Guangshuo Li
2026-11-20 17:48 ` 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-225719@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=liguangshuo@mail.sdu.edu.cn \
    --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