this adds, with a feature-gate, the option for userspace
programs to use & access keys in the APPLICATION data slots.
The implementation bounds-checks the requested indices to ensure
sensitive data in slots around the APPLICATION region cannot
be accessed. Even with corrupted AppKeyOp packets, it shouldn't
be possible to access other slot ranges, but because this code
is so intimate with importan secrets it's recommended to
gate the feature off unless required by the end user application
code.
This patch replaces the watchdog thread with a spin-wait on
an atomicbool that is set by the IRQ handler once an IRQ
triggers. This is a much cleaner, lower-overhead way to handle
the time out.
This patch also puts the camera setup into a retry loop, and
by default on setup it does a hardware reset of the display
subsystem (this includes the OLED screen). This hopefully
gives the subsystem a much better chance of recovering from
the camera being in a scrambled state. The working theory
for why the camera might get scrambled is that it assumes
it is a sole I2C device, and when its init sequence is
interrupted by other devices handling requests it does
not handle this situation gracefully.
The password verification in RootKeys compared hashed passwords
byte-by-byte with an early return on mismatch. This leaks how many
leading bytes match through timing, weakening the protection that
bcrypt provides.
Replace the loop with subtle::ConstantTimeEq::ct_eq, which is
already used elsewhere in this crate (backups.rs, FPGA key check).
Signed-off-by: Finn Glas <finn@finnmglas.com>
dry-runs are useful for warming up "hot paths" in UI code
to improve latency. This is specifically a feature for tuning
interactions on systems that have swap memory.
on first boot, camera may not always start (some boards it never starts)
it always starts on a second prompting
the issue is related to the relevant code being swapped out, it seems;
i think an event fires and gets missed in the fray of all the data
being swapped in from off-chip storage.
this patch:
- re-orders the pipe warming and system bring-up
- adds a watchdog thread that ensures the camera interrupt fires,
and if it does not, issues a manual camera interrupt to kick
start the system
This greatly improves the reliability of first-start success. Across
several trials on many units i had only one misfire - not sure what
it was, can't reproduce, but this is much better than the roughly
80-90% misfire rate I was seeing before.
ship it.
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.
Mirror the error code at byte 1 (in addition to byte 4) in
respond_with_error. The std-side Xous net backend's send path
reads byte 4 (correct vs. the historical [1,1,1,1,code,0,0,0]
layout), but the recv paths read byte 1 (which is always 1
under the old layout, so ErrorKind::TimedOut and WouldBlock
were unreachable from the recv side). With this change both
decoders see the right value; existing byte-4 readers are
unaffected; the "buf as u32-LE != 0" error marker still holds
because byte 0 stays 1.
Companion PR to rust-lang/rust will fix the std side to read
byte 4 and match the send path. This kernel-side mirror is the
shippable workaround until that lands and works with any
Rust-toolchain version.
kernel can lock on boot if keys are pressed in the loader. This
would cause the interrupt handler to trigger while the handler is
being registered, before everything is set up, leading to an IRQ
storm and the kernel hanging.
the fix is to simply disable interrupts while the setup is happening
a further refactor is the run() method is marked as diverging,
so that it's clear what's going on in the code. this refactor
touches other targets as well, since it's at an api level and
not just a target level.
the susres process timeout timer was not cancellable, which means
that there was always a timeout pending regardless of the
success or failure of a suspend/resume process.
This fixes the implementation so that the timer is cancelled
in the case of a successful suspend/resume.
- move susres service up in order
- move clock mangaer up
- move i2c into its own thread
- move keyboard server down
- add centralized hnadlers for perclk update
- TODO: actually call perclk update on perclk changes
(but at least now both ADC and I2C have a hook for updating)
- make main loop stall at the end by calling a dummy server
- This reduces CPU load by removing a future-dummy-wait timer
an instance of the SPI interface timing out was observed on boot.
It's rare, but it happens.
This wraps those early calls with a retry loop and then
fail to reboot in case something really goes wrong.
Assisted-by: qwen3.6:27b (local)