From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.54 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796022788; b=u8rN5MtaCZ0EuRbUEKUydzh1X4w64DOC5XoCIUqyAImjePlqtkyasxI4U8nq6Z75MxlN VAS4PH+rTZR5qhNOpZ+5kFib0rCky/jVVFoDhW3sKv0P2Vu66zXT3d/h+RZYI6yHBp2kr 94SRaMPbV2pe17BYx32Q6f8/UY8MbE45Oc5g2jttGloGlGQOgcqKS+zAbalF+9ew8XgIB uYX8dHU5HZB91W3OEmL6x5Hrbj4tDXc2esCmgEme2MC5qk7Q9JKyLmf1p307xhRhqjt4y Uhdx8np2HbiG9u0a5VOdHfxJfTZRUoexdLqW51nLVO0nKslwxv5Ru+YPt4FfayYY9hQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796022788; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=fb1+2VkzkIa3bKvwMx5qHJEUYCwLBSwodaI9I1Wgj1Q=; b=k87ZTe1ZPgpNiksP3xjKj03T2cYL+RqmqhU3d+jgq7c3y4oR8bxHPJ8yKyxkR4I3a37L JzolRm7bn85S/FP3ESqIm640vs+AEVtbGdA+R/AIK0eXLtq+fCTLEpn26sX3IV784sByr FtciHsO+TXMiPABUpHw1yZe8tFFM5IW0mEsPfWZUb/GKC/wmXlf9Pz0Zp7L82KMAaJmR/ H1xx1Y3aUG+W1tT6zexH2ObhMKjBHJ5aapKfSiMN/66fxJ0a0dpkCma63ciNOHPQ5vXb8 gSSPpLx0lPnuS+JoceXKCcg9e8Shf2jKQiYiPNYhU2R58hvL7GGFdqK5UE8LlFcs/fw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Ib4Xp8Hp; arc=none smtp.remote-ip=209.85.128.54 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7F4AF606A683 for ; Mon, 30 Nov 2026 07:13:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7F4AF606A683 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Ib4Xp8Hp Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-4a9a8d6cea8so127973995e9.1 for ; Sun, 29 Nov 2026 23:13:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796022787; x=1796627587; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=fb1+2VkzkIa3bKvwMx5qHJEUYCwLBSwodaI9I1Wgj1Q=; b=Ib4Xp8HpL9r4CDb6Zyz/IJP7q8u5/VcUcnZmAmxaRpC4xkP5Ug8LDBBfcNKBmHjjiz Vw+Rc0NyCFF9RHSrDmah0sG1L1wu55Ic7QUOTb/iyBz9KCh1LmqUYn62eYiRxlyrC19e jtFz6RIkE3MwxEOXL7Z+cytLyJtOZRIiJ3VIVjIgrT8fLePZ6Wg1AaNyBKzoyEISIywN TlD1eBFCyO6vhhTeXPiJmUekXFcUxDvqlram0ISlVL+nuKX0Dlmk4Xu9nzezOTUEMyXk fqIPXwi4Q2atSQ3hyd9BCgDEssclg/BXWCBvKug6h8N9gGIRNkv9CkkzUcXKFz5wnl+a X7kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796022787; x=1796627587; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=fb1+2VkzkIa3bKvwMx5qHJEUYCwLBSwodaI9I1Wgj1Q=; b=e9zmtmJ+tpvvcPJLYaqbrtFqPicd6Cj+jNhhxT7l3u+d7wpdsUzlQW/USJCNa47GWp 63UPT45rYX9WvbOuJ3HDErlZBHoYzYknpMgJb2ERkUTn7agExNHdH1rM7RwiLnWkpF0a ejwTLv/3+OSEh8532EVVEXWG55B8MYRa4658TJjii2BaWmZQ8404ypn62GRj098tuXFM KNA12eJhgG+YC0flw2r5kbE3vJRRzSkdzGING6emICkKHgxRkYZeFDzJpdOHJD8IqoIv f7uR88AKDTUOPHvZ5pBK5W9iIZ0PM5h8vaEWIrRkGLab4IBSMrmvcg3fl3OyO8nz63Cg GUmg== X-Forwarded-Encrypted: i=1; AL+hErFy5BKCXsq3e83mx/RAegqj9TWjel2DUir7/pEznaFvIfj3gfo5IggtlCWnGrlVxgc5dv+mLWk=@vger.kernel.org X-Gm-Message-State: APuU4Z+eLwIZ0KkCAbhnjVBuXh3qzIyekM0h9nRPx0h57PTXmluShnVW B7/B2VNGaVtN1SfUivU0eyfg46DJ6EW8VlS1mmasHJ7lNXpbm4PUEa1b X-Gm-Gg: AZFdTZfHaX94HgHVboRjMNtKEPqfM+vPqZ02Of9Q+zqkGWVADJcOM8qFSVlK8RCpIqO nupLleTigeyzphVCKIEv8ZOPUElRAdwGvT4h16GJM55yoldPf8reEWVfssFflHOC7wS3ZOvyzyj 8avyjyX9QskhoXzQ/kHVa8UcEutM024QQd9K/R64zYrfxx7L3iVwc5mAj9cUNVTTZRM6GKGwQNt TAzGbxwOGM5w70539jfd4fM4NtuoRaOFeYClDw6Px8Qrn5aNqA3WvctCS/H7999RI+3zxIdJS4h wRlxp2gghEZXZlDCi+MI2ztT5UqdQ65izic9M5qfdupi8AfGDuejVWj9II997vHsywdoQAPVetW Ln5NTUn0oRg1+W0rtcs1J1CptLbXKZaMkokQJXgx8uFU2qlD2TIxeLXsZrw3v7CvIp5dwttaF2t Wxqisw9uGSfLfK37G0mNt3l1knWI2cysB1hnDQStoZCuuG482bWJHWuFGSsfCc/JAVtkZUTON1p IEWi8pKCsIplDB2VdmJsL88N8x635isF0klkCcyTmRTLNByXHIRAlN2qU77bmXvmjUUSntBpNTI sAKh6zLhyGvvXnO0sZ363BkPNgM0nbJ2D7bzPRM= X-Received: by 2002:a05:600c:b8a:b0:4a0:20b4:ba93 with SMTP id 5b1f17b1804b1-4bb88818156mr647429245e9.16.1796022786541; Sun, 29 Nov 2026 23:13:06 -0800 (PST) Received: from foxbook (bfj60.neoplus.adsl.tpnet.pl. [83.28.47.60]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb88f148aasm367861175e9.0.2026.11.29.23.13.05 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Sun, 29 Nov 2026 23:13:05 -0800 (PST) Date: Mon, 30 Nov 2026 08:13:03 +0100 From: Michal Pecio To: Mathias Nyman Cc: , , stable@vger.kernel.org Subject: Re: [PATCH 09/10] xhci: fix use-after-free for errors mid TD on empty halted rings Message-ID: <20261130081303.2d5235d1.michal.pecio@gmail.com> In-Reply-To: <20261127121755.281420-10-mathias.nyman@linux.intel.com> References: <20261127121755.281420-1-mathias.nyman@linux.intel.com> <20261127121755.281420-10-mathias.nyman@linux.intel.com> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Fri, 27 Nov 2026 14:17:54 +0200, Mathias Nyman wrote: > If a TD with an error mid TD is followed by an event that doesn't point > to that TD, handle_tx_event() gives back the TD with xhci_dequeue_td(). > If this was the last TD of the URB, the URB is given back and the TD, > part of the freed urb_priv, is freed with it. > > If the TD list is then empty ... and we are getting more transfer events, then it's a HW bug. Or a driver bug which should be fixed. > and the endpoint is halted, Then it's another HW bug because isochronous endpoints don't halt. > handle_tx_event() jumps to check_endpoint_halted and passes the now > dangling td pointer to xhci_handle_halted_endpoint(), which adds it > to the endpoint's cancelled TD list. This causes a use-after-free and > corrupts the cancelled TD list. > > Set td to NULL after giving it back. xhci_handle_halted_endpoint() > handles a NULL td, and td is reassigned if there are more TDs on the > ring. > > Reported-by: Sashiko > Closes: https://sashiko.dev/#/bug/linux-2b321b4d-f99f-4acd-9590-8dd98a82ebb5 > Fixes: f42a36bae064 ("usb: xhci: Fix handling errors mid TD followed by other errors") > Cc: stable@vger.kernel.org # 6.12+ > Signed-off-by: Mathias Nyman I don't disagree with the diff even if I never cared about that while working on this code before, but commit message could be more honest: Hardware is buggy enough that we would rather waste one or two bytes of code than risk that bogus events corrupt memory by completing the same TD twice if it's the last TD but we keep receiving more events and they suggest that this isochronous endpoint has halted. I'm personally not sure if HW is buggy enough for *this* to happen, but we know that it is plenty buggy in general. Now that I think about it, ISTR a reported case of Stall Error on isoc in some Intel chipset. And there is a simpler fix which decreases rather than increases driver code size: get rid of check_endpoint_halted altogether, because every case of transfer events on an empty endpoint or No-Op is a bug and much has been done to solve those bugs since 810a624bd1b64 10 years ago. The author even understood the bug, but didn't seem to appreciate that cancelling URBs concurrently with their execution is not intended and never a good idea for a multitude of reasons: https://marc.info/?l=linux-usb&m=149612023718060&w=2 4. Every time a URB is killed, the endpoint ring is restarted and URBs that are not killed yet are executed. If we are unlucky, the URB's TRB is gets cancelled right after it has been executed but before xhci_irq() gets to run, causing this condition. Regards, Michal > --- > drivers/usb/host/xhci-ring.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c > index fca23daf6add..7ccd89a4b995 100644 > --- a/drivers/usb/host/xhci-ring.c > +++ b/drivers/usb/host/xhci-ring.c > @@ -2891,6 +2891,7 @@ static int handle_tx_event(struct xhci_hcd *xhci, > if (td && td->error_mid_td && !trb_in_td(td, ep_trb_dma)) { > xhci_dbg(xhci, "Missing TD completion event after mid TD error\n"); > xhci_dequeue_td(xhci, td, ep_ring, td->status); > + td = NULL; > } > > if (list_empty(&ep_ring->td_list)) { > -- > 2.43.0 >