Commit graph

268 commits

Author SHA1 Message Date
bunnie
336e47eabe remove comment 2024-04-09 15:46:48 +08:00
bunnie
6735312444 add some more asserts & checks; undo kernel load last patch
kernel load last isn't necessary

add some asserts to help sanity check things. In particular,
the kernel mapped memory can't exceed 0xA000 in length, otherwise
it bumps into hard-coded constants in the kernel for where hardware
mapped pages should go (i.e., panic framebuffer, debug UART, etc.)
2024-04-09 15:30:21 +08:00
bunnie
d367c99a1f fix page mapping; allow kernel to load in arg order; swap_root breakout
Page mapping just can't be done during the phase 1 loading, because
we move the loading point by an unpredictable amount which messes
up phase 2. I mean, we could try to predict the amount, but it's easier
if we just stick with the current algorithm instead of trying to
do both at once. Basically, phase 1 must be "no-alloc" entirely
as it copies.

Phase 2 can allocate page table entries, because all the data
is copied to RAM and you know where that starts; and you can start
to append data to the end of that without affecting the loading
points of programs.

Undo a previous patch to force kernel to load last. Turns out
this is legal, it was only problematic because of other bugs.

Also, reflect swap_root in the BootConfig structure and not
in InitialProcess structure.

+ Various other debug fixes
2024-04-09 15:26:38 +08:00
bunnie
8c82d710bb reflect swap offset patches in atamsam5d27 arch 2024-04-09 15:25:59 +08:00
bunnie
8abb126577 break out swap_root & improve debug 2024-04-09 15:25:37 +08:00
bunnie
a66e4f5901 modify stack smash check to detect if non-PID is written
this is more robust, and should work across all architectures.

Note that the reliability of the check is slightly impacted
since we're now checking for a subset of valid numbers, so
the number of bytes checked is doubled.
2024-04-09 15:24:22 +08:00
bunnie
d6e7f7ce16 add debugging and asserts to detect stack smash in loader
In swap configuration, the loader does a lot more: it has
to decrypt full pages of RAM and hold them temporarily;
up to two pages at once, once for the decrypt of the source
swap image, and one for the encrypt to swap memory.

This causes a lot more stack to be used than the original loader.

Add some debugging for this, and an assert based on a heuristic
that the RPT (runtime page tracker) last few entries ought to
be 0. This I think is probably true on most platforms. If this
fails to be true, then, we can probably modify the assert to
fail if any number in the RPT is greater than the number of
processes: this should be true in *all* cases, but a stack smash
is very likely to write something in there that's larger than
the number of allowable processes in the system.
2024-04-09 15:17:49 +08:00
bunnie
630a81b185 we need more stack to decrypt memory in the loader. 2024-04-09 15:17:21 +08:00
bunnie
30202d962c don't build swap_root into the InitialProcess structure
the kernel doesn't use it, so it just ends up being wasted
space.
2024-04-09 15:16:26 +08:00
bunnie
9992d29b40 chore: cleanup warning in non-swap mode 2024-04-09 00:06:18 +08:00
bunnie
d318134bdc fix default flags for swap; add load checking for swap
load checking is aware of all three types of sections, and
can natively call the encrypt/decrypt ops to ensure that
the encrypted swap is set up correctly.
2024-04-09 00:04:47 +08:00
bunnie
62f1ad09f0 ensure that the kernel is loaded last, even after argument extension
The kernel is supposed to be loaded last, but, when we append
arguments that isn't true anymore. This fix makes sure the
kernel is loaded last.
2024-04-09 00:03:48 +08:00
bunnie
dbacbb609b fix argument appending and mutability issues
The argument appending code in copy_args() is truly abominable.
Suspect more latent bugs in there. Definitely some deep technical
debt in this routine, it's basically just a pile of unsafe pointers
jammed together with no checks. This has to do in part with the
underlying implementation of the argument iterators, which
understandably try to do a lot with no allocations, but it's
brittle and does not play nicely with the idea of extending
the argument records.
2024-04-09 00:01:08 +08:00
bunnie
d6a9c85acb extended debugging; make check_load aware of swap 2024-04-08 23:58:19 +08:00
bunnie
bd58d9187e make secboot's stack test adjust to the platform-defined RAM available 2024-04-08 23:56:35 +08:00
bunnie
8811114a9b remove unused alignment feature
we're not passing pages around like I thought I would. svae
the stack space, so in the future if we do stuff with e.g.
suspend/resume we don't have to reserve such a huge
chunk of RAM for boot.
2024-04-08 23:55:40 +08:00
bunnie
1d0f34779a extend debug to print swap bits 2024-04-08 23:55:24 +08:00
bunnie
03c3f61ba3 fixes to encrypt/decrypt routines to adjust offsets etc. 2024-04-08 23:54:36 +08:00
bunnie
36173fde95 adjust ram available size when swap is enabled 2024-04-08 23:54:24 +08:00
bunnie
58ce8a2923 make resume not a default feature in renode
this is compensated for in xtask to put it back into
your usual builds, but it allows us to not have it in the
swap config.
2024-04-08 23:43:45 +08:00
bunnie
cd140769ac add code to map swap page tables into swapper memory space 2024-04-08 12:41:08 +08:00
bunnie
2b5fabb2fd add swap pt routines 2024-04-08 12:40:42 +08:00
bunnie
25cbf0dc67 add swap pt map handling 2024-04-08 12:40:23 +08:00
bunnie
287ad58c8a add the swapper PID as a constant 2024-04-08 12:39:52 +08:00
bunnie
379d4e81c5 cleanup swap top mod now that most of the implementation is done 2024-04-08 12:39:29 +08:00
bunnie
30b5be7a79 remove superfluous import 2024-04-08 12:39:07 +08:00
bunnie
6ce157b20d add swap handling to minielf 2024-04-08 12:38:42 +08:00
bunnie
63a8b51fe9 gate SDBG behind feature flag 2024-04-08 12:38:02 +08:00
bunnie
2ce579b221 phase 1 changes for swap 2024-04-07 22:37:40 +08:00
bunnie
26efde0a71 track address of the decrypt buffer 2024-04-07 22:36:54 +08:00
bunnie
a478af445d fix IniS arg copying. lay down boilerplate for phase 1 copy
the hard part - the core inner loop of the copy -- is still
to be done.
2024-04-07 19:01:09 +08:00
bunnie
8aa20e65f6 match new API for accessing swap 2024-04-07 19:00:18 +08:00
bunnie
bd54417e44 add routines for shuttling encrypted data to/from swap RAM region
RAM is assumed to be off-chip, and thus the data is encrypted
in the region. We also encrypt it in the Precursor case, even
though it's on-chip, because we want to capture this as a test case
in a known working environment.

Also incorporate some routines to generate the per-boot random
key for swap encryption.
2024-04-07 18:58:54 +08:00
bunnie
c07f33a169 track the current free page in swap ram 2024-04-07 18:58:31 +08:00
bunnie
417fa16a22 add rand_chacha as a dependency for the loader
this is needed in the cramium-soc case because the raw TRNG
does not have a whitener, it should not be used directly to
generate keys.
2024-04-07 18:57:23 +08:00
bunnie
f2a8603e55 merge encrypted swap argument structure into kernel arguments 2024-04-07 14:29:25 +08:00
bunnie
999cb320ed add a function to nab the decrypt buffer
HIGHLY unsafe, but saves us a decryption operation as we
interleave between the various states of the loader.
2024-04-07 14:28:31 +08:00
bunnie
35082c4688 add crc handling to loader
for patching the argument structure
2024-04-07 14:28:05 +08:00
bunnie
c53515fc63 coalesce swap hal into boot config object; read initial swap args
this worked, so it validates the encryption/decryption of the swap
at least!
2024-04-07 00:41:18 +08:00
bunnie
f86d63aa41 add tracking for swap-specific data structures in bootconfig 2024-04-07 00:40:33 +08:00
bunnie
c7e1f22cfa fix pointer issue in resolving swap config
also a bunch of latent debug in case we need to muck around again
2024-04-07 00:39:34 +08:00
bunnie
8f94ecaf6c limit AAD to 64 bytes 2024-04-07 00:39:05 +08:00
bunnie
71336ebf3e start to sketch in bits and pieces of the swap HAL
this is far from complete but needed to check in for the
build check to pass
2024-04-06 23:04:03 +08:00
bunnie
4bb7c87646 gate loader todo behind feature flag 2024-04-06 23:01:33 +08:00
bunnie
903b2219db gate loader features behind flag 2024-04-06 23:01:04 +08:00
bunnie
32857a70b0 add platform-dependent drivers for swap
precursor does direct memory mapping
cramium uses a qspi interface
2024-04-06 22:59:43 +08:00
bunnie
dddbc3c163 add aes-gcm-siv dependency to loader 2024-04-06 22:58:20 +08:00
bunnie
8bae95ef72 put placeholders for inis handling, phase 2 2024-04-06 07:47:18 -07:00
bunnie
c354b75d97 put placeholders to handle inis in phase1 2024-04-06 07:47:18 -07:00
bunnie
c37349778e put todo! placeholders for minielf handling of inis 2024-04-06 07:47:18 -07:00