[BUG] usbmsc: GET MAX LUN / MS-RESET EP0 stall in composite mode — wIndex checked against compile-time USBMSC_INTERFACEID instead of dynamic devinfo.ifnobase
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 72/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 静か
- 技術スタック
- c
調査の方向性
drivers/usbdev/usbmsc.c と usbmsc_setup() を読み、リクエストのチェックを usbmsc_desc.c の動的なインターフェース割り当てと比較します。複合構成で GET MAX LUN と MS-RESET を再現または調査し、説明されている usbmon キャプチャを使って、それらがもうストールしないことを確認します。USBMSC がマウントされ、standalone 構成と CDC インターフェースに影響がないことが確認できれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Description
On a composite USB device that includes USBMSC (tested: CDC-ACM + CDC-NCM + USBMSC on
RP2350 / Raspberry Pi Pico 2 W), the Mass-Storage class control requests GET MAX LUN and
Bulk-Only Mass Storage Reset are answered with an EP0 STALL instead of the expected
response. macOS retries GET MAX LUN ~6 times over ~4 s and then, critically, reads a
garbage LUN count off the failed control transfer and probes phantom LUNs — after which
the drive never mounts. Linux tolerates the stall (assumes a single LUN) but the stall is
still wrong and observable.
This is not rp23xx/rp2040-specific — it is a generic bug in drivers/usbdev/usbmsc.c
that affects any composite configuration where the USBMSC interface number is not zero.
Root cause
usbmsc_setup() in drivers/usbdev/usbmsc.c validates the target interface of the
class/interface requests by comparing the request's wIndex against the compile-time
constant USBMSC_INTERFACEID:
#define USBMSC_INTERFACEID (CONFIG_USBMSC_IFNOBASE + 0) /* usbmsc.h, == 0 by default */
But in composite mode the USBMSC interface number is assigned dynamically by the
composite core and stored in priv->devinfo.ifnobase. The configuration descriptor is built
from that dynamic value:
/* usbmsc_desc.c */
dest->ifno = devinfo->ifnobase; /* interface descriptor advertises the real ifno */
So the host correctly directs GET MAX LUN / MS-RESET / GET&SET-INTERFACE to
wIndex == devinfo.ifnobase (interface 4 in my composite layout), but usbmsc_setup()
checks index != USBMSC_INTERFACEID (4 != 0) → ret = -EDOM → the USB driver stalls EP0.
Four comparisons in usbmsc_setup() are affected (SET_INTERFACE, GET_INTERFACE, MSRESET,
GETMAXLUN); all use USBMSC_INTERFACEID where they should use priv->devinfo.ifnobase.
In the standalone (non-composite) case ifnobase == CONFIG_USBMSC_IFNOBASE, so the two are
equal and the bug is invisible — which is why it has gone unnoticed.
Fix
- if (index != USBMSC_INTERFACEID)
+ if (index != priv->devinfo.ifnobase)
applied to the MSRESET and GETMAXLUN handlers (and the matching == test in the
GET/SET_INTERFACE handlers). Full diff below.
Reproduction and validation (RP2350, Raspberry Pi Pico 2 W, silicon; Linux host, usbmon)
Composite layout places USBMSC at interface 4. Forcing a fresh SCSI probe on Linux
(echo 3-4:1.4 > /sys/bus/usb/drivers/usb-storage/unbind, then bind) and capturing usbmon:
Before the fix — GET MAX LUN stalls:
S Ci:3:007:0 s a1 fe 0000 0004 0001 1 < # GET MAX LUN, bmRequestType a1, wIndex=4
C Ci:3:007:0 -32 0 # -EPIPE / EP0 STALL, 0 bytes
After the fix — GET MAX LUN succeeds:
S Ci:3:010:0 s a1 fe 0000 0004 0001 1 <
C Ci:3:010:0 0 1 = 00 # 1 byte returned, value 0x00 = 1 LUN
No regression: the FAT drive still mounts/reads, CDC-NCM and CDC-ACM are unaffected, and
cold re-enumeration is clean.
macOS impact (the motivating symptom)
On macOS the composite's network + serial come up but no disk device is ever created.
The kernel log shows GET MAX LUN stalling (endpoint 0x00: status 0xe0005000 (pipe stalled))
6×, then Max LUNs reported as 28 with 0xe0005000 — macOS reads a junk LUN count from the
stalled transfer — after which a bulk-IN babble error on 0x87 right after READ CAPACITY
sends IOUSBMassStorageDriver into a reset/retry loop that gives up. The babble does not
reproduce on Linux (Linux never mis-reads the LUN count). The working hypothesis is that the
babble is downstream of the phantom-LUN probing caused by the GET MAX LUN stall; a Mac
re-test of the fixed image is in progress. Either way the GET MAX LUN stall is a real,
independently-confirmed bug and the correct first fix.
Related
Same driver family and hardware as #19434 (rp2040/rp23xx cold-plug pull-up loss). This one
is in the generic drivers/usbdev/usbmsc.c layer rather than the arch USB driver.
Environment
- NuttX board branch tracking recent master;
drivers/usbdev/usbmsc.c,usbmsc_desc.c,
usbmsc.h. - RP2350, Raspberry Pi Pico 2 W, composite CDC-ACM + CDC-NCM + USBMSC (USBMSC at interface 4).
- Hosts: Linux (usbmon/sg_raw, reproduced + fix-validated), macOS (motivating symptom).
Disclosure
This investigation, root-cause analysis, and the tested fix were performed by an AI agent
(Claude Code), operated and directed by the submitter, and the results were reviewed by the
submitter before posting. Happy to provide the full usbmon captures, the macOS kernel-log
excerpts, or test any proposed alternative fix on hardware.
- 主要言語
- C
- スター
- 4.1k
- フォーク
- 1.7k
- 平均マージ
- 1日 10時間
- マージ済み PR(30日)
- 617
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
apache/nuttx のほかの issue
-
Type: Bug
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
apache/nuttx#17343 · コメント 4 件 ·
メンテナーはふだん 1 日以内に返信
-
Arch: all OS: Linux Type: Bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
apache/nuttx#16249 · コメント 7 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
apache/nuttx#21075 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
arch/arm/stm32: serial setformat writes CR1 parity/word-length bits with UE=1 in several drivers対応中かも @Sarthak-Pandey が 3 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
apache/nuttx#20969 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Arch: risc-v Area: Memory Management OS: Linux Type: Bug
難易度 5/5 1週間以上 初心者へのやさしさ 38/100
apache/nuttx#20582 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
libsdl-org/SDL#16607 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
PowerShell/Win32-OpenSSH#2482 · リアクション 1 件 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
OpenMathLib/OpenBLAS#6192 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
メンテナーはふだん 2 日以内に返信