This is useful in CI to test various stages of dev-key signed
image vs secret key erase without having to go through a complete
suicide cycle on the chip.
This command is gated behind a feature flag that would only be
invoked for beta testing. I think it's still safe to have even
as a beta-signed feature because the worst you can do with this
is replace existing keys - so it could be used to DoS/brick, but not
leak secrets.
this allows the BIO to continue to function even though
the CPU core is in WFI. It isn't running at full speed, but
for some applications (such as WS2812 LED driving) the lower
speed is perfectly adequate and you save a lot of power
by turning off the CPU core.
The panic on failure causes incompatibility with older boot0's
that don't set up the collateral area correctly.
Make the failure more graceful, but we also promise ourselves
to add CI tests to check for this explicitly, because we can't
just rely on panics to enforce behavior.
this requires a PlatformSpecific extension to the
susres API.
In addition to that, a DeepSleep op is added so we're
no longer overloading the meaning of the SuspendRequest
operation.
there is currently no method to detect USB power connect
in this board. Considering adding a simple circuit to enable
this. This design is not meant to be battery powered but
it is possible that an aftermarket modification would introduce
a battery, in which case, vbus detection does become A Thing.
this one is a little bit tricky. The lite version of baosec
forgoes the off-chip TRNG to save cost. Thus, there is an
"anti-feature" in the configuration, and so in this case
the dabao version of the server has to be selected despite
the baosec flag.
Three pieces of inforation are leaked about the root seed:
- whether or not the first 64 bits are all 0
- whether or not the first 64 bits are all 3's
- whether if none of the above are true
It's fairly indirect leakage, and I think it is a relatively
minor price to pay for the confidence it gives that some underlying
library behavior didn't accidentally lead to faulty keygen.
Note that these 64 bits are 64 bits out of tens of thousands
of bits that go into the keygen, because the nuisance keys
and the chaff key are all blended together to create the final
derived root key. Thus the security margin on the key is quite
large and even a full disclosure of these 64-bits is a minor
impact on overall security.
The keystore is a sensitive server, and the one-way counters
have security-critical propoerties. So instead of revealing a
generic one-way counter API to the world, specific, limited
requests to do things are going to be created for the keystore.
In this case, the bootwait flag would be convenient to be able
to set from userspace. The motivation for this requirement is
actually continuous integration - a normal human could just
hold down a button while turning on power, but in CI, I don't
have a robotic thumb (or an alternative electrical signal) to
simulate the nerve-pinch on boot.
Previously I was "cheating" and simulating this by nuking the
loader, which effectively forces a bootwait.
However, in production, this is *not possible* because the JTAG
port is sealed off. Thus, this may be the first of a series
of small PRs to incorporate CI tooling that clears up tech
debt like nuking the loader to get into boot wait.
A particular edge case was finally reproduced & fixed. The edge
case occurs when a swap is triggered while handling an interrupt,
and an OOM happens during the context switch to/from the interrupt.
The background on this is that the hardware drivers for the swapper,
as well as much of the logical heavy lifting on e.g. what pages to
swap out, live in a userspace process known as xous-swapper.
The userspace process has to run free of interrupts - when you're
OOM'd or trying to swap, interrupts should not happen. The way to
do this in Xous is to run that code inside an interurpt context,
as interrupts are not interruptable.
Thus, the xous swapper userspace consists of two halves: a regular
userspace stub that provides some amount of control/debug over
the swapper, and a handler that gets run in a "pseudo-interrupt"
context.
Like all other interrupts, the handler "borrows" the stack of the currently
running thread - interrupt contexts don't have an explicit stack, they
just grow on top of the current stack of the current thread in the
current process at the time of the interrupt.
This is broken because when you have a swap event inside an interrupt
context, there are conditions where you might not have a stack. What
was in fact happening is that the stack pointer was being orphaned
as being the "exception stack" - which is a temporary location,
only accessible by the kernel, used for storing all the registers
going into and out of exceptions. Since no stack pointer is set up,
the moment the userspace starts to run and spill its registers to
stack, the system trips a "nested swap" event, which leads to a panic
because this is not allowed.
The fix to this is to devote two hard-wired pages, mapped in the
loader, to be the swapper's private stack area. Instead of behaving
like an interrupt and borrowing the caller's stack, the swapper instead
goes back to its hard-wired stack to do all the processing.
This should also improve the performance of swap handling in some
cases because we can now guarantee the stack is always in-memory
and doesn't need to be swapped in during swap processing.
One complication is that the "reserved memory" that the swapper
puts aside in case it *does* need to allocate extra pages during
handling can't be freed at the top of the OOM routine. Thus if
the swapper ends up using new pages, we should expect yet another
crash.
However, in practice, this doesn't seem to happen, because the
cases in which we hit needing a new page are typically related
to cases early on in boot where superpages/new page table entries
are being allocated, or if we're growing the heap that passes
data back and forth between swap and userspace. Because this call
triggers in such a specific condition, I hypothesize that actually
in practice it should generally be able to run without allocations.
One case where maybe it could hit an allocation is if the swapper
hit, for the first time, in an interrupt handler that was swapped
out, and never hit before, and the interrupt handler needed a
superpage to be allocated, thus triggering an allocation request
for a new PTE or two. I think this is probably pretty unlikely, but
if we do hit it, the fix would be to, for the purposes of targets
with "swap" enabled, to mark unmap_memory and map_memory to be
legal syscalls in interrupt contexts. These are normally illegal
because interrupts should always return - and these calls could
potentially fail or block. However, I think in this case it's
a trade-off between "we should be failing if we run out of memory"
and that failure being a potentially incorrect behavior that is guarded
against by a runtime check to discourage such calls.
turns out that when the keyboard is activated, *all* the keyboard
lines take over the GPIOs - and this will fight with the the doubled-up
PF7_PA2/PF8_PA1/PF9_PA0 I/Os.
Using the keyboard controller means that *all* of the PF2-PF9 pins
are now driven by the keyboard controller, regardless of the GPIO
setting.
This is because when the core is powered off, the GPIO output mappings
are lost (they are in the core domain, not always on), and the KPC
was implemented without the ability to selectively demux unused
rows/cols.
In particular on baosec this can lead to high power consumption on
the 24MHz clock when driving the camera, because the KPC fights
with the clock.
The mitigation for the current baosec hardware is to configure
the KPC such that the internal pull-up is responsible for the
"high" level, and it's only driven when "low". This reduces the
amount of fighting with the oscillator.
A future rev of hardware will move the osc to the PA3 pin, where
there is a PWM output but no muxing with the KPC, eliminating
the conflict entirely.
- shipmode is for long-term storage. it disconnects the battery
from the system so that the shelf life can be ~years
- deep sleep effectively shuts down the system but leaves the
real time clock running. Requires a full reboot to recover
from deep sleep.
The original RTC was set to a 1Hz tick, which isn't sufficient
for the time API
This has been reworked to give a 1/1024 second increment.
Rollover logic is implemented in the RTC. Requires the system
to be powered on at least once every 48 days to capture the
rollover, otherwise it could miss a rollover event. This is
fine because the backup battery doesn't last that long, and
scans of QR codes for password login always reset the RTC anyways.
The RTC offset randomization code is now gone because we're
not tracking long-term power-on information in the RTC.
add a little bit of timing dither to one of the core delay routines
this hardens the OS against glitch attacks by making the timing of
concurrent tasks less predictable
this makes i2c accessible without having to rely explicitly
on the server itself, making the library callable in more contexts.
necessitated avoiding a name space collision and moving the
I2C hardware drivers to a stucture named I2cDriver; the I2C
object now unambiguously refers to the userspace interface
to I2C.
40 bytes gives 320 bits which fits nicely into a version 3 code,
which allows 4 pixels per module rendering.
if we have to move to 3 pixels per module, the next code up that optimally
uses the full screen is version 6. This would give 102 bytes of transfer
in a single scan.
The equation for capacity is:
`binary_bytes = floor((alphanumeric_capacity / 3) × 2)`
where `alphameric_capacity` is the capacity of the QR code version
per spec lookup table.
a 40-byte message can be encoded in a version 3 code with
medium ECC. This is pretty optimal because it allows 4 pixels
per module in the QR code, which is a nice size for viewing.
base45 is added as a dependency to the project. Base45 is weird but
apparently it's the most efficient way to code binary data into a
QR code.
40 bytes (320 bits) is enough to exchange a 256-bit key plus
64 bits of sideband data. I think this is going to be enough for
basic device-to-device handshaking.
Previous implementation sent the QR code as draw commands.
This is inefficient as it would require hundreds of draw
commands to be sent per QR code rendered.
This implementation codes the QR code as a bool and sends
it in a single memory message, and implements a QR code renderer
on the receiver side.
The QR code rendering is also cleaned up so that the QR code is
always centered and takes the full screen, to give the best
conditions for someone scanning the code from another device.
sometimes on boot, a process tries to send keyboard an incorrectly
formatted message. I think this might be the IOX interrupt handler
firing due to random noise. Corrective action towards debugging
includes instrumenting the keyboard call with debug info, and also
ensuring that the iox interrupt handler banks are initialized to 0.
This allows the center key to be used as a UI trigger action
without creating a carriage return on the console. this prevents
console actions from errantly triggering during complex ui navs.
probably later on we should filter out more of the UI nav items
going to the console because the console is always listening
some panic messages are hundreds of characters long, most of them
are path hashes or paths to crates that are less useful.
truncate any panic messages to the last set of displayable
characters, so that the "most useful" portion (e.g. file name
and line number) are always visible in a panic.
the video layer is the "traffic cop" managing when modals
get focus. This patch creates a feed from the video layer
that listers to subscribe to that filters out key presses
destined for modals.
moving it a shy later into the boot makes the mount process faster
because it's not fighting for swap memory with everything else
trying to initialize at the time.
this is constructed in a way such that
1. it's gated off in production builds
2. if it was accidentally gated on, there is some security impact
but not a significant loss of security
We do need the telemetry so that during CI we can confirm that things
are actually working. I think the risk of being too buttoned-up
and then accidentally doing something like accidentally never
initializing keys and leaving them all zero is greater than the
risk of accidental partial leakage of information due to a procedural
mix-up in the image signing ceremony.
in theory, no production images should be signed that have this
feature enabled. But, reducing the amount of leakage just in
case an accident happens and this flag is somehow slipped
into a signed production image.
previous implementation was full of too many special cases
also add a version that allows us to fill using a seeded CSPRNG
for better performance on bulk fills
This moves the key store initialization to the key manager
process itself.
It has been tested to work with signed images, and to also
protect the system in case of another process trying to access
the key data as well as in the case of developer keys being
used.
gate out modals entirely from gen2 pddb
passwords in gen2 are now entirely handled outside of the
respective service crates, cleaning up the APIs
some history - on gen1 (precursor) devices, the thesis was to
reduce the amount of distance a password has to travel from
the point of a user entering it to the point of use. I think this
is academically interesting, but it pulls in a lot of code
into each service to manage the passwords, conflating services
with UI layers.
it was a nice experiment.
in gen2 (and hopefully beyond) targets, we now commit to
the idea that something else is passing in the sensitive key
materials. This means that, in fact, keying material has to
transition between process spaces, which increases the attack
surface to recover this. However, it also makes the crates
more portable and maintainable.
This is mitigated partially by the fact that in gen2 targets
the entirety of the code base runs within a piece of silicon,
so "sniffing" (passive observation of data going to memory)
attacks are a good bit harder.