Commit graph

10340 commits

Author SHA1 Message Date
bunnie
3220e48015
add some more debug output on acl adjustment 2025-10-28 21:53:57 +08:00
bunnie
643946a82a
make acl correct by default for the data region 2025-10-28 21:53:33 +08:00
bunnie
bb801a16ed update docs 2025-10-28 21:40:37 +08:00
bunnie
90c46c65c3
add altboot support to bao1x targets
specify cargo xtask baot1x-alt-boot1 and dragging this UF2
file onto the disk boots into an alternat boot1 loader that
allows updating of boot1.
2025-10-28 21:38:44 +08:00
bunnie
09309eb3ae
better altboot support
for updating boot1 on dabao
2025-10-28 21:37:55 +08:00
bunnie
28f7a8d6b2 remove default feature used for testing 2025-10-28 18:54:37 +08:00
bunnie
4e0b5100b8
loader: detect dev key
loader was previously just accepting a dev key image and not
doing any countermeasures. now, kernel, detached-app, or swap
not being properly signed activates countermeasuers.

also select the swap key fallback for checking swap. this is
"half" of the solution, the other half will have to be implemented
in userspace - if we do it at all. i'm starting to think that
the swap encryption is not necessary, it was introduced
under the assumption that signature checking swap would be
too slow, but it's not. so maybe this feature will get dropped.
2025-10-28 18:50:40 +08:00
bunnie
c827a0ed12
add swap key slot 2025-10-28 18:50:09 +08:00
bunnie
d37f74f51d
lockfile update for the commit set 2025-10-28 18:03:14 +08:00
bunnie
b557cd5ebc
add some trng tests to the console 2025-10-28 18:02:33 +08:00
bunnie
79eab7da5e add feedback on boardtype resetting 2025-10-28 18:02:11 +08:00
bunnie
82a47602c2 improve std interface for bio
- imem accessors are static-mapped slices
- AtomicCsr is used so that the bio structure is Sync allowing
it to be shared across threads
2025-10-28 18:01:17 +08:00
bunnie
3e22f5f9cf add board type specifier for dabao-console 2025-10-28 18:00:56 +08:00
bunnie
52198821b0 cleanup typos 2025-10-28 18:00:38 +08:00
bunnie
c159ddd214
cleanup std interface for acram ranges
need to register memory windows to the rram object so that
writes can succeed in a virtual memory environment
2025-10-28 17:58:51 +08:00
bunnie
d10274b9ec
fixup pio->bio typos
also fixup a return-type bug in the std implementation for
bio pin settings

much more bio abstractions will be needed, but for now,
this branch is just focused on the keystore.
2025-10-28 17:57:33 +08:00
bunnie
5f137aac96
add TRNG service for baosec target
dabao has no external TRNG, and so it can "cheat" and use the
server ID api call from the kernel to get random numbers (the
server ID is just TRNG output from the kernel's TRNG).

baosec has an external TRNG, and it needs a userspace
server to blend both kernel TRNG output and this external TRNG.
the TRNG requires the BIO block to aggregate the random data.
This commit adds that implementation.
2025-10-28 17:55:06 +08:00
bunnie
cb6bc4d2c6
add keystore master key derivation
the master key is currently derived from a number of factors:

- the key seed
- chaff keys
- nuisance keys

and then a salt of the uuid/cpid and some info based on the
developer bit is added.

The info addition ensures that the key rotates if developer
mode is entered, so in addition to the key material being
deleted, the info itself is different which should cause
the master key to rotate and "be lost" even if the key
erasure routine is flawed.

Chaff keys harden against side channel analysis of data
in flight from the RRAM array - under the theory that
the RRAM array is a big, long set of wires (on the order
of mm's) that should make a great target for EM microprobes.
The chaff keys are read out in a random order every boot,
to make it harder to accumulate enough samples to average
out what's going on.

The nuisance keys are just read straight out of the array.
They might be recoverable by side channel analysis, but
their purpose is to make it annoying for a brute-force
read-out of the key array by a microscopist. The location
and size of the nuisance keys are picked to force the attacker
to really dial in their polishing process so that they have
to hit the right layer across the entire chip (or at least
a couple mm's); and then a set of bits are packed closely
together to try and induce as much cross talk on the word
lines, running under the theory that any attack relying
on stray electrons activating the bitlines to enable read-out
are likely to non-selectively activate bitlines, so the
resulting "glow" of the word line is going to be a superposition
of several bits at once. An attacker could, of course, cap
each bit line with a FIB, read the word lines, then uncap/recap
them one by one - but this drives up the cost of the attack
and ensures that it's not just a single imaging run but
will take at least hours if not days for a skilled adversary
with the most modern equipment to extract the data. Furthermore,
the large amount of bits demands that the attacker read out
the data with better than 97% accuracy (the last 3% can be
cleaned by the ECC coded into the array), so mistakes
are costly.

The chaff/nuisance keys are read out where the chaff keys
(which are order-independent) are interleaved with the nuisance
key readout. The chaff keys are read roughly twice, using
a continuous-time algorithm to pick which version of the
chaff key is read, making it a bit harder for sidechannel
analysis to pick out which key is in flight.

It's an attempt at sidechannel hardening, we'll see how it
holds up. Pretty sure there's still some low hanging fruit
in the read-out, it'll be interesting to see what the red
team comes up with.

Hopefully this at least makes the keystore not the low hanging
fruit, and we're back at looking at bootloader/kernel exploits etc.
to do key extraction, which I'm sure there are many; but at
least those can be patched.
2025-10-28 17:29:06 +08:00
bunnie
d8aa8cddd7
harden boot0
- setup rram security bits immediately
- setup coreuser mapping immediately
- check boot0 pubkey region against data slots, and note if
issues are found (and erase keys)
2025-10-28 03:39:20 +08:00
bunnie
28e5484c57
expand audit and add boot0 key indelibility test
audit is now expanded to track one way counters and
summarizes security state

boot0 key indelibility test added as a feature, to be
used in the future for CI
2025-10-28 03:37:28 +08:00
bunnie
6e41294854
only clear ACLs that need clearing
also clean up some comments/docs and increase visibility
of the security constant for RRAM so that it can be applied
early in boot
2025-10-28 03:36:12 +08:00
bunnie
290a662bc3
add pubkey block to the data sets, fix nuisance key range
just learned of another ECO incoming that will tie the key
and data areas together in terms of access control from
the IFR region, so the nuisance key range has to have
its access control redefined to steer clear of the data
slots allocated that have write-protects on them.

pubkey block is added to the data ranges

also a oneway counter to keep track of pubkey validation
failures in boot0 is added
2025-10-28 03:33:15 +08:00
bunnie
1549a87772
update blobs
include artifacts that burn pubkeys and write-protects into
the data array
2025-10-28 03:32:12 +08:00
Jeanie
ceab531852 remove item unused by extension 2025-10-27 23:15:20 +09:00
Jeanie
eb34d121ac docs tidying and proper readme 2025-10-27 22:51:57 +09:00
bunnie
fb3c89949c fix boot delay calibrations 2025-10-27 19:07:33 +08:00
bunnie
4486438df3 add loader code that configures the board type for baosec
only when the baosec feature is specified for the loader.

Note: Will blow up if you try to load a baosec image on a dabao board.
2025-10-27 19:06:42 +08:00
bunnie
763c0e8193 make boardtype return the current boardtype when no args given 2025-10-27 19:06:15 +08:00
bunnie
e6bef77b5f
change boot1 default behavior
The motivation for this is to make the tester configuration
exactly identical to that used in production. Right now a
"cheater" step is used to set the board type to dabao and
enable boot waiting because in the test environment there
isn't a physical switch anyone can press to invoke that
behavior.

So, in order to get the test environment to work just like
production, the behavior goes from insta-die if no valid
image is found on the next stage, to "wait for new image".
This is slightly less secure of a default, but only slightly
so. Basically the previous scheme required someone to be
physically present to press the "give me a new image" button,
this one causes the system to automatically accept a new image.
I suppose the main downside is this does allow the possibility
of say, a fully remote, automated exploit to be delivered
if an adversary can damage the loader image such that it
doesn't pass signature check and then it will automatically
go into a mode looking for a new image, at which point
an arbitrary image could be potentially loaded (although
because the image would need to be signed, and there is
a trap that destroys secrets if a developer image is
presented, it wouldn't instantly lead to secret disclosure,
but it would be a denial of service).

The flip side is that with the paranoid default, developers
are "confused" by the silent failure of a brand new chip that
has no code loaded in it (because it goes catatonic until
the developer knows to press the load button).

The loader image is protected from writes after boot, so
in theory there isn't a direct path to "spoil" the loader
image and trigger this path, so it's not like we're just
hanging in the wind. It just means that there isn't a
full human-presence requirement as a defense in depth against
a potential denial of service if an adversary could find
a way to spoil the loader image.

If the DoS path is a concern, one option is to configure
the system such that the developer key is revoked. This
would disallow that from being recognized as a valid
image, and would also prevent the DoS from happening,
as it would require the adversary to present a valid,
signed image which presumably they can't as long as
the signing keys are kept safe.
2025-10-27 18:22:00 +08:00
bunnie
5f7b3d6442
commit more boot blobs
these are burned in at CP and define the accessibility of various
regions in the RRAM
2025-10-27 18:20:58 +08:00
bunnie
ba75cb38d9 add more breadcrumbs to remind myself about tools i made 2025-10-27 17:41:15 +08:00
bunnie
b769e4ada9 don't include any apps by default in dabao image
this allows the environment to specify it fully
2025-10-27 17:32:47 +08:00
bunnie
dcd4e0bb80
Merge pull request #704 from betrusted-io/protected-rram
make USB a default feature in dabao builds
2025-10-27 00:55:12 +08:00
Jeanie
16e23282ec Merge remote-tracking branch 'upstream/main' into tools-bao 2025-10-27 01:05:36 +09:00
bunnie
6a548de693
Merge branch 'main' into vault2 2025-10-27 00:02:26 +08:00
bunnie
1ab4a62a13
Merge pull request #700 from betrusted-io/protected-rram
WIP: protected RRAM APIs
2025-10-27 00:00:45 +08:00
bunnie
012f6f5141 make USB a default feature in dabao builds 2025-10-26 22:56:13 +08:00
bunnie
eb3cdc054d add bytemuck dependencies 2025-10-26 22:23:11 +08:00
bunnie
3a02dc125c add rram debug commands & duart-debug mode for the HAL in std 2025-10-26 22:22:46 +08:00
bunnie
70a0b62014
rram handler for std environment
rram handler for `std` requires the following additional features
over baremetal:

- mapped pages list, because a process has to "own" a page of RRAM
before writing to it. It's anticipated that the rram writer hardware is
"owned" by the keystore, so all write-access will be mediated by a
service in that PID

- irq-context handling of writes. this prevents writes from being
detached from their staging data, or other concurrent writes
from conflicting.
2025-10-26 22:18:23 +08:00
bunnie
fc3da61307 add duart debug support for std environment 2025-10-26 22:17:37 +08:00
bunnie
e91eb176e7 cleanup warning 2025-10-26 19:34:00 +08:00
bunnie
f4fee4488c fix baud rate on console for dabao target
frequency changes means uart nees to be re-initialized
2025-10-26 19:31:36 +08:00
bunnie
775726af23 standardize BAUD_RATE location
also slow down pre-emption timer a bit, on a slower system
like ours 100Hz is less overhead
2025-10-26 19:30:49 +08:00
bunnie
e770249f0a improve error messages 2025-10-26 19:30:34 +08:00
bunnie
2f957d3f35 improve error messages 2025-10-26 19:30:18 +08:00
bunnie
72e8c1a6fa
print errors on slot initialization instead of crashing
these errors mostly trigger when transitioning between
board types during testing
2025-10-26 19:29:11 +08:00
bunnie
df9ae96263 fixup dabao demo apps
- add boot delay on hello world - otherwise you might miss it
because it prints before the console is enumerated

- add preemption to the dabao environment

- improve error handling
2025-10-26 19:27:54 +08:00
bunnie
0ef31b1288
update lockfile with new keystore deps 2025-10-26 13:38:48 +08:00
bunnie
4e522873f0 add preemptionstate opcode to the hal api 2025-10-26 13:38:28 +08:00