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 2ADE51B6CFA; Wed, 19 Feb 2025 09:19:00 +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=1739956740; cv=none; b=J/Lb899d0fEe+RNq4ioBVqumZ93NIxsh+l/d2ayda9fm5B3yzOQfK+39xuRr/CApPtPoLp+KzY4rHN0f0otVBQfwd0hXVRNHUiVgR+i6Ct3c5gA9V/b9Pykm7ztu0fRq5YoJ1IMX+I3OmmlgZzZSuwv1Uv3EmtE7bVIN2uBb+eI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739956740; c=relaxed/simple; bh=kBAL90oKwe2H+3tEiV+OVa0M7FKGY7FrMRmzC1dqxBE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RKHoLP34TQIwEmgXt3OSzxSJxRG5IWVHLVT+09123HT1+BhElUVAkdzOFCi2gCxYdrqYOZ/eSsI9e9ygVUF5bNM06+O5s4Xc4uGSgpxKAAS0xByyuXHMgb4kfSxEJynrEWKMRvWgS2e3jaLQfkzjoqAgfePEY2UUHW/cNZxy+F0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=k6DW0iqP; 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="k6DW0iqP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A65FEC4CED1; Wed, 19 Feb 2025 09:18:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1739956740; bh=kBAL90oKwe2H+3tEiV+OVa0M7FKGY7FrMRmzC1dqxBE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k6DW0iqPS2XP4veyx3+jTXyU1m8ahZRD0iou2GQB/2P7YP4bmXBS7KgQ6O3NYhoV2 MGTpIBmAi/Zdsj4ee/5Uo+/bTRGnmdIIttE7/X0LCVqFAHa4qQswGixnmRRG0Qzx9e XQRTVuMXLeDwhgPUHwzTF97rXIApvY0zd7ujZBAU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Michal Pecio , Mathias Nyman Subject: [PATCH 6.1 252/578] usb: xhci: Fix NULL pointer dereference on certain command aborts Date: Wed, 19 Feb 2025 09:24:16 +0100 Message-ID: <20250219082702.941360623@linuxfoundation.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250219082652.891560343@linuxfoundation.org> References: <20250219082652.891560343@linuxfoundation.org> User-Agent: quilt/0.68 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.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Michal Pecio commit 1e0a19912adb68a4b2b74fd77001c96cd83eb073 upstream. If a command is queued to the final usable TRB of a ring segment, the enqueue pointer is advanced to the subsequent link TRB and no further. If the command is later aborted, when the abort completion is handled the dequeue pointer is advanced to the first TRB of the next segment. If no further commands are queued, xhci_handle_stopped_cmd_ring() sees the ring pointers unequal and assumes that there is a pending command, so it calls xhci_mod_cmd_timer() which crashes if cur_cmd was NULL. Don't attempt timer setup if cur_cmd is NULL. The subsequent doorbell ring likely is unnecessary too, but it's harmless. Leave it alone. This is probably Bug 219532, but no confirmation has been received. The issue has been independently reproduced and confirmed fixed using a USB MCU programmed to NAK the Status stage of SET_ADDRESS forever. Everything continued working normally after several prevented crashes. Link: https://bugzilla.kernel.org/show_bug.cgi?id=219532 Fixes: c311e391a7ef ("xhci: rework command timeout and cancellation,") CC: stable@vger.kernel.org Signed-off-by: Michal Pecio Signed-off-by: Mathias Nyman Link: https://lore.kernel.org/r/20241227120142.1035206-4-mathias.nyman@linux.intel.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/xhci-ring.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -380,7 +380,8 @@ static void xhci_handle_stopped_cmd_ring if ((xhci->cmd_ring->dequeue != xhci->cmd_ring->enqueue) && !(xhci->xhc_state & XHCI_STATE_DYING)) { xhci->current_cmd = cur_cmd; - xhci_mod_cmd_timer(xhci); + if (cur_cmd) + xhci_mod_cmd_timer(xhci); xhci_ring_cmd_db(xhci); } }