From mboxrd@z Thu Jan 1 00:00:00 1970 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=1796157215; b=Kl9SXA9aI9IU92RthU4U4/s1fp+/IfgTADtVFsy2b9fCTSpEkx2nkcXhvYL6P2F7nb94 Mqmoigjt7gIxBgFTVUrGoazMZzjVL010cYkliUwGITv3PDeEWYaxUA5xxDlTHfoKXjEMj bYYc7HKzv7RR0CVA4DLQLHFVYzg80Jvi1uKSzYa66PmJxZ7P1JBfO169nJWP9/McN9FVh ksSjUXmWC4Wl4kAlE/4K31aJr+cCzb8FfaciLnoTG4s5WvLTU/5rQNOcfgVgSoqjnloXk 3/CMCo1/3d9KMksUhE9udtkmOR2j8ds1esWqv2eemhER1NkI1SwqtspXxZ2pfTF7PcQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796157215; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=+7jYGZ5xAwYYJIHIJWbyfypDAETOjdLrKTj0TjG+ACM=; b=zeEYpIpjC9zmvnpMT11fSfcMazO8zrVH4WAcyF6Hkg16lWa+6TEWtpFhcrIXoywlvWix hb5CNqnA9mf6PBDjuDnPeCnAh9Rm1FGe7qOHUbg/FvKsegB//Ybubw1W4/5SYbPvTNK3X QKrf/s1Rd7uSJXaDSZsy90KfrUKJBAUio9nMNAq3Me3yfZzNjrXQT8Un81jvXgFnIs60b QDoVuoSXiwO9HflNl00JLgSuE41KV7hN4QenHnjK7mJOObN0Zc17N8XzJdC2tOv+azQS8 u7RhmvQkxDpFZ8noSNfOAB/fEmRYjVbGga2/8TXcYEVdZJehoO5NRaFccbcZAzIohoA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=SMO2xA2f; 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 21D13606A31A for ; Tue, 1 Dec 2026 20:33:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=SMO2xA2f Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9C6611F000C1; Tue, 1 Dec 2026 20:33:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796157214; bh=+7jYGZ5xAwYYJIHIJWbyfypDAETOjdLrKTj0TjG+ACM=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=SMO2xA2f6aBsdEcU7it2dvPewztW1bn/6CYD2HiRBfOaldHlLvw08eB3Asme+hSZk 2b2UlN1AIswhbE00bdbWmKEw+juRvDlnCzpM6NzaO5NBwSiRAmrB+JtpQDeutuxp/p 7kyTel8Tcw26VHQGzrCW/aDEC4oYVKO7g0YrcYonElSLncxzqPCV/sB3o8FQotHdNq 7SgAiFR93Bu4BhF+xc5ulNRyHNPG+nbV3rHp7L2ju8kT6ryPoAnte1pgi2lMuv05uf 64y23HDpId4c6MB7t8V802VOl7BihCQUqs3zNBOUOHPbTcIa2GWsjFQAWdT5OAKNRB ojXdRzutF4SZA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] usb: xhci: reject bulk transfers beyond mapped scatterlists Reply-To: sashiko-reviews@lists.linux.dev To: "Artem Dinaburg" Cc: linux-usb@vger.kernel.org In-Reply-To: <20261201202438.32470.9674.04-xhci-sg-length-patch@trailofbits.com> References: <20261201202438.32470.9674.04-xhci-sg-length-patch@trailofbits.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Tue, 01 Dec 2026 20:33:34 +0000 X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce: - [Critical] usb: xhci: ignored prepare_transfer() error in xhci_queue_bulk_tx() [1] -- commit e3051e84fd8a91e56973b850c546c8ac5a2336b8 Author: Artem Dinaburg usb: xhci: reject bulk transfers beyond mapped scatterlists This commit makes count_sg_trbs_needed() return -EINVAL if an URB's transfer_buffer_length exceeds the mapped scatterlist length or if no TRBs are counted, and checks this error in xhci_queue_bulk_tx() before calling prepare_transfer(). > diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c > index 7ccd89a4b9951..071b3ba684d70 100644 > --- a/drivers/usb/host/xhci-ring.c > +++ b/drivers/usb/host/xhci-ring.c [ ... ] > @@ -3692,9 +3695,12 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_= t mem_flags, > if (urb->num_sgs && !(urb->transfer_flags & URB_DMA_MAP_SINGLE)) { > num_sgs =3D urb->num_mapped_sgs; > sg =3D urb->sg; > + ret =3D count_sg_trbs_needed(urb); > + if (ret < 0) > + return ret; > + num_trbs =3D ret; > addr =3D (u64) sg_dma_address(sg); > block_len =3D sg_dma_len(sg); > - num_trbs =3D count_sg_trbs_needed(urb); > } else { > num_trbs =3D count_trbs_needed(urb); > addr =3D (u64) urb->transfer_dma; [Severity: Critical] This problem wasn't introduced by this patch, but later in xhci_queue_bulk_tx() does the need_zero_pkt block ignore a prepare_transfer() failure [1]? drivers/usb/host/xhci-ring.c:xhci_queue_bulk_tx() { ... if (need_zero_pkt) { ret =3D prepare_transfer(xhci, xhci->devs[slot_id], ep_index, urb->stream_id, 1, urb, 1, mem_flags); urb_priv->td[1].end_trb =3D ring->enqueue; urb_priv->td[1].end_seg =3D ring->enq_seg; field =3D TRB_TYPE(TRB_NORMAL) | ring->cycle_state | TRB_IOC; queue_trb(xhci, ring, 0, 0, 0, TRB_INTR_TARGET(0), field); } ... } If the payload TRBs fill the ring and prepare_transfer() fails to expand it, queue_trb() still writes the zero-length packet TRB into an unreserved slot, overwriting active or link TRBs, and leaves urb_priv->td[1] off the endpoint's td_list so the URB never completes. [1] https://sashiko.dev/#/bug/linux-d1207da1-af8c-42d8-b0aa-53d3000029e7 --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261201202438.3247= 0.9674.04-xhci-sg-length-patch@trailofbits.com?part=3D1