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 D61B11FC104; Wed, 5 Feb 2025 15:11:09 +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=1738768269; cv=none; b=koby/u+PcJCgNIn5ZNzwJCus2Emfi40Nl9gb1qgtnrjfVbEsZy+L8nb1FdF8SC9MdgkiXBJnwbseTWm/UKipLXjL3vbkoaAHSUxs9VcVbQzLkQt/jwjvLeCNBAqBx4aWX1svcpXc7K5bHkordULDS4lba9QJ4C4V0MLPvxG/4z4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738768269; c=relaxed/simple; bh=d9Ocwact0GAXJcBxCnDBEZvju4lhOg+9fUNIqmY4I6Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rQn6buAwlECKiAs+H8P4IPrMSFxuL1ldu88ir0eCsSZso+IAkP6mQa06dxwm5/rQFR2hE8AKgo5zmWZ9/6NGquxFbtw8usBymVj6bYParBXpYGXnyPGr5Pi855TybDf3CHx+yLNXoXVyNLf0VUQmKo7nMBC/1V+vhlmSoQwlJto= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Ek6nOi/R; 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="Ek6nOi/R" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E0D29C4CEE2; Wed, 5 Feb 2025 15:11:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1738768269; bh=d9Ocwact0GAXJcBxCnDBEZvju4lhOg+9fUNIqmY4I6Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ek6nOi/Rzy5f3CYlKW55e+nFPCnaWWpFzkSsGlah5dS4lWWKq7ZRdn2dRDAI50Lgb qzw/G8hP8XM+Zu7y5A8OyFdtaJiZ2YK4GQ3cK0UrMp+vcUvkcvLyVoc+GCsGJXVbxj Jz1GN4lip0j1jY3LUdamuxLfUtojJCNeBx+ByXBs= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Michal Pecio , Mathias Nyman Subject: [PATCH 6.12 553/590] usb: xhci: Fix NULL pointer dereference on certain command aborts Date: Wed, 5 Feb 2025 14:45:08 +0100 Message-ID: <20250205134516.427784084@linuxfoundation.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250205134455.220373560@linuxfoundation.org> References: <20250205134455.220373560@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.12-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 @@ -422,7 +422,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); } }