All of lore.kernel.org
 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: pch_udc: Fix potential ep0 DMA descriptor leak
Date: Wed, 11 Nov 2026 12:34:41 +0000	[thread overview]
Message-ID: <sashiko-outbox-208982@kernel.org> (raw)
In-Reply-To: <20261111-e5624093d6-usb-pch-udc@mail.sdu.edu.cn>

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] usb: gadget: pch_udc: double-put in pch_udc_probe() [1]
--

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

usb: gadget: pch_udc: Fix potential ep0 DMA descriptor leak

This commit frees the ep0 data DMA descriptor back to dev->data_requests
before destroying that pool in pch_udc_remove(), instead of freeing it to
dev->stp_requests.

> diff --git a/drivers/usb/gadget/udc/pch_udc.c b/drivers/usb/gadget/udc/pch_udc.c
> index 99b3ce28210f9..5996f1d16aedc 100644
> --- a/drivers/usb/gadget/udc/pch_udc.c
> +++ b/drivers/usb/gadget/udc/pch_udc.c
> @@ -2989,6 +2989,10 @@ static void pch_udc_remove(struct pci_dev *pdev)
>  		dev_err(&pdev->dev,
>  			"%s: gadget driver still bound!!!\n", __func__);
>  	/* dma pool cleanup */
> +	if (dev->ep[UDC_EP0OUT_IDX].td_data)
> +		dma_pool_free(dev->data_requests,
> +			      dev->ep[UDC_EP0OUT_IDX].td_data,
> +			      dev->ep[UDC_EP0OUT_IDX].td_data_phys);
>  	dma_pool_destroy(dev->data_requests);
>  
>  	if (dev->stp_requests) {
> @@ -2998,11 +3002,6 @@ static void pch_udc_remove(struct pci_dev *pdev)
>  				dev->ep[UDC_EP0OUT_IDX].td_stp,
>  				dev->ep[UDC_EP0OUT_IDX].td_stp_phys);
>  		}
> -		if (dev->ep[UDC_EP0OUT_IDX].td_data) {
> -			dma_pool_free(dev->stp_requests,
> -				dev->ep[UDC_EP0OUT_IDX].td_data,
> -				dev->ep[UDC_EP0OUT_IDX].td_data_phys);
> -		}
>  		dma_pool_destroy(dev->stp_requests);
>  	}

[Severity: Critical]
This problem wasn't introduced by this patch, but can pch_udc_remove() call
usb_del_gadget_udc() on an uninitialized or already-cleaned &dev->gadget
[1]?

pch_udc_probe() jumps to its finished label on failure and calls
pch_udc_remove(), which unconditionally invokes usb_del_gadget_udc() at the
top of the function:

drivers/usb/gadget/udc/pch_udc.c:pch_udc_probe() {
	...
	retval = init_dma_pools(dev);
	if (retval)
		goto finished;
	...
	retval = usb_add_gadget_udc(&pdev->dev, &dev->gadget);
	if (retval)
		goto finished;
	return 0;

finished:
	pch_udc_remove(pdev);
	return retval;
}

If probe fails before usb_add_gadget_udc(), usb_del_gadget_udc() calls
put_device() on a zero-initialized kobject.  If usb_add_gadget_udc() itself
fails, it already drops its device references before returning, so calling
usb_del_gadget_udc() in pch_udc_remove() causes a double-put and
use-after-free.

[1] https://sashiko.dev/#/bug/linux-7ca8dd59-dc65-4e63-bbde-b83dd0eb2845

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261111-e5624093d6-usb-pch-udc@mail.sdu.edu.cn?part=1

      reply	other threads:[~2026-11-11 12:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-11 12:23 [PATCH] usb: gadget: pch_udc: Fix potential ep0 DMA descriptor leak Guangshuo Li
2026-11-11 12:34 ` 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-208982@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.