Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795038190; b=qP4QE8IRTDCmBkviL3h9CBtjnCoFrAqlEN8t6PKEhz4JvVOUYcxauXcDrRS9YRU3KaGe oaf8yBWx64g/4YudQ1YO14xClnfd96LQBy5UJOvAE5f+ZcHhsgnKLs9/qYZQVm8Tl7ytf KGK6yS9js/I+kisj35jIS54t+3jUWH2dX1DQNGG91gCVwg7AdNTwhAsRMCC6zJtFi6i8n 0YNx4ES1ADQarPRJKScKNcXIZ2NL5iCC/gZ6RU5hcjplo4pAI2IuXJtP6Vp9/d/orPaCE uGLqKvWHRlID8u3hbEnxvTfCQaEOK1gMKShPtfc1cljLbQsRDYLLyyOCNjlZDt1SH3A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795038190; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=5VC0Y9Lii/N4vtVqvDatnE3BH85bsIDWyq0K4k5tdmA=; b=vvEuaSkfIisWv4jk8Ua9vFfA914G+y/pfHX4mVXy3CsX62vml49w5t+Ej8FFbkmRBqGg iA0MkK/QOZh2eaE0mq2shi5wz2OdrOSBTd4FTeVW018BHhFvgyJ6yEuQLSKiaaPkZbDsO bS7AKHOm5YIfCBAqvYTruvXKX3D8OAokQzzGguY9hFn8sRLWyFtxj/F8waTE//5RGPa5l B7H6kyb1DrN7jNJC9+IraP8Eldkq7ZYhphxRx0mttsoGtdH442G5npbhiPanQmX1Ghkup F0SnvysUg+PmcLQ93RV209+LhJpEnG0pHhwcZ2BfL8iV9WUtE6lwLeni7BtKPoUQOgw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=UHX4E7eG; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9FD2D606A32C; Wed, 18 Nov 2026 21:43:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=UHX4E7eG Received: by smtp.kernel.org (Postfix) with ESMTPSA id 01CE31F000C5; Wed, 18 Nov 2026 21:43:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795038190; bh=5VC0Y9Lii/N4vtVqvDatnE3BH85bsIDWyq0K4k5tdmA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=UHX4E7eGwDD1g0yu0qnQHXT6e3fDO7ZXgw0OgWIxrMkiZ55/otl4CjFYjsAwtFCIJ 3P2uBMev+bAMzeEAnW2EwkvETspeWohC4p9eIrRMY/aDZB9neB1SnY6tsqp+ihiK4U mFYeW/XssnUmlLZ7EPSMQfSurn9WJWdOof/qqsok= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, co+fd80bc5967eb22c3@bugs.sh, Michal Pecio , Mathias Nyman , Sasha Levin Subject: [PATCH 6.6 1658/3318] usb: xhci: Fix bounce buffer overflow Date: Wed, 18 Nov 2026 15:38:00 +0100 Message-ID: <20261118150411.513306851@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150313.527275416@linuxfoundation.org> References: <20261118150313.527275416@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Michal Pecio [ Upstream commit 68c5cb7574c567e83ba95258cb146db95e069a87 ] High-speed devices with out of spec 1024 byte bulk endpoints exist and are allowed by USB core, but xhci-hcd always sets packet size to 512. The exact nature of these devices isn't documented, commit fb5ee84ea72c ("USB: Accept bulk endpoints with 1024-byte maxpacket") only states that they "don't work with xHCI host controllers", whatever it means. But somebody (or a malicious device) can try, and then the driver will allocate a 512 byte bounce buffer for this endpoint and may write up to 1024 bytes into it if particular scatter-gather URBs are used, because xhci_align_td() obtains packet size from the descriptor. Fix this. As a side effect, TRBs will be aligned to the packet size chosen by the driver on all endpoints of all speeds. Alignment serves the xHC, not device, so this is fine. Only out of spec devices are affected anyway. Reported-by: co+fd80bc5967eb22c3@bugs.sh Link: https://lore.kernel.org/linux-usb/D4tcSGerkYkIV1DmaUo1t8TaR5qQElDLkidn@bugs.sh/ Fixes: f9c589e142d0 ("xhci: TD-fragment, align the unsplittable case with a bounce buffer") Cc: stable@vger.kernel.org Signed-off-by: Michal Pecio Signed-off-by: Mathias Nyman Link: https://patch.msgid.link/20261009151624.618967-11-mathias.nyman@linux.intel.com Signed-off-by: Greg Kroah-Hartman [ sashal: adapted the max_pkt assignment removal to match usb_endpoint_maxp() instead of xhci_usb_endpoint_maxp() ] Signed-off-by: Sasha Levin --- drivers/usb/host/xhci-ring.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 66c399253a9b4..3794492b16ec2 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -3644,15 +3644,13 @@ static u32 xhci_td_remainder(struct xhci_hcd *xhci, int transferred, static int xhci_align_td(struct xhci_hcd *xhci, struct urb *urb, u32 enqd_len, - u32 *trb_buff_len, struct xhci_segment *seg) + u32 *trb_buff_len, struct xhci_segment *seg, u32 max_pkt) { struct device *dev = xhci_to_hcd(xhci)->self.sysdev; unsigned int unalign; - unsigned int max_pkt; u32 new_buff_len; size_t len; - max_pkt = usb_endpoint_maxp(&urb->ep->desc); unalign = (enqd_len + *trb_buff_len) % max_pkt; /* we got lucky, last normal TRB data on segment is packet aligned */ @@ -3797,9 +3795,8 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags, if (enqd_len + trb_buff_len < full_len) { field |= TRB_CHAIN; if (trb_is_link(ring->enqueue + 1)) { - if (xhci_align_td(xhci, urb, enqd_len, - &trb_buff_len, - ring->enq_seg)) { + if (xhci_align_td(xhci, urb, enqd_len, &trb_buff_len, + ring->enq_seg, ring->bounce_buf_len)) { send_addr = ring->enq_seg->bounce_dma; /* TD bounced at least, and last on this seg */ td->bounce_seg = ring->enq_seg; -- 2.53.0