Linux USB
 help / color / mirror / Atom feed
From: Yongjin Lee <contact@marulee.dev>
To: valentina.manea.m@gmail.com, shuah@kernel.org
Cc: i@zenithal.me, gregkh@linuxfoundation.org,
	linux-usb@vger.kernel.org, Yongjin Lee <contact@marulee.dev>,
	stable@vger.kernel.org
Subject: [PATCH] usbip: stub: ignore peer NO_TRANSFER_DMA_MAP
Date: Sun,  6 Dec 2026 03:55:16 +0900	[thread overview]
Message-ID: <20261205185516.587-1-contact@marulee.dev> (raw)

The stub driver allocates transfer buffers and relies on the USB core to
map them for DMA. A peer can set USBIP_URB_NO_TRANSFER_DMA_MAP, which the
stub translates to URB_NO_TRANSFER_DMA_MAP. This skips the mapping,
leaving the HCD to use urb->transfer_dma even though the stub never sets
it and the peer cannot supply a valid server-side DMA address.

Clear the wire flag before constructing URBs, and remove the URB flag
from the allowed mask. The early clear also covers paths that return
before masking_bogus_flags() applies its mask.

On a no-IOMMU QEMU xHCI guest, a peer-supplied flag caused the host
controller to write device data outside the allocated transfer buffer.
With this change, the same request returned the expected data, as did
the normal control request. The same EP0 comparison passed on Linux
6.18.66 and on mainline revision
28a23309c8e40d651faf4cc3cc9b71458a11b987.

OpenAI Codex (GPT-6) assisted in tracing the flag and drafting the fix
and changelog. The result was checked with source review and the QEMU
before/after test described above.

Fixes: 4d7b5c7f8ad4 ("Staging: USB/IP: add host driver")
Cc: stable@vger.kernel.org
Signed-off-by: Yongjin Lee <contact@marulee.dev>
---

Notes (usbip-submission):
    Full x86_64 KASAN builds passed, with no new W=1 warnings.

 drivers/usb/usbip/stub_rx.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/usbip/stub_rx.c b/drivers/usb/usbip/stub_rx.c
index 1e9ae578810..04164022047 100644
--- a/drivers/usb/usbip/stub_rx.c
+++ b/drivers/usb/usbip/stub_rx.c
@@ -429,8 +429,7 @@ static void masking_bogus_flags(struct urb *urb)
 	}
 
 	/* enforce simple/standard policy */
-	allowed = (URB_NO_TRANSFER_DMA_MAP | URB_NO_INTERRUPT |
-		   URB_DIR_MASK | URB_FREE_BUFFER);
+	allowed = URB_NO_INTERRUPT | URB_DIR_MASK | URB_FREE_BUFFER;
 	switch (xfertype) {
 	case USB_ENDPOINT_XFER_BULK:
 		if (is_out)
@@ -482,6 +481,10 @@ static void stub_recv_cmd_submit(struct stub_device *sdev,
 	if (pipe == -1)
 		return;
 
+	/* The remote peer has no server-side DMA address for this buffer. */
+	pdu->u.cmd_submit.transfer_flags &=
+		~USBIP_URB_NO_TRANSFER_DMA_MAP;
+
 	/*
 	 * Smatch reported the error case where use_sg is true and buf_len is 0.
 	 * In this case, It adds SDEV_EVENT_ERROR_MALLOC and stub_priv will be
-- 
2.43.0


             reply	other threads:[~2026-12-05 18:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05 18:55 Yongjin Lee [this message]
2026-12-05 19:13 ` [PATCH] usbip: stub: ignore peer NO_TRANSFER_DMA_MAP sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261205185516.587-1-contact@marulee.dev \
    --to=contact@marulee.dev \
    --cc=gregkh@linuxfoundation.org \
    --cc=i@zenithal.me \
    --cc=linux-usb@vger.kernel.org \
    --cc=shuah@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=valentina.manea.m@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox