xous-core/services/usb-bao1x
bunnie d3970eaa80 remove potential race condition in sending U2F packets over USB
The hardware handler structure passes through an interrupt
request boundary that breaks assumptions around the borrow
handler due to the unsafe transmutation of the record pointer
at the interrupt handler entry. This means that records shared
between the userspace and machine handler space are not part
of the borrow-checker's review.

This patch adds an AtomicBool flag that indicates if the ISR
has completed running, and forces the userspace to wait until
the ISR has completed before returning. This does potentially
slow down the rate of packet transmission but it ensures that
the `fido_tx_queue` structure does not have concurrency issues
in the case where the following happens:

1. U2fTx opcode encountered
2. fido_tx_queue has a u2f_msg put on it
3. ISR triggered
4. in the process of handling the ISR, a page fault is hit, so
the ISR doesn't start for some time.
5. Before the ISR returns, another U2FTx opcode is encountered
6. fido_tx_queue is being modified by userspace
7. The ISR is able to resume
8. You have a simultaneous modification to the fido_tx_queue
which is UB.

I think it's maybe possible that this scenario above can't
structurally happen due to an ISR page fault not allowing
the system to resume through to "normal" code running (iirc
the swapper will handle a page fault in ISR and resume directly
into the ISR routine) but this patch guards against incorrectness
in that implementation.

for what it's worth, later tests show that this bug was not
actually at the root cause of the behavior I was chasing down,
so in fact this was not happening. However I think it's still
a good idea to fix this potential problem.
2026-05-18 12:54:17 +08:00
..
src remove potential race condition in sending U2F packets over USB 2026-05-18 12:54:17 +08:00
Cargo.toml bump utralib version for publication 2026-01-29 19:12:00 +08:00