the reason we do this is that if we don't switch off library
modules, they are compiled in and just become dead code in the
OS image. with enough modules, this will eventually become
a significant drag on binary size.
This macro introduces page-level padding around the BIO code
regions, so that the rust assembler/linker computes relative
offsets correctly. This is necessary for code that is
autogenerated from C that uses `statics`
It's not recommended to be used *everywhere* because even
tiny BIO snippets of a few bytes would be blow up to 4k each.
erratum_check.py will automatically scan bio_code! segments
in a .rs file, flag patterns that could be a problem, and
can automatically patch these, if requested.
Getting compiled code going has revealed a couple of frankly
embarassing erratum in the BIO. Kind of shameful to make such
a n00b mistake but I guess my sole defense is I had to put it
together in a hurry with little resources.
Here's the bugs:
BUG 1 ("phantom rs1"): For lui/auipc/jal, the 5-bit field at
instruction bits [19:15] is not gated off. If that field decodes
to register 16-19 (x16-x19) for just these instruction types,
a spurious pending read is made from the corresponding FIFO,
which affects correctnes and can block execution.
BUG 2 ("phantom rs2"): For non-R/S/B-type instructions, the 5-bit
field at instruction bits [24:20] should be gated off but isn't.
When that field equals 20 (0b10100), a spurious `quantum` signal
triggers, which can affect the instruction fetch pipeline
This script inspects the output of the Clang assembly, and in the
process of translating it to Rust assembly, transparently patches
almost all of the cases with work-arounds. The assumptions and
exceptions for the work-arounds are:
- The stack pointer is initialized and valid. This is always
true for Clang-derived scripts because it's in the _start()
routine
- No interrupts that can mutate stack: true because interrupts aren't
supported in this implementation.
There is one edge case that isn't covered: J-type instructions
aren't patchable at this stage because the label offsets haven't
been resolved into instructions. However, "naked" jal instructions
are rare in compiled code - it's always jalr, which is an I-type
instruction. This is noted as a warning when the script runs, and
is fixable by simply inserting a "nop" after the jal instruction
if the target is at the wrong address - this will shift the immediate
so that it no longer contains the 0x14 (decimal 20) pattern in
the immediate field.
An abomination: a zig-based C toolchain, installed via python,
compiles to clang assembly, translated by python script, into
Rust assembly. Then compiled and linked into your app.
Really tempting fate with this one...will I come back to this
commit in a couple years and be filled with regret?
Already, I have some misgivings - the zig toolchain is
definitely not stable, and has been through some API changes,
and doesn't run on all platforms. But - I forge ahead.
- include the toolchain hash for reproduction iff it is
specified
- for the code hash, report *only* the code region, none of
the signature headers. This should match exactly what is
reported by the *_presign.img artifacts.
the sealed data records are laid out with some extra space
at the end for future expansion.
The first such expansion added is a toolchain hash, which allows
us to note which toolchain is required to reproduce the current
image.
The change is backward compatible so the version field of
the record is *not* incremented.
in order to prevent the recursive introspection issue, the
code image is built from a reproducible toolchain from
a given commit on xous-core. However, in order for us to
record *which* toolchain was used, it's impossible to do
this without modifying the commit hash of the toolchain -
thus making it impossible to know what toolchain was actually
used to build the reproducible code.
The fix to this is to out-of-band, at the final signature time,
patch over a field in the signature header expressly laid out
to accommodate the hash.
- add a function we can re-use to check if a file needs updating
- change the wording of the baobit commit when it's not specified
to "unspecified" vs. "unknown"
Adds BAOBIT_COMMIT constant to boot0/boot1 version.rs, allowing
the Guix build channel commit to be embedded in firmware for
reproducibility verification.
- Add --baobit-commit CLI flag to xtask
- Generate BAOBIT_COMMIT in boot version files
- Display in audit command output
- Simplify versioning.rs to always write files
- improve bollards to include "die" jumps where appropriate
- cleanup warnings in unsafe-dev feature
- panic handler calls die repeatedly
- upgrade jump api
the original stub for illegal instruction handling advances
the program counter - this was copypasta from the kernel
irq routine, where this behavior is needed to handle syscalls.
However, this behavior is contra-indicated for the purpose
of dying on a bollard - you don't want to skip past the
bollard for any reason.
- xor-masking of jump target moved to immediately before the jump
- mscratch csr zeroed
- anti-rollback single-update distance limited to 512: let's hope we
never even get close to having 512 security revisions in a single
generation!
- sanity check untrusted signature/add length fields - constrains
hash-checks to within the right "range", preventing abuse of the
hash reads as an oracle to leak state about other things in memory.
- check valid_key != valid_key2 invariant before returning
somehow some formatting regressions snuck in despite previously
being CI-clean on formatting.
I suspect this might have to do with the Rust 1.93.1 bump
that happened just recently, sometimes new versions of Rust
introduce small formatting changes.
the macro will give relevant positional information when the
assert fails, whereas the function always fails in the same place
and we lose that valuable debugging info
The USB engine passes raw pointers around for DMA purposes;
most importantly, it passes *back* raw pointers and lengths.
There's no really good way to check these, and I suspect that
there may be USB protocol exploits that can be used to manipulate
these values. Thus, an assert is added on the touch points where
the raw pointers go to and from the USB hardware to check that,
at the very least, the entire buffer being referenced is strictly
within the USB hardware's memory space.