Commit graph

9846 commits

Author SHA1 Message Date
Sylvain Bellemare
0959ea80db
Improve security of dockerfiles
* Verify checksum of downloaded rust target riscv32imac-unknown-xous_*.zip
* Pin base image to a sha256 digest
* Quote build arg to prevent shell injection attacks
* Run cargo --locked to make sure builds follow Cargo.lock
* Use --proto '=https' for curl to only allow HTTPS protocol to prevent downgrade attacks
* Create non-root user to run cargo commands and build artifacts
2026-01-16 16:41:43 +09:00
bunnie
a16c176bab
Merge pull request #781 from betrusted-io/production-keys
Transition to production settings
2026-01-16 03:59:08 +08:00
bunnie
341c2353ab add audit of boot mode to audit and security assessment
Turns out we *can* check this at run-time. I thought originally
once the chip was sealed these became hidden. I was wrong.
So, this means we can actually test to confirm that production
was done correctly and in fact the CM7 and debug ports are sealed
off.

this adds that test.
2026-01-16 00:52:01 +08:00
bunnie
6eda3925ae update fuse blocks 2026-01-16 00:51:18 +08:00
bunnie
b06c124b3e
add a routine to print the info region
The info region is a region of RRAM that is used to configure
the chip - boot security, what CPUs can run, access control
lists, etc. There's no secrets in here, but it's very helpful
to inspect for audits and correctness of configuration, so
a routine is added to print it in boot1.
2026-01-15 17:04:11 +08:00
bunnie
86f0b18fdc
add the actual raw signing key handles to the repo
note that the "sk" is just a handle that points to the residential
key on an HSM, so the "private key" contains nothing of
cryptographic interest.
2026-01-15 17:03:06 +08:00
bunnie
aab774368b
version bump on fido signer tool 2026-01-15 17:02:34 +08:00
bunnie
bf721e3b5c
adjust permissions on serial number; make chip init more permissive
It is not clear if I can get the factory to burn the serial number
(wafer lot, ID, x/y location) into the location I want it to be.
So, I am allowing this to be updated by the firmware on boot,
thus necessitating the permissions to be writeable for the serial
number field.

Furthermore, if there is any error in initializing the chip's
identity in the factory, right now the chip goes into a mode
where it has crashed and can't run diagnostic code. Write errors
in this stage are thus turned into .ok() instead of .unwrap()
because we want to allow the chip to go through the whole flow
and then diagnose any issues later on.
2026-01-15 16:58:22 +08:00
bunnie
a5a6cc8e48
Fix comments in production key 2 slot 2026-01-15 16:57:27 +08:00
bunnie
3e5b62aab3
Add production public key to the first key slot 2026-01-15 16:56:43 +08:00
bunnie
f6a2568c1c
Merge pull request #776 from sbellem/docker-ci
Docker ci
2026-01-15 14:58:08 +08:00
Sylvain Bellemare
f5bd5e2982
Add ci to build dabao firmware with docker 2026-01-14 15:03:03 +07:00
bunnie
32c5d492cd
Merge pull request #773 from sbellem/docker
Add Dockerfiles to build dabao apps & bao1x boot1
2026-01-14 14:36:22 +08:00
Sylvain Bellemare
bf61d2512c
Add Dockerfiles to build dabao apps & bao1x boot1 2026-01-14 03:13:13 +07:00
bunnie
47f529f2d2
Merge pull request #774 from betrusted-io/gdb-misc
GDB over serial and misc improvements
2026-01-14 03:54:42 +08:00
bunnie
893c71c023 track new dependencies for kernel 2026-01-14 03:25:50 +08:00
bunnie
29d25c13a1 refactor UDMA UART to use "poll" mode to receive data
The prior implementation tried to use the UDMA streaming mode
to get Rx data out of the UART.

The problem is that with streaming mode, it's hard to tell how much
data is actually available. This is because the thing that sets up
the stream sets "some number of bytes" as the fetch depth of the
DMA Rx, but all you can read is "number of bytes remaining" out
of the DMA interface.

So when 0 bytes are remaining, you can fetch some data, but you don't
know *how much* to fetch. And if someone else fetched partial data
before you, you don't know how much partial data was fetched. This
could be resolved with some gnarly, highly concurrent state that
gets incremented on every fetch.

Or, we could use poll mode. There's a reason i think it's in the
block, because the Rx DMA mode is more or less not usable. Poll
mode you read a config register, see if there's valid data, and if
so, when you read the data register, it's pulled out of a FIFO.
The FIFO is in hardware and it's 4-deep. As long as you don't
need more than a depth of 4, you're rock solid.

This is a lot easier than the UDMA Rx mode, so I've just gone ahead
and deprecated the Rx mode. I could only ever get the Rx mode
to work to receive a single character *anyways*, so despite its
potential to receive thousands of bytes without CPU intervention,
it was only ever used as a 1-deep buffer because of the inability
to know exactly how much was in the buffer. Thus, the poll mode
is actually an improvement over the DMA mode, in practice.

More importantly, it means the Rx link is much more stable in
GDB kernel mode, if the baud rate is cranked down to 115200 (at
1M baud, the kernel still can't respond quite fast enough to
reliably drain it).
2026-01-14 03:21:06 +08:00
bunnie
24105e7b22 add the default perclk speed as a public constant
instead of just hard-coding it in the clock setting routine
2026-01-14 03:20:27 +08:00
bunnie
e76e5a87ff add bao1x-api dependency to kernel in gdb-stub
this is necessary to re-init the UART speed as that crate contains
the default perclk speed.
2026-01-14 03:19:35 +08:00
bunnie
541fecead2 add probably flawed implementation of poke_memory
this is a first take at the poke_memory primitive, which is necessary
for GDB to patch in debug breakpoints.

I think the memory patching is *working*, but...stuff like single
stepping is still not working. This might be just me using GDB
wrong, tho. Need someone who actually uses GDB/is more familiar
with it to poke around a bit more.
2026-01-14 03:18:19 +08:00
bunnie
7940529d0b integrate gdb initializations into the kernel 2026-01-14 03:16:32 +08:00
bunnie
d39087b2e9 cleanup warnings in gdb debug and cleanup debug shell for bao1x
bao1x debug shell has no input, so removing the help functions
will save space in the kernel
2026-01-14 03:15:26 +08:00
bunnie
d380ea1ab6 add gdbuart implementation for bao1x 2026-01-14 03:14:13 +08:00
bunnie
533607b9ec gdb-stub: disable userspace console
The serial port going to the userspace console is disabled to allow
for gdb access to the kernel.
2026-01-14 03:13:39 +08:00
bunnie
284e639453 adjust xtask default features
- dabao now includes debug-proc by default
- gdb-stub now passes to both kernel and user programs, so that
uart switching can be achieved
- print-panics activated in the kernel, so we can see the panic
messages. They had disappeared for a while, and didn't notice.
2026-01-14 03:10:17 +08:00
bunnie
86ab6b02c9 add proc info commands to dabao target 2026-01-14 03:09:40 +08:00
bunnie
7b697c0918 add note to serial console that console has moved to USB
this makes it clear that when USB is plugged in, the console
session on the hard serial port migrates to the USB serial port.
2026-01-14 03:08:41 +08:00
bunnie
d1d0998800 link to pre-built tested CI artifacts 2026-01-11 21:22:52 +08:00
bunnie
944a8082ec
Merge pull request #772 from betrusted-io/tech-debt
Tech debt payback - swap bug, error codes & kernel analytics
2026-01-07 20:22:35 +01:00
bunnie
8fcb70118a update verifier pins 2026-01-08 03:11:45 +08:00
bunnie
5b01c1e7b8 reset pins and patch dependencies 2026-01-08 03:11:25 +08:00
bunnie
fba011db3a commit version bump so that we may publish our packages 2026-01-08 03:04:19 +08:00
bunnie
3283142664 update lockfile 2026-01-08 03:02:53 +08:00
bunnie
42e96d723a hook the debug info output in the "test" command
this command and its dependencies will probably be stripped out
or modified for production, so i think this is a good place to hang
these.
2026-01-08 03:02:04 +08:00
bunnie
c23bed360f implement extraction of kernel analytics
this is gated behind the feature "debug-proc" because this could
leak attacker-useful information, and also it adds a primitive that
causes the kernel to write the debug information into any page
that the userspace already has access to. There are some checks
to ensure that the page is actually in RAM (so you can't use this
to trigger weird peripheral states, etc.) so hypothetically this
should just cause corruption in the userspace process if it is
abused, but still - more attack surface, more problems.

however, the feature is useful enough and the risk is small enough
that I think I'm going to leave it enabled for the foreseeable future.
It's definitely helpful to be able to see how much free memory
you have, and other resource allocation trackers like connection
limits and interrupt handler allocations.
2026-01-08 02:56:33 +08:00
bunnie
5be0ddbd0f add PlatformSpecific syscall & cleanup warnings
a number of warnings cropped up in the latest Rust, which
have been cleaned up.

In addition, a definition for a PlatformSpecific syscall has been
added. This is a catch-all for meta-calls that can be experimented
with on a specific platform without having to update the xous API.

Xous API updates necessitate about a hundred files to get their versions
bumped to absorb the new API, and so this is considered to be
a fairly major task.
2026-01-08 02:40:13 +08:00
bunnie
c7d8b88456 strip out debug shell commands from the kernel in bao1x targets
debug shell is actually not reachable in bao1x targets because
the DUART is Tx-only. thus this code is just dead weight in the
kernel for bao1x platforms.
2026-01-08 02:24:03 +08:00
bunnie
d623dc723e tech debt: add more error codes
since the swap update is going to require republishing the
Xous-rs crate, I'm adding a bunch of more descriptive error codes
that I wish Xous could have, and documented the cases in which
they would be used.

This makes it a bit easier to propagate errors up the stack on
more of the calls, at the expense of a more complicated error
type.
2026-01-08 02:22:23 +08:00
bunnie
e27b30d818 fix edge case in swapper
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.
2026-01-08 02:08:03 +08:00
bunnie
f879068bbb cleanup retired apis and improve swap debug output 2026-01-08 02:05:01 +08:00
bunnie
65e56b6586 add note about fetching tags to the page readme 2026-01-08 02:03:58 +08:00
bunnie
9e25c6110e add swap test servers to workspace 2026-01-08 02:03:28 +08:00
bunnie
415fa27758 add a pair of swap test servers
these do nothing but allocate a bunch of memory and revisit the
allocated memory, to exercise swapping.
2026-01-08 02:02:23 +08:00
bunnie
aad14c2cca
Merge pull request #771 from betrusted-io/fix-avtrng
Fix avtrng
2026-01-06 08:50:21 +01:00
bunnie
f387e06b15 fix help messages in demo commands 2026-01-06 15:44:17 +08:00
bunnie
079ec33134 improve formatting & timing slightly 2026-01-06 15:43:50 +08:00
bunnie
d1a3eb4b58 handle clock counter rollover case & fix bug in assembly register naming
t3 doesn't actually exist
2026-01-06 15:40:14 +08:00
bunnie
161b36e88f fix avtrng test/characterization routine 2026-01-06 14:45:39 +08:00
bunnie
c5cc39d142
Merge pull request #770 from betrusted-io/bio-demos
Various minor updates & fixes
2026-01-06 06:50:00 +01:00
bunnie
6396d75c30 fix missed API migration in baremetal 2026-01-06 13:42:10 +08:00