From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0AF6F3F20EA; Tue, 17 Mar 2026 16:46:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773765988; cv=none; b=a3m5J56dFbrxbCJjAkamjAbQW3z+T4i5CQBQvHXOrEOBiu3OvGrCuNUtwX3Bv5N/TcWC2VxNdFgpe5qtBpYafnZK4lY3Vgss70+Puz6Hd6aMzrfsQDeaWIRHbvmmTxXDyOmNCz/nOL71YpLUsjdipHvGjukIanCDqxpN1ZXEvTc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773765988; c=relaxed/simple; bh=xiIRrS9Xcri9MrZsJqAl+DVBW+EpvA2znOb5cIwBxtA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y6IMkOQ4naEMIiHA+ospqi3gDjqYkh3WCuc2ySEAFpXZsNXcZF2lQKIZPQyfv+jLj5QB3r3DE46ceadSTLkk0SRX6WEVdQG8nT1gJRiAJJEXxI6+PjZ4LaDChCGl5+1uYE404eIsJH5QjiMXDoIyhh5RADfMkfsTJ//5ZCEMEcI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=2S95gP1u; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="2S95gP1u" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 50F7EC4CEF7; Tue, 17 Mar 2026 16:46:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1773765987; bh=xiIRrS9Xcri9MrZsJqAl+DVBW+EpvA2znOb5cIwBxtA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2S95gP1u1WqAIlpoWPTCpLrTRMB0GeYuO6OeZ3OdVb+RSRxL4Qt9wEwpJyzelZMvf 0fkVuPGWmxhJdEOLfudCP86y/L7vaySKIDqp8nzzoo7vPKp96fpKKSZnVRVVdDkY4y svrjh1dlnyztC8n12MtrTQgbKlhw3yQf/agbwfjs= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Zilin Guan , Mathias Nyman Subject: [PATCH 6.19 145/378] usb: xhci: Fix memory leak in xhci_disable_slot() Date: Tue, 17 Mar 2026 17:31:42 +0100 Message-ID: <20260317163012.350950766@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260317163006.959177102@linuxfoundation.org> References: <20260317163006.959177102@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Zilin Guan commit c1c8550e70401159184130a1afc6261db01fc0ce upstream. xhci_alloc_command() allocates a command structure and, when the second argument is true, also allocates a completion structure. Currently, the error handling path in xhci_disable_slot() only frees the command structure using kfree(), causing the completion structure to leak. Use xhci_free_command() instead of kfree(). xhci_free_command() correctly frees both the command structure and the associated completion structure. Since the command structure is allocated with zero-initialization, command->in_ctx is NULL and will not be erroneously freed by xhci_free_command(). This bug was found using an experimental static analysis tool we are developing. The tool is based on the LLVM framework and is specifically designed to detect memory management issues. It is currently under active development and not yet publicly available, but we plan to open-source it after our research is published. The bug was originally detected on v6.13-rc1 using our static analysis tool, and we have verified that the issue persists in the latest mainline kernel. We performed build testing on x86_64 with allyesconfig using GCC=11.4.0. Since triggering these error paths in xhci_disable_slot() requires specific hardware conditions or abnormal state, we were unable to construct a test case to reliably trigger these specific error paths at runtime. Fixes: 7faac1953ed1 ("xhci: avoid race between disable slot command and host runtime suspend") CC: stable@vger.kernel.org Signed-off-by: Zilin Guan Signed-off-by: Mathias Nyman Link: https://patch.msgid.link/20260304223639.3882398-2-mathias.nyman@linux.intel.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/xhci.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -4146,7 +4146,7 @@ int xhci_disable_slot(struct xhci_hcd *x if (state == 0xffffffff || (xhci->xhc_state & XHCI_STATE_DYING) || (xhci->xhc_state & XHCI_STATE_HALTED)) { spin_unlock_irqrestore(&xhci->lock, flags); - kfree(command); + xhci_free_command(xhci, command); return -ENODEV; } @@ -4154,7 +4154,7 @@ int xhci_disable_slot(struct xhci_hcd *x slot_id); if (ret) { spin_unlock_irqrestore(&xhci->lock, flags); - kfree(command); + xhci_free_command(xhci, command); return ret; } xhci_ring_cmd_db(xhci);