lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <f9476552-a6dc-4f1c-91da-b15c8f0d9844@linux.intel.com>
Date: Mon, 1 Sep 2025 13:14:32 +0300
From: Mathias Nyman <mathias.nyman@...ux.intel.com>
To: David Wang <00107082@....com>, Michał Pecio
 <michal.pecio@...il.com>
Cc: WeitaoWang-oc@...oxin.com, gregkh@...uxfoundation.org,
 linux-usb@...r.kernel.org, regressions@...ts.linux.dev,
 linux-kernel@...r.kernel.org, surenb@...gle.com, kent.overstreet@...ux.dev
Subject: Re: [REGRESSION 6.17-rc3] usb/xhci: possible memory leak after
 suspend/resume cycle.

On 30.8.2025 13.17, David Wang wrote:
> 
> At 2025-08-30 17:48:28, "Michał Pecio" <michal.pecio@...il.com> wrote:
>>
>> Hi,
>>
>> Good work, looks like suspend/resume is a little understested corner
>> of this driver.
>>
>> Did you check whether the same leak occurs if you simply disconnect
>> a device or if it's truly unique to suspend?
>>
>>> And bisect narrow down to commit 2eb03376151bb8585caa23ed2673583107bb5193(
>>> "usb: xhci: Fix slot_id resource race conflict"):
>>
>> I see a trivial bug which everyone (myself included tbh) missed before.
>> Does this help?
>>
>> diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
>> index f11e13f9cdb4..f294032c2ad7 100644
>> --- a/drivers/usb/host/xhci-mem.c
>> +++ b/drivers/usb/host/xhci-mem.c
>> @@ -932,7 +932,7 @@ void xhci_free_virt_device(struct xhci_hcd *xhci, struct xhci_virt_device *dev,
>>   */
>> static void xhci_free_virt_devices_depth_first(struct xhci_hcd *xhci, int slot_id)
>> {
>> -	struct xhci_virt_device *vdev;
>> +	struct xhci_virt_device *vdev, *tmp_vdev;
>> 	struct list_head *tt_list_head;
>> 	struct xhci_tt_bw_info *tt_info, *next;
>> 	int i;
>> @@ -952,8 +952,8 @@ static void xhci_free_virt_devices_depth_first(struct xhci_hcd *xhci, int slot_i
>> 		if (tt_info->slot_id == slot_id) {
>> 			/* are any devices using this tt_info? */
>> 			for (i = 1; i < HCS_MAX_SLOTS(xhci->hcs_params1); i++) {
>> -				vdev = xhci->devs[i];
>> -				if (vdev && (vdev->tt_info == tt_info))
>> +				tmp_vdev = xhci->devs[i];
>> +				if (tmp_vdev && (tmp_vdev->tt_info == tt_info))
>> 					xhci_free_virt_devices_depth_first(
>> 						xhci, i);
> 
> I confirmed this *silly* code is the root cause of this memory leak.
> And I would suggest simpler code changes (which is what I was testing):
> 
> 
> diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
> index 81eaad87a3d9..c4a6544aa107 100644
> --- a/drivers/usb/host/xhci-mem.c
> +++ b/drivers/usb/host/xhci-mem.c
> @@ -962,7 +962,7 @@ static void xhci_free_virt_devices_depth_first(struct xhci_hcd *xhci, int slot_i
>   out:
>          /* we are now at a leaf device */
>          xhci_debugfs_remove_slot(xhci, slot_id);
> -       xhci_free_virt_device(xhci, vdev, slot_id);
> +       xhci_free_virt_device(xhci, xhci->devs[slot_id], slot_id);
>   }
>   
>   int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id,
> 

Thanks to both for catching this

I can quickly turn this into a proper patch unless one of you would like to submit one?

Thanks
Mathias

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ