A zero-length-packet write that returns `kIOReturnNoDevice` leaves the usbdev fd connected instead of marking it disconnected

オープン
#529 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
c, macos

調査の方向性

Read usbdev_async_cb in src/syscall/usbdev.c and the existing zlpfail fixture step in src/syscall/usbdev-fixture.c. Then inspect tests/test-usbdev-urb-loopback.c to see how fixture steps are exercised. Add coverage for a zero-length write returning a device-gone code; done means the fd reports POLLERR | POLLHUP and refuses ioctls with ENODEV.

索引モデルが issue の本文から書いたものです。

説明

bug

What happens

When an OUT URB with USBDEVFS_URB_ZERO_PACKET completes and the terminating zero-length write in usbdev_async_cb (src/syscall/usbdev.c) returns kIOReturnNoDevice or kIOReturnNotAttached, the URB gets -ENODEV but the fd is not marked disconnected. Until the IOKit terminate notification arrives (or never, when usbdev_arm_disconnect_watch could not register it), poll does not report POLLERR | POLLHUP and ioctls are not refused with ENODEV.

Evidence

Checked by reading at a20dfab; not reproduced. The comment above usbdev_ioret_device_gone says "Every site that sees one owes the fd a disconnect stamp" and names three sites: SUBMITURB's start, the completion callback, and the queued follower's start. The zero-length write in usbdev_async_cb is a fourth site that sees an IOKit result. Its result goes only through usbdev_urb_status, while the main transfer result in the same callback goes through usbdev_ioret_device_gone and usbdev_mark_disconnected_locked.

Cause

The disconnect state is set at each site that sees a device-gone IOKit code, and the ZLP write is the one site without the check.

Reproduce

Not reproduced. The loopback fixture's zlpfail step makes the zero-length write return kIOUSBPipeStalled, not a device-gone code, and its terminate step also fires the terminate notification, which stamps the fd and hides this. A fixture step that makes only the zero-length write return kIOReturnNoDevice would reproduce it with tests/test-usbdev-urb-loopback.c.

Possible fix

In usbdev_async_cb, after the zero-length write, call usbdev_mark_disconnected_locked(u) when usbdev_ioret_device_gone(zr) holds, as the main result does, and add the ZLP write to the site list in the comment above usbdev_ioret_device_gone. Add a zlpnodev step to src/syscall/usbdev-fixture.c for the test.

Origin

Follow-up from #525.

主要言語
C
スター
282
フォーク
32
平均マージ
1日 12時間
マージ済み PR(30日)
17

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

sysprog21/elfuse のほかの issue

sysprog21/elfuse の issue をすべて見る

似ている issue

C の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。