fix(dfu): read iSerial index at runtime; honor --cpid/--ecid overrides

Retire the three hardcoded DFU_SERIAL_INDEX = 3 constants in
usb_dfu.c, path_b_identity.c, and checkm8_internal.h. usb_dfu_find()
now captures bDeviceDescriptor.iSerialNumber into device_info_t and
usb_dfu_read_info() iterates hint -> 3 -> 4 with the sentinel check
deferred until every probe has returned only the product string. The
checkm8 spray helpers accept the resolved index as a parameter, and
the CLI override log fires whenever --cpid/--ecid populated a field
the descriptor read could not, so A14/A15/A16 devices no longer
strand users on the false NOT-in-SecureROM-DFU diagnostic.

Files modified:
- include/device/device.h
- include/device/usb_dfu.h
- include/exploit/checkm8_internal.h
- src/bypass/path_b_identity.c
- src/device/usb_dfu.c
- src/exploit/checkm8.c
- src/exploit/checkm8_spray.c
- src/main.c
- tests/mocks/mock_hw_stubs.c

Closes: #45, #65, #59, #27, #17, #52, #30, #22, #25, #10, #8, #6, #7
This commit is contained in:
Moussa Ouallaf 2026-07-17 03:03:52 +02:00
parent 443a18f9ad
commit 03d352d7f5
9 changed files with 332 additions and 101 deletions

View file

@ -37,11 +37,12 @@
#define USB_ABORT_TIMEOUT_MIN 0
/*
* Apple DFU devices report serial number at descriptor index 3.
* USB_MAX_STRING_DESCRIPTOR_IDX (10) is used as wIndex in GET_DESCRIPTOR
* requests to trigger the string descriptor allocation path.
* requests to trigger the string descriptor allocation path. The DFU
* serial descriptor index itself is no longer a compile-time constant
* -- it is read at runtime from bDeviceDescriptor.iSerialNumber and
* threaded through the spray helpers by their caller.
*/
#define DFU_SERIAL_IDX 3
#define USB_MAX_STRING_DESC_IDX 10
/* ------------------------------------------------------------------ */
@ -217,8 +218,11 @@ int checkm8_usb_request_stall(libusb_device_handle *usb);
/*
* checkm8_usb_request_leak -- Async GET_DESCRIPTOR with 1ms timeout
* and EP0_MAX_PACKET_SZ length. Returns 1 if sz==0, 0 otherwise.
* `iserial_idx` is the descriptor index that populates the low byte
* of wValue -- the caller reads it from bDeviceDescriptor.iSerialNumber
* (via device_info_t::iserial_index) rather than assuming a constant.
*/
int checkm8_usb_request_leak(libusb_device_handle *usb);
int checkm8_usb_request_leak(libusb_device_handle *usb, uint8_t iserial_idx);
/*
* checkm8_stall -- Repeatedly send GET_DESCRIPTOR with variable abort
@ -226,12 +230,12 @@ int checkm8_usb_request_leak(libusb_device_handle *usb);
* successful leak request. Matches gaster's checkm8_stall().
* Returns 0 on success, -1 if MAX_STALL_RETRIES is exceeded.
*/
int checkm8_stall(libusb_device_handle *usb);
int checkm8_stall(libusb_device_handle *usb, uint8_t iserial_idx);
/*
* checkm8_no_leak -- Async GET_DESCRIPTOR with 1ms timeout and
* (3*EP0_MAX_PACKET_SZ + 1) length. Returns 1 if sz==0, 0 otherwise.
*/
int checkm8_no_leak(libusb_device_handle *usb);
int checkm8_no_leak(libusb_device_handle *usb, uint8_t iserial_idx);
#endif /* CHECKM8_INTERNAL_H */