* [PATCH] usb: core: hcd: fix accessing unmapped memory in SINGLE_STEP_SET_FEATURE test
@ 2025-08-06 8:39 Xu Yang
2025-08-06 14:48 ` Alan Stern
0 siblings, 1 reply; 2+ messages in thread
From: Xu Yang @ 2025-08-06 8:39 UTC (permalink / raw)
To: gregkh, mingo, tglx, jun.li, viro, thomas.weissschuh,
andriy.shevchenko, stern
Cc: linux-usb, linux-kernel, imx
The USB core will unmap urb->transfer_dma after SETUP stage completes.
Then the USB controller will access unmapped memory when it received
device descriptor. If iommu is equipped, the entire test can't be
completed due to the memory accessing is blocked.
Fix it by calling map_urb_for_dma() again for IN stage. To reduce
redundant map for urb->transfer_buffer, this will also set
URB_NO_TRANSFER_DMA_MAP flag before first map_urb_for_dma() to skip
dma map for urb->transfer_buffer and clear URB_NO_TRANSFER_DMA_MAP
flag before second map_urb_for_dma().
Fixes: 216e0e563d81 ("usb: core: hcd: use map_urb_for_dma for single step set feature urb")
Cc: stable@vger.kernel.org
Reviewed-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
---
drivers/usb/core/hcd.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 03771bbc6c01..c4a1875b5d3d 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -2166,7 +2166,7 @@ static struct urb *request_single_step_set_feature_urb(
urb->complete = usb_ehset_completion;
urb->status = -EINPROGRESS;
urb->actual_length = 0;
- urb->transfer_flags = URB_DIR_IN;
+ urb->transfer_flags = URB_DIR_IN | URB_NO_TRANSFER_DMA_MAP;
usb_get_urb(urb);
atomic_inc(&urb->use_count);
atomic_inc(&urb->dev->urbnum);
@@ -2230,9 +2230,15 @@ int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
/* Complete remaining DATA and STATUS stages using the same URB */
urb->status = -EINPROGRESS;
+ urb->transfer_flags &= ~URB_NO_TRANSFER_DMA_MAP;
usb_get_urb(urb);
atomic_inc(&urb->use_count);
atomic_inc(&urb->dev->urbnum);
+ if (map_urb_for_dma(hcd, urb, GFP_KERNEL)) {
+ usb_put_urb(urb);
+ goto out1;
+ }
+
retval = hcd->driver->submit_single_step_set_feature(hcd, urb, 0);
if (!retval && !wait_for_completion_timeout(&done,
msecs_to_jiffies(2000))) {
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] usb: core: hcd: fix accessing unmapped memory in SINGLE_STEP_SET_FEATURE test
2025-08-06 8:39 [PATCH] usb: core: hcd: fix accessing unmapped memory in SINGLE_STEP_SET_FEATURE test Xu Yang
@ 2025-08-06 14:48 ` Alan Stern
0 siblings, 0 replies; 2+ messages in thread
From: Alan Stern @ 2025-08-06 14:48 UTC (permalink / raw)
To: Xu Yang
Cc: gregkh, mingo, tglx, jun.li, viro, thomas.weissschuh,
andriy.shevchenko, linux-usb, linux-kernel, imx
On Wed, Aug 06, 2025 at 04:39:55PM +0800, Xu Yang wrote:
> The USB core will unmap urb->transfer_dma after SETUP stage completes.
> Then the USB controller will access unmapped memory when it received
> device descriptor. If iommu is equipped, the entire test can't be
> completed due to the memory accessing is blocked.
>
> Fix it by calling map_urb_for_dma() again for IN stage. To reduce
> redundant map for urb->transfer_buffer, this will also set
> URB_NO_TRANSFER_DMA_MAP flag before first map_urb_for_dma() to skip
> dma map for urb->transfer_buffer and clear URB_NO_TRANSFER_DMA_MAP
> flag before second map_urb_for_dma().
>
> Fixes: 216e0e563d81 ("usb: core: hcd: use map_urb_for_dma for single step set feature urb")
> Cc: stable@vger.kernel.org
> Reviewed-by: Jun Li <jun.li@nxp.com>
> Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
> ---
Acked-by: Alan Stern <stern@rowland.harvard.edu>
I guess we both overlooked the fact that the URBs used in this debugging
pathway get submitted in two partial steps.
Alan Stern
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-08-06 14:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-06 8:39 [PATCH] usb: core: hcd: fix accessing unmapped memory in SINGLE_STEP_SET_FEATURE test Xu Yang
2025-08-06 14:48 ` Alan Stern
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).