xous-core/services
bunnie 0b454cb7a8 evict salamanders from AES-GCM-SIV in the PDDB
So you'd like to think that an authenticating cipher would like,
authenticate stuff on decryption. And AES-GCM-SIV was billed as sort
of AES with the pointy edges taken off.

Well, there's always one more bug, actually this time a salamander:
https://eprint.iacr.org/2020/1456.pdf Apparently one can forge
authentication if the attacker can control keys and ciphertext. In the
case of the PDDB I think the attack is largely theoretical, because
you'd have to forge through both the AES-GCM-SIV and the rather
insufficient nonce/murmur hash check on the PTE that locates the page
to be decrypted.

But it's never good to have cryptographic properties depend upon
something that's known to be insufficient, so let's assume the attacker
can simply forge keys and stick some data on the device.

This wouldn't be a problem for confidentiality but it could lead to
the ability to plant evidence, but more importantly could lead to code
paths that were thought to be protected against fuzzing being fuzzed
as you could conceivably create a Basis root record that "checked out"
and then the larger body of the PDDB code would try to chomp on other
pages that are forged, leading to a bigger attack surface. Plus who
knows what else might exist beyond salamanders...

This patch does a "key commitment" on the Basis root page, so that it
is now cryptographically hard to create a salamander.  Basically
instead of using the system root key directly in AES-GCM-SIV, the key
goes through a KDF that expands it with yet another nonce plus a bit
of header data. The KDF is SHA512/256 and it expands it twice,
changing one bit in the header data (as prescribed by the paper cited
above), to create a version of the key that is written to disk (the
commitment), and a version of the key that is used to
decrypt/authenticate the AES-GCM-SIV data. Only if both the commitment
and the authentication check out, do we accept a Basis root page as
valid.

I had some concerns about the slightly different structure of the
Basis Root page being detectable, but I have been assured that the key
commitment form and the MAC in AES-GCM-SIV satisfy a property known as
IND$-CPA ("indistinguishable from uniform randomness by a
chosen-plaintext attacker") by Rogaway[1], and, more strongly, "Secure
nonce misuse-resistant authenticated encryption (mrAE)" by Gueron and
Lindell (see appendix for def)[2]. Still, just out of total paranoia
and nothing else, I organize the basis root page such that the MAC is
in the identical location as the other non-committed pages...just in
case there is some mathematical property of the MAC that could be
leveraged to leak info about the existence of the basis root record.
The commitment nonce and sha512/256 result I understand better and
feel pretty comfortable that they are going to be strongly random and
indistinguishable from AES ciphertext.

Thanks to Michael Rosenberg for taking the time to explain all this to
me and to guide me through the process of making the fixes. It is a
major PDDB API-breaking change and I'm glad it's able to be rolled out
before most users have received a device.

[1] https://web.cs.ucdavis.edu/~rogaway/papers/ad.pdf
[2] https://eprint.iacr.org/2015/102
2022-02-28 03:13:26 +08:00
..
aes clarify the dependency policy 2022-01-10 16:50:10 +08:00
aes-test clarify the dependency policy 2022-01-10 16:50:10 +08:00
benchmark remove dependency on blitstr v1 entirely 2022-01-23 04:08:32 +08:00
benchmark-target clarify the dependency policy 2022-01-10 16:50:10 +08:00
cb-test-c1 clarify the dependency policy 2022-01-10 16:50:10 +08:00
cb-test-c2 clarify the dependency policy 2022-01-10 16:50:10 +08:00
cb-test-srv clarify the dependency policy 2022-01-10 16:50:10 +08:00
codec refactor i2c interface to eliminate static mut unsafes 2022-02-19 00:31:25 +08:00
com trim out some excess redraw calls that are slowing down boot 2022-02-05 18:55:46 +08:00
content-plugin-api clarify the dependency policy 2022-01-10 16:50:10 +08:00
dns add a crappy but slightly more accurate approximation of UDP to hosted mode 2022-02-21 00:54:46 +08:00
doc
engine-25519 TcpListener debugging, just a little bit 2022-02-02 00:23:14 +08:00
engine-sha512 clarify the dependency policy 2022-01-10 16:50:10 +08:00
gam always redraw the full extent of secure modals 2022-02-05 23:20:41 +08:00
graphics-server fix issue #101 based on @xobs changes 2022-02-15 17:36:53 +08:00
ime-frontend trim out some excess redraw calls that are slowing down boot 2022-02-05 18:55:46 +08:00
ime-plugin-api fix up the REFCOUNT on connections 2022-01-31 23:13:10 +08:00
ime-plugin-shell clarify the dependency policy 2022-01-10 16:50:10 +08:00
jtag fix up the REFCOUNT on connections 2022-01-31 23:13:10 +08:00
kernel-test clarify the dependency policy 2022-01-10 16:50:10 +08:00
keyboard use NIST SP800-38F (AES-KWP) to wrap the system key for the PDDB 2022-02-03 18:24:06 +08:00
llio eliminate static mut unsafe pattern in callback function storage 2022-02-19 01:38:20 +08:00
log-server maybe, just maybe...we finally have version info baked into the kernel correctly. 2022-01-31 23:02:32 +08:00
log-test-client clarify the dependency policy 2022-01-10 16:50:10 +08:00
modals add busy-wait queuing for alerts in case multiple alerts pop up 2022-02-05 02:03:56 +08:00
net add a crappy but slightly more accurate approximation of UDP to hosted mode 2022-02-21 00:54:46 +08:00
pddb evict salamanders from AES-GCM-SIV in the PDDB 2022-02-28 03:13:26 +08:00
rkyv-test-client clarify the dependency policy 2022-01-10 16:50:10 +08:00
rkyv-test-server clarify the dependency policy 2022-01-10 16:50:10 +08:00
root-keys add a facility to dump keys for Renode integration (or to steal keys if you can patch the firmware) 2022-02-15 22:24:03 +08:00
shellchat make the UDP socket specifiable on command line 2022-02-21 01:26:04 +08:00
skeleton fix skeleton template 2022-02-27 18:21:11 +08:00
spinor spinor: fix incorrect ecc write into softirq block 2022-02-14 17:32:20 +08:00
status integrate app name in sec notes patch, make app name update retriggered on change 2022-02-24 19:44:24 +08:00
susres fix issue #101 based on @xobs changes 2022-02-15 17:36:53 +08:00
test-stub clarify the dependency policy 2022-01-10 16:50:10 +08:00
test-stub2 clarify the dependency policy 2022-01-10 16:50:10 +08:00
ticktimer-server add a feature to turn off timestamps 2022-02-07 17:38:07 +08:00
trng fix up the REFCOUNT on connections 2022-01-31 23:13:10 +08:00
xous-names fix up the REFCOUNT on connections 2022-01-31 23:13:10 +08:00
README.md Update README.md 2021-05-06 00:44:01 +08:00

Xous Services

services map

Xous is a microkernel OS. The kernel itself is a small program, which runs within just one 4kiB page of RAM. The kernel in and of itself hands out pages from the page table, and routes messages. Everything else is managed by "servers".

Interprocess messages are fast and light-weight in Xous. Scalar messages pass data using registers on the stack, and are the fastest messages. Memory messages work by remapping memory pages between processes. send, lend, and lend_mut of memory pages is supported. send creates a full copy of the page, and is non-blocking; lend remaps the page into the borrowing process with read-only privileges, blocking the lending process until the borrowing process returns the page. lend_mut is like lend but with read/write privileges allowed on the lent memory.

The underlaying hardware is entirely memory-mapped; this includes the notional "disk" which is actually FLASH ROM. Every hardware peripheral has its addresses page-aligned, so that individual peripherals may be "owned" by a given server. The kernel itself "owns" no hardware other than a UART for debugging and a private port into the TRNG.

The kernel starts up a core set of servers, which are broadly divided into three categories:

  • "Well known" servers
  • "HAL" servers
  • "Application" servers

Almost all servers in xous are accessed through a 128-bit, cryptographically random SID. These random IDs change with every boot. Thus, in order to connect to a server, one must first resolve its name into an SID. In order to facilitate this process, three "well known" servers are provided:

  • xous-names
  • ticktimer-server
  • log-server

These three servers can be accessed by any process, regardless of their trust level, as their SID is actually a well-known number. The ticktimer-server is well-known so that servers can delay their boot (if necessary; so far it hasn't been). The log-server is well-known so that errors in connecting to the name server can be debugged.Please refer to the README for xous-names for more details on how name resolution works.

Initially, xous-names functions as a permissive oracle that allows kernel servers to freely look up SIDs using the set of names defined in names.rs. Once the kernel is initialized, a lockdown message is sent to xous-names which prevents any further lookups on servers that are meant to be private to the kernel. (TODO: a coherent, maintainable method for declaring private servers to xous-names)

The distinction between "HAL" servers and "Application" servers is fuzzy; but as a rule of thumb, "HAL" servers are private to the kernel and strive for minimal complexity and maximal clarity in their writing. "Application" servers remain discoverable by user applications after the lockdown event, and are responsible for gate-keeping and vetting requests to the HAL layer.

An example of this is the graphics-server and the gam.

The graphics-server is a HAL; any process that can talk to it is capable of drawing pixels on the screen at any location. The graphics-server implements drawing primitives like Rectangle, Line, Circle, and TextView, as message-passing at the pixel level would not be performant. User processes should not be allowed to talk to it, because it would allow user processes to create a fake UI and thus could fool users into typing passwords into fake dialog boxes.

The gam is a Graphical Abstraction Manager. It manages various Canvas objects that have trust levels associated with them. Primitives such as TextView are bound to Canvas objects, and the gam will handle vetting if the objects are allowed to be drawn, clipping, and so forth. Note that the Xous philosophy is that applications do not get to control the exact look-and-feel of their UI; this is to prevent less trusted applications from masquerading as trusted applications, but also assists with things like accessibility and internationalization. For example, applications cannot pick their font; they can only request a style class such as "small", "regular", and "bold". Thus application developers should think of rendering their UI more as hints and directives to the gam, and less as direct pixel pushing.

Conceptually, a complete Xous OS implementation would have HALs that claim the pages of every hardware device, and application servers that claim all the other remaining memory pages -- this includes unused pages and aliased regions -- except for the free memory reserved for applications themselves. Thus, Xous as a kernel does nothing to prevent anyone on its own right from mapping a page; it's up to the complete set of services frameworks to ensure that all the requisite pages have been mapped. (TODO: an audit tool to check the memory space and verify that 1. all CSRs and memory spaces explicitly declared in soc.svd are mapped, and 2. checks that otherwise remaining free space is mapped to a "gutter" that panics if accessed).

We're trying to track progress on implementing the various servers using github projects.

Server Limit

Xous is currently limited to 128 servers. Each potential server reserves 40 bytes of space in the kernel. Xous 0.8 carries about 30 servers, so 128 servers should be reasonably future-proof. Adjusting the limit requires making a change in two places (note the permalink is to an older version of Xous):

  1. 68aff967e8/kernel/src/services.rs (L19)
  2. 68aff967e8/kernel/src/services.rs (L235)

Process count is adjusted by altering https://github.com/betrusted-io/xous-core/blob/master/kernel/src/arch/riscv/process.rs#L15. Xous 0.8 carries about 10 processes, and the current limit is 63. Each additional process reserves about 16 or so additional bytes for tracking information.

Well-Known Servers

Here is the list of well-known services:

  • ticktimer-server -- allows processes to know elapsed time since start, and request sleeps. Also manages WDT.
  • xous-names -- resolves names into SIDs.
  • log-server -- implements info and error logging. Has a separate UART from the kernel UART.

Hal Servers

Here are a list of HALs, implemented and projected, and their functions:

  • com -- manages requests to and from the EC
  • graphics-server -- manages the frame buffer and basic drawing primitives. Talks to the MEMLCD
  • keyboard -- key matrix management; debounce; ScanCode conversion. Keyboard layouts (qwerty, dvorak, azerty, qwertz, braille) are interpreted in this server
  • trng -- manages the TRNG hardware, provides TRNGs for other processes
  • llio -- manages I2C, RTC, GPIO, pin interrupts, soft reboot, and power pins. Also home for info, build IDs, etc.
  • codec -- basic buffering of frames into and out of the audio CODEC
  • jtag -- manages the JTAG interface (used for key fusing)
  • keys -- management of cryptographic key store
  • engine25519 -- Engine25519 interface
  • sha512 -- SHA512 interface
  • spinor -- manages the erasure and programming of the SPINOR
  • ram -- manages allocation of RAM for applications
  • scheduler -- manages thread scheduling and priorities

Application Servers

Here are a list of application servers, implemented and projected, and their functions:

  • fcc-agent -- use-once -- a special agent meant to run on a minimal Xous for FCC testing. Should never be compiled into production firmware.
  • trng-tester -- use-once -- a special server used to facilitate testing of the TRNG. Pipes TRNG output to memory regions that can be read out using bt-rngd and fed into Dieharder for analysis.
  • gam -- pre-alpha -- manages Canvas objects, and provides an abstract framework for applications. Also manages status bar, context menus and pop-up notifications.
  • ime -- liases with keyboard and gam to handle keyboard input
  • pddb -- plausibly deniable database. Used in lieu of a conventional filesystem for storing key/value pairs in a plausibly deniable fashion.
  • update-ec -- manages the updating of the EC
  • update-soc -- manages remote (non-USB) updates of the FPGA and kernel
  • net -- manages connections to the Internet
  • wifi -- manages wifi configuration
  • power -- intermediates requests to the backlight, battery status, charging, RTC, etc.
  • accel -- intermedates requests to the accelerometer
  • audio -- intermediates requests to the audio hardware. Does stream mixing, etc.
  • usb -- handles USB connections
  • credentials -- trusted PIN/password entry mechanism, manages currently activated credentials

Applications

Here are a list of user applications:

  • shell -- refactoring -- provides a "chat-like" interface for talking to Xous
  • chat -- text and audio secure chat app
  • launcher -- an application launcher
  • password -- a password vault