Code: https://github.com/rogemega/mini-ecu Codelab (step-by-step tutorial): https://github.com/rogemega/mini-ecu/blob/main/docs/codelab.md Video: https://youtu.be/x3yPOG4rW8Y

Inspiration

Automotive software runs on QNX because of a few properties that are easy to state and hard to see: synchronous message passing, priority inheritance, resource managers, fault recovery, and — since QNX 8.0 — security policies. I wanted a sample small enough to read in an evening that lets you watch each of them happen, on a laptop, without a board.

What it does

Five small C programs boot on QNX SDP 8.0 inside QEMU:

  • vehicled — a resource manager that owns the vehicle state at /dev/vehicle/speed. cat it, or send typed devctl() commands. A 50 Hz timer pulse drives a toy vehicle model.
  • brakectl — a priority-40 control loop that asks for the speed every 10 ms, brakes above 80 km/h and measures the latency of every request.
  • hog — a priority-20 CPU load on the same core.
  • ecuwatch — a watchdog that starts the others, receives heartbeat pulses, and restarts processes that crash or hang.
  • vctl — a command-line client.

Two experiments are built in:

  1. Priority inheritance. With hog running, the brake controller's worst request latency is 0.7 ms. Start the server with _NTO_CHF_FIXED_PRIORITY (inheritance off) and it becomes 201 ms, and the car overshoots the speed limit. Same code, one channel flag.
  2. Security policy. Every process runs with its own type. Even as root, an intruder_t process can read the speed but cannot brake, cannot move the throttle, and cannot register a fake /dev/vehicle/speed; the operator tool may only move the throttle. The brake/throttle rules are custom permissions (class vehicle { brake throttle }) that vehicled checks per request with secpol_check_permission().

How I built it

  • C with qcc from QNX SDP 8.0 (free non-commercial license), x86_64 for QEMU (also builds for aarch64le).
  • mkqnximage builds the images; a small script adds the programs and boots QEMU with user-mode networking, so no bridge or sudo is needed.
  • The system part of the policy was recorded with secpolgenerate on a --secpol=open image, then combined with a short hand-written policy for the sample and compiled with secpolcompile into a --secpol=secure image.
  • Every number in the README and the video comes from running it in QEMU.

Challenges

  • Getting a security policy that boots: the recorded rules referenced an undeclared default type, policy statements are order-sensitive, and the default recording configuration marks the console as unrestricted, so nothing the shell does is recorded. The codelab lists each pitfall and the fix.
  • Making priority inversion visible: all processes are pinned to one CPU with ThreadCtl(_NTO_TCTL_RUNMASK), and the vehicle model integrates over measured time so late ticks do not hide the effect.

Accomplishments

  • One channel flag turns a 0.7 ms worst case into 201 ms — a clear, measurable demonstration of why QNX servers inherit client priority.
  • Per-request authorization that works for root processes, written in ten lines of policy and a few lines of C.
  • A codelab that goes from installing the SDK to an enforced security policy in eight steps.

What I learned

How the resource-manager framework, pulses and channels fit together; that secpolgenerate also records custom-permission use; and how much the default priority inheritance quietly protects a system.

What's next

Run each process as a non-root user as well, replace the toy model with a CAN resource manager, and run it on a Raspberry Pi 4 (make ARCH=aarch64le already builds it).

Built With

  • c
  • mkqnximage
  • qemu
  • qnx
  • secpol
Share this project:

Updates

Submission history