Skip to content

96. There is no boundary: the response sender has no bound, so the loop overwrites its own counter

Section 94 ended by saying the threshold at program 0x010A56 had to be a comparison somewhere in the firmware and that somebody could find it. There is no such comparison, and there is no threshold. What decides whether an unterminated read ends is the byte the loop happens to read 0x8C7 bytes above where it starts, because the byte sender writes past the end of the response buffer and eventually writes into the loop's own counter.

The sender does not bound anything

0x20394 is nine instructions and there is no length check among them:

20394: 02 01       MOVLB 0x2
20396: c7 c2 e9 ff MOVFF 0x2c7,FSR0L      ; a 16 bit write pointer, 0x2C7/0x2C8
2039a: c8 c2 ea ff MOVFF 0x2c8,FSR0H
2039e: c7 2b       INCF 0x2c7,F           ; advanced before the byte lands
203a0: 00 0e       MOVLW 0x00
203a2: c8 23       ADDWFC 0x2c8,F
203a4: cd c2 ef ff MOVFF 0x2cd,INDF0      ; the byte, wherever the pointer now points
203a8: 04 01       MOVLB 0x4
203aa: 0d 2b       INCF 0x40d,F           ; and the response length, also unbounded
203ac: 12 00       RETURN

So a caller that sends more bytes than the buffer holds walks the pointer up through data memory, writing what it sends. The loop of section 94 is exactly such a caller: with an odd count it never reaches its exit test, and it emits two bytes an iteration for as long as it runs.

Where the pointer starts, and what it reaches

The command layer reloads the pointer before every response, at 0x2015E, after polling the descriptor bit that says the previous report has gone:

2014c: 04 01       MOVLB 0x4
2014e: 0c bf       BTFSC 0x40c,7          ; previous report still pending, come back later
20150: b5 d0       BRA 0x202bc
20152: 05 0e       MOVLW 0x05
20154: 02 01       MOVLB 0x2
20156: 84 5d       SUBWF 0x284,W          ; the command state
20158: 27 e0       BZ 0x201a8
2015a: 02 01       MOVLB 0x2
2015c: 68 0e       MOVLW 0x68
2015e: c7 6f       MOVWF 0x2c7            ; buffer base 0x0468
20160: 04 0e       MOVLW 0x04
20162: c8 6f       MOVWF 0x2c8

The read body then sends two bytes before the loop starts, the response code at 0x26B9C and 0x28C at 0x26BA8, so the loop's first data byte lands at 0x046A. Its counter is 0xD31, its scratch word 0xD32 and 0xD33, and its 24 bit address 0xD34 to 0xD36, all above the pointer and all in its path.

0xD31 - 0x046A is 0x8C7, which is 2247 bytes, or 1124 iterations. Until then nothing the loop writes changes anything it uses: the pointer only climbs, 0xD32 and 0xD33 are rewritten every iteration anyway, and the address bytes sit above the counter. At iteration 1124 the counter is overwritten with a byte read from flash, and from that moment:

  • if the byte is even, the count reaches zero and the read completes normally, having scribbled 2247 bytes of data memory on its way;
  • if it is odd, the loop carries on, the next writes land on the address bytes, the read jumps somewhere else and the remote does not come back until it restarts.

So the rule is a parity test on one byte of flash, 0x8C7 above the start of the chunk that hangs. Not a comparison, not a region, and nothing about 0x010A56 at all.

Every measurement so far, predicted

A simulation of the loop, given the sender's behaviour above, the addresses out of the disassembly and the page 0xFF image read off the spare, predicts 21 of 21 measurements from sections 93 and 94, including the shape the bisection could not place: offset 0xA80, where the read returns and the remote dies immediately afterwards, which is the even case with 2247 bytes of collateral.

Two controls, because a simulation with a free parameter would predict anything:

the write pointer starts at measurements predicted
0x0466 to 0x0469 16 to 18 of 21
0x046A, the value the firmware gives 21 of 21
0x046B to 0x046E 15 to 17 of 21

and, with the sender given the bound it does not have, so that only the count decides:

model measurements predicted
bounded sender, parity of the count alone 11 of 21, and it cannot tell any two offsets apart

The constant was not fitted. 0x0468 is a literal at 0x2015E and the two preamble bytes are two CALLs, so 0x046A was read out of the firmware and then tested.

The model is src/harmony/readloop.py and the 21 of 21 above is one command away for anyone holding the page. Two more were then predicted in advance and measured, below, for 23 of 23. The regression test deliberately does not run it against that page, because page 0xFF carries the remote's identity block and is the one image kept out of tests/lab.py for that reason. So the test pins the mechanism, which is where the argument actually lives: that the sender is nine instructions with no comparison, skip or branch among them, that the pointer is reloaded per report from 0x0468, that two bytes precede the loop, and that the counter therefore sits 0x8C7 above where the loop starts writing. The model is then exercised on synthetic pages, including the negative that a byte one position either side of the deciding one changes nothing.

There is a second, independent check that does not use the simulation at all. Take the fourteen bisection outcomes as fourteen parity constraints on an unknown offset k, and search every k from 1 to 0xD31: 27 of 3377 satisfy all fourteen, and 0x8C7 is one of them. That sounds weak until the null is measured. Shuffling which outcomes were hangs, 300 times, 297 of the 300 shuffles admit no k at all, so a satisfiable pattern is itself the unlikely thing here.

What this kills

The threshold at 0x010A56 is an artefact of which offsets the bisection chose. Every offset tried below it, 0, 2, 0x40, 0x800, 0xA00, 0xA40, 0xA50 and 0xA54, happens to have an even byte 0x8C7 above its final chunk. They are round numbers, and round numbers in this image land in structured, zero rich data, so that is less of a coincidence than it looks. On the same reading 568 of the 1323 even offsets below 0xA56 hang, and 983 offsets above it survive in the first 0x2000 alone.

The bisection was not wasted: it is what forced the explanation to be content dependent, since no comparison produces a threshold at 0xA56, and it is the data every part of this section is tested against. What it does not support is the word boundary.

Falsified on hardware, in both directions, the same day

Two 63 byte reads on page 0xFF, each with a 62 byte control at the same offset first, written down here and committed before the spare One was plugged in. The unit was identified from what it holds, not from its path: its config base matches one-spare-after-sync-config.bin byte for byte.

offset deciding byte boundary reading section 96 measured
0x0004, 62 bytes returns returns 62 bytes in 4 ms
0x0004, 63 bytes 0x01 at page offset 0x0909 returns, it is far below the threshold hangs failed after 146 ms, remote gone
0x0A66, 62 bytes returns returns 62 bytes in 4 ms
0x0A66, 63 bytes 0xFE at page offset 0x136B hangs, it is above the threshold returns 63 bytes in 45 ms

Both predictions hold and the two readings disagree about both. 0x0004 is four bytes above an offset measured safe three times and 2642 bytes below the supposed threshold, and it hangs. 0x0A66 sits above the threshold and comes back. So the threshold is not a weak rule with exceptions, it is not a rule at all, and one byte of flash 2247 further on decides each case.

The remote came back on its own in under two seconds at a new device path, a seventh self-clearing restart, and its config base read back identical afterwards.

That takes the record to 23 of 23 measurements predicted, of which these two were predicted in public before the remote was connected, which the other 21 were not.

What it means for the rail

Nothing changes and the reason is now better. packages/usb refuses an odd count on internal memory everywhere, and an odd total is exactly the condition for an odd final chunk, because the chunker emits 62 byte chunks and a remainder. What the refusal prevents is not a restart at certain addresses: it is a loop that writes an unbounded amount of flash content over data memory, whose best case is 2247 bytes of collateral damage and a successful looking reply. The reply from a "survived" odd read is not trustworthy either, which is a reason to refuse the count rather than tolerate the ones that return.

The same defect is on all three architectures, and only the distance differs

Established the same day, so the paragraph that used to end this section saying it was not is gone. Each image was read the same way, starting from the fetch primitive's own shape, a TBLRD*+ and a TBLRD* six bytes apart feeding PRODL and PRODH, rather than from an address guessed by analogy.

fetch loop head exit test sender buffer base counter distance
arch 12, One 3.4 0x2E70A 0x26BC8 0x26C16 0x20394 0x0468 0xD31 0x8C7, 2247
arch 14, 700 2.8 0x1B558 0x0CA8A 0x0CAD6 0x172DA 0x0468 0xD5D 0x8F3, 2291
arch 9, 525 0x07DC4 0x03372 0x033A4 0x0173C 0x0468 0x70B 0x2A1, 673

Everything that makes the defect a defect is common to all three:

  • the exit test is SUBLW 0x00 then BNC on each, so an odd count never reaches zero;
  • the step is two, because the fetch can only read a word;
  • the sender advances a 16 bit pointer and stores through it with no bound, and increments the same byte at 0x40D on all three;

Corrected within the hour, section 98. That line went on to call the shared 0x40D "the sort of coincidence that says one codebase rather than three". It is not a coincidence and it says nothing about the codebase: 0x40C is the USB buffer descriptor for endpoint 1 IN, 0x40D is its byte count and 0x40E and 0x40F its buffer address. Those are fixed by the part, so all three would share them however they were written. The genuinely shared software choice is the buffer base 0x0468, and one address is thin evidence. * the buffer base is the literal 0x0468 on all three, reloaded per report; * two bytes precede the loop, so it starts writing at 0x046A everywhere; * and the loop's counter sits below its own address bytes in every layout, so the runaway pointer always reaches the counter first. That ordering is what makes the outcome a parity test on one byte rather than a jump to an arbitrary address.

What differs is only how long the remote survives. Arch 9 decides after 337 passes where arch 12 takes 1124 and arch 14 1146, so a 525 scribbles a third as much of its memory before the byte that settles it, and reaches that byte three times sooner.

src/harmony/readloop.py carries all three as PROFILES. The library's refusal is on the count and is architecture independent, so nothing about the rail changes; what this settles is that adding a read profile for a new architecture must not be taken as evidence that its internal read path is safe, because on the evidence here it will have the same defect.


Section 95 | the archive | section 97. Section 96 of the findings archive, which is frozen; the reference holds the current answer. The archive on GitHub.