Commit graph

636 commits

Author SHA1 Message Date
bunnie
3466115cce
harden loader/kernel/app/swap checks
At this point, some of the keys are partially locked out
which makes reacting to an attack slightly less effective
(keys are now locked into a particular process space configuration
which is not available in the loader's default config).

The reaction at this point sums up to seeing if the image is
a developer image, and if so, ensuring that the developer mode
bit is set (which would indicate that the keys have been
erased). I suppose an attacker could get around this by glitching
to some code that sets developer mode without also erasing
the keys. This weakness needs to be explored and hardened against.
2025-12-05 23:17:11 +08:00
bunnie
3293578d3e add second pll check in loader 2025-12-04 16:14:59 +08:00
bunnie
3f7dce3052
loader hardening
The loader is only lightly hardened at this point. Some minmal
random delay + bollards inserted. The signature check routine
inherits all the hardening of boot0 because it uses the same
code. PLL mode is checked at least once.

more loader hardening will happen in a future PR - at the
moment, we're focused on boot0/boot1 hardening.
2025-12-04 15:38:57 +08:00
bunnie
9b54fdb64f fix dabao target dependencies 2025-12-02 02:27:01 +08:00
bunnie
52215251a4 add a random seed to the environment
this is randomly genverated on boot and inserted into the
environment. it is unique per-PID.

This is useful for seeding psuedorandom number generators,
especially in environments where syscalls are not possible.
2025-12-02 01:40:49 +08:00
bunnie
cd8a312b8d switch on the xtal32 source for the rtc in baosec mode, in the loader 2025-11-24 18:27:04 +08:00
bunnie
3893bc78a7 add more annotations & set bootwait on setting board type
bootwait allows automation to load the swap image after the
board type is set correctly

breaks the paradox that you can't init swap on a blank chip
because it doesn't know it has swap
2025-11-19 14:00:08 +08:00
bunnie
b587f63279 emit CI diagnostic on kernel sigfail 2025-11-19 13:54:53 +08:00
bunnie
a208d59690
deny boot to any developer-key signed kernel/detached-app/swap images
Secret keys can't be erased after boot1 exits because the protection
bits are hardened from modification after that point.

thus it is not possible for the loader to switch the device
into developer mode.

Thus the only way to enter developer mode is through a dev-mode
signed loader. A system that has never been put into developer
mode will refuse to run any developer-mode xous kernel, app, swap
images.

Once a system has been exposed to a dev-mode signed loader,
the boot1 will flip the developer mode bit and erase the secret
keys.

Later on, if a production loader is replaced, it doesn't matter
that a production loader is loading dev-mode signed successors
because the secret keys are already erased.

Note that in all cases, the key revocations take precedence
so if the developer key is revoked, these cases should never
even be encountered.
2025-11-18 23:33:33 +08:00
bunnie
4477af6058 fix broken font rendering in rust 1.91
Rust 1.91 (or perhaps, more accurately llvm?) changed how link
ordering works.

Previously, modules would be linked in the order they were referenced
(e.g. pub mod b; pub mod a; would result in b being at a lower address
than a in the resulting binary).

However, apparently, this has changed and now someone in their
infinite wisdom decided that modules should be alphabetized before
linking.

I'm really not sure why the arbitrary ordering of the human alphabet
is superior to any other system, and also, if you really wanted
things alphabetized, you could just alphabetize them in your
reference order.

Previously the fonts were laid out in a way that tried to minimize
cache thrashing by co-locating certain sets of fonts together.

Now they are just sprayed around through the arbitrary and not
terribly useful permutation funtion of the english alphabet.

Rant off.

This changes the specification of the fonts in the code generator
to be in alphabetical order, making the screen once again legible.
2025-11-18 00:18:55 +08:00
bunnie
5e805196e6 fix typo 2025-11-14 19:14:25 +08:00
bunnie
d754b86769 fix susres on precursor
heap can't be initialized before suspend/resume is checked

bao1x doesn't have suspend/resume, and requires heap early
on to check signatures

so heap initializationg is now optionally included in two
locations to meet the conflicting requirements per platform.
2025-11-07 08:01:31 +08:00
bunnie
5981d7afe4 make heap a standard feature available in precursor
this makes the env building uniform across platforms
2025-11-07 00:37:36 +08:00
bunnie
8402c601d2 refactor loader to use new env and pass serial #'s to bao-1x envs 2025-11-06 14:02:02 +08:00
bunnie
01efeb49cb refactor env parsing
make it extensible so that more env vars can be added easily
2025-11-06 13:55:21 +08:00
bunnie
2f0895b46c Merge branch 'main' of github.com:betrusted-io/xous-core into keystore-dabao 2025-11-02 08:02:17 +08:00
bunnie
d901c61846 modify boot sequence to generate keys for a dabao environment
also update the audit to check the respective flags
2025-11-01 23:56:47 +08:00
bunnie
406e39a0d5 fix timebase of delays in loader
should be tied to the system clock frequency
2025-11-01 20:09:12 +08:00
bunnie
e82b5e5a7f
cleanup after previous commit
now that the ensure QE command is part of the discovery API,
there's no longer a need to call it
2025-10-30 14:56:57 +08:00
bunnie
3f46e8443c improve spi device detection code 2025-10-30 04:14:28 +08:00
bunnie
0e50a2591f ensure that boot wait is asserted exactly once in the device lifecycle 2025-10-29 03:43:17 +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
79eab7da5e add feedback on boardtype resetting 2025-10-28 18:02:11 +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
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
e9bf366d3d update freq v voltage setting code in loader 2025-10-25 22:22:40 +08:00
bunnie
66131a59bf add speed-up setting for dabao
the boot1 loader on alpha0 release is conservative
2025-10-25 22:12:42 +08:00
bunnie
569e9526eb fix comment 2025-10-25 01:31:48 +08:00
bunnie
4a12668751 only check the flash ID after going to QPI mode
handles more cases of flash mode switching
2025-10-25 01:31:20 +08:00
bunnie
dab13d5b70 turn on the AV generator in loader
the kernel should rely on the AV generator for random numbers,
and so it should be on and operational by the time the kernel
boots
2025-10-24 21:12:31 +08:00
bunnie
9c9c6f67a7 fixup tag return API
returns a [u8;4] instead of a u32
2025-10-06 15:20:56 +08:00
bunnie
3c68eea714
Merge branch 'main' into signing 2025-10-06 13:45:29 +08:00
bunnie
dbb0a75118 bump versions
have to absorb a version change due to xous-semver change

might as well also update the utra/svd generator dependencies
since that's been held off for a long time now.
2025-10-06 13:23:18 +08:00
bunnie
6d4f8004d3 fix breakage associated with changes to xous-semver 2025-10-06 13:17:21 +08:00
bunnie
3c341d0f8e handle return codes that include tags 2025-10-06 03:49:55 +08:00
bunnie
b665e799ee add detached-app handling
"detached-apps" are Xous applications loaded into a region
of memory-mapped FLASH (and thus memory-mapped applications)
that are separate from the main xous.img image.

This allows developers to work on "just their app" instead
of having to upload the whole Xous ball.

Currently the only configuration that supports this is the
dabao configuration.
2025-10-05 17:08:42 +08:00
bunnie
ee1f3f3cb7 add detached-app handling in argument copy
also add some extra debugging to argument extensions.
2025-10-05 17:08:09 +08:00
bunnie
ac7a1b86e0 fixup bugs in arg extension processing.
Turns out we 'just got lucky' with our previous success
in getting arg extension to work (scary!!): the arg format
is pretty uhh...flexible...in terms of what it will accept
for arguments.

This fixes those bugs, the arg copy looks clean now, and
also removed the over-allocation problem by descending
the new argument list twice, once to sum the space needed,
and once to actually do the copy.
2025-10-05 17:06:33 +08:00
bunnie
0f98c3bea1 implement signature checking on the off-chip swap image
Swap can be "secured" in two ways:

1) it can be re-encrypted to a secure, locally generated key

2) it can be signature-checked with a public key.

(2) is provided as a path to receive updates. Updates are distributed
as "encrypted" (with the "0" key), but signed with a public key.
Once the update is validated, it's meant to be re-encrypted
with a per-device unique key.

A big reason for the re-encryption is because the swap is already
encrypted, we can rely on the AEAD for validation, and skip the
signature check (saves time on boot). Recall that the reason
we don't just do a sig-check and run is that is a TOCTOU:
it's pretty trivial to execute a mux that swaps out the FLASH
memory after the signature check with another version that has
malicious stuff in it. So we go with a sector-by-sector
AEAD that's ideally encrypted to a locally generated key.

It also offers the possibility to prevent malleability of the
swap data between devices, as many public-key signed images
could be floating around, including old versions that include
insecurities (e.g. prevents downgrade attack by replacing
an up to date image with an older signed image with an insecurity).

However, this latter possibility requires the user interface
to be correctly setup to prevent malleability by asking users
to opt-in to partition re-encryption. Need to consider this user
experience flow - kicking the can down the line, but that time
is coming soon.
2025-10-04 18:55:36 +08:00
bunnie
7ff1e438ff make decrypt_page_at fallible
previously we just panic'd (which is actually the right behavior
for this type of error) but because we now have a reason for it
to fail (e.g. testing the encryption key) we make this fallible.

in all other places we just unwrap() - there is no fallback if
decryption fails, boot should just halt.

but this allows us to check which decryption key is deployed
in phase 1.
2025-10-04 18:54:15 +08:00
bunnie
9b11361256 fixup loader heap; move signature validation; fixup swap structures
- loader heap is now fixed in a "throw-away" region of memory.
this means the heap should only be used sparingly, and somewhat
dangerously, because the values can't persist beyond the lifetime
of the loader.

- signature validation moved earlier

- fixup swap structures to refer to the API so that image creation
is easier/consistent
2025-10-04 00:56:18 +08:00
bunnie
86f0c60d95 refactor argument merging
the original rather unsafe version is replaced with a more readable
version that has a number of safety checks applied.

in the process of doing this, we now support merging of multiple
argument regions and a variable number of tags to merge.

tested to work on at least the base case of one swap region to
merge into the list.
2025-10-02 16:35:16 +08:00
bunnie
e1537328fa light refactoring of kernel arguments structure
this is a fairly complicated bit of legacy code that we're
trying to make slightly better/more readable.

some docs are added, as well as getting rid of a bunch of
"magic" constants, instead preferring to map things into
structured data where possible.

also fixed the location of the heap allocation relative to
the boot flow. It's now in a spot where I think we can
safely put dynamically allocated kernel arguments.
2025-10-02 02:17:45 +08:00
bunnie
76e22e3d0a cleanup warnings 2025-10-01 23:58:49 +08:00
bunnie
a1c1c85a5f add signature check to kernel 2025-10-01 23:53:44 +08:00
bunnie
9d2311f9ce add remaining pin setups in the loader
this simplifies the kernel's boot job a little bit by
having all the I/O resources set up by the loader.
2025-10-01 23:39:43 +08:00
bunnie
634ccd6c38 add adjustable signature block offsets based on the target
bao1x has a smaller, more efficient signature block that
folds more data into the signed region.
2025-10-01 23:38:48 +08:00
bunnie
4c84fc523d remove deprecated testing feature 2025-10-01 23:38:28 +08:00
bunnie
0437a1263b remove deprecated loader features 2025-10-01 23:38:05 +08:00