Accessory Access: IOUSBHostInterface can’t be opened after AAUSBAccessory.open() (QEMU-based VM app)

Hi,

I’m building a macOS hypervisor app based on QEMU + Hypervisor.framework (a fork of the open-source UTM project). Following Quinn’s advice in DTS case 23599042, I’m trying to implement USB passthrough on macOS 27 with Accessory Access instead of com.apple.vm.device-access. Since the app doesn’t use the Virtualization framework, I take the IOUSBHostDevice from AAUSBAccessory.open(serviceQueue:) and forward the transfers to QEMU through usbredir.

What works

“Claim USB Accessory” capability (com.apple.developer.accessory-access.usb), plus com.apple.security.app-sandbox and com.apple.security.device.usb
registerListener(:matchingCriteria:); the user assigns the device from the “Virtual Machine Accessories” menu bar item; usbAccessoryDidConnect fires
open(serviceQueue:) returns an IOUSBHostDevice; control transfers with enqueueDeviceRequest work; configureWithValue(
:matchInterfaces:) succeeds

What fails
Opening any interface. IOUSBHostInterface(__ioService:options:queue:interestHandler:) on the device’s child IOUSBHostInterface services always fails:

Error: Unable to open io_service_t object and create user client. with reason: IOServiceOpen failed.
Error: Failed to create IOUSBHostInterface. with reason: Failed [super init]
IOUSBHostErrorDomain 0xe00002c9

I tried with the interfaces as delivered, after configureWithValue(1, matchInterfaces: false) and after configureWithValue(1, matchInterfaces: true). No sandbox violations are logged. Device: USB 3 mass storage stick. macOS 27.0.1, Xcode 27.2.

Questions

Is interface and pipe access (IOUSBHostInterface / IOUSBHostPipe) supposed to work for an AAUSBAccessory opened by an app that doesn’t use the Virtualization framework?
If so, what’s the right way to get those objects?
If not, is the default control endpoint the intended scope? In that case I’ll file a feedback report, since bulk and interrupt endpoints are needed for USB passthrough in non-Virtualization hypervisors.

Thanks!

What fails Opening any interface. IOUSBHostInterface(__ioService:options:queue:interestHandler:) on the device’s child IOUSBHostInterface services always fails:

So, the first thing to do here is to open IORegistryExplorer, find you USB device, and then trace up to see what, if anything, is attached to the interface. Most problems here boil down to misunderstandings about the state of the overall registry, so getting a clear picture of that is always the first step.

Moving into speculation, the critical detail here is this:

Error: Unable to open io_service_t object and create user client. with reason: IOServiceOpen failed.

IOServiceOpen() is the basic IOKitLib call used to initiate user client access. The most helpful detail here would be what error it returned and, since we didn't log it, the easiest way to GET that error code is to simply call "IOServiceOpen()" yourself and see what error it returns.

If I had to guess, you'll get "kIOReturnExclusiveAccess". That's what would happen if you're original IOUSBHostDevice didn't capture or seize. You're accessing mass storages devices:

Device: USB 3 mass storage stick.

...which means you can't just open the existing interface, as that interface will already be in use by the mass storage stack. You need to take control of the device so the mass storage stack unloads, which will then allow you to control the interfaces.

Is interface and pipe access (IOUSBHostInterface / IOUSBHostPipe) supposed to work for an AAUSBAccessory opened by an app that doesn’t use the Virtualization framework?

Yes. Functionally, the IOUSBHost framework is useless without interface/pipe access and the AccessoryAccess framework wouldn't have worked at all if it wasn't willing to allow communication.

If so, what’s the right way to get those objects?

See above for my best guess as to whats going on.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

Thanks Kevin, that was very helpful. I called IOServiceOpen() directly on the interface service and logged the registry state:

IOServiceOpen() returns 0xe00002e2 (kIOReturnNotPermitted), not kIOReturnExclusiveAccess.
No mass storage driver is attached to the interface. The only child of IOUSBHostInterface@0 is an AppleUSBHostFrameworkInterfaceClient, and the interface reports busy = 1.
ioreg while the device is assigned to my app:
+-o UDisk@20231400 <class IOUSBHostDevice, registered, matched, active, busy 0>
+-o IOUSBHostInterface@0 <class IOUSBHostInterface, registered, matched, active, busy 0>
+-o yuVM@20231400 <class AppleUSBHostFrameworkDeviceClient, !registered, !matched, active>

So the device client from AAUSBAccessory.open() belongs to my process, but opening the interface is rejected with kIOReturnNotPermitted. I get the same result with the interfaces as delivered, after configureWithValue(1, matchInterfaces: false) and after configureWithValue(1, matchInterfaces: true), and also with IOUSBHostObjectInitOptionsDeviceSeize on the interface.

The app is sandboxed with com.apple.developer.accessory-access.usb and com.apple.security.device.usb; no sandbox denials are logged.

Is there an additional step or entitlement needed to open the interfaces of a device obtained through Accessory Access? Or should the interfaces be obtained some other way than creating IOUSBHostInterface from the child services of the device?