The plain version
Imagine you approve a letter, and then a clerk posts a different letter in the same envelope. Approving "a letter" is not enough. You have to approve the exact words, and the post box has to check them.
On an industrial bus called Modbus, the message is the danger. The same write command can change a harmless setting or a battery's protection limit; only the register address differs. Switching power on or off does not tell you what the transmitter says. So we put a small guard between the computer and the wire that sends only the exact message that was approved.
What merged
- #186: the bus guard logic.
- #212: frames bound to the approved action, unit addresses and a single-use pass.
- #217: a signal's register width comes from its write-map entry.
- Related: #193, signed approvals.
The rules (technical)
sawbones-busguard is no_std, designed to sit between a pod's UART and its RS-485 or RS-232 driver. BusGuard::decide holds these rules:
- Only well-formed frames. A frame must parse as one Modbus RTU request with function 0x03, 0x04, 0x06 or 0x10, the exact length that function needs and a correct CRC-16/MODBUS. Anything else, and any broadcast (unit address 0), is blocked.
- Reads need a rule. Reads transmit too, so they pass only if an allow-list rule permits them on that port.
- Writes need a rule and a lease. A write passes only if a rule permits it, a lease is live on the same port, and the frame is byte for byte the frame the lease's approved action encodes to, with the SHA-256 recorded at the grant. Passing spends the lease. Changing any byte, unit, register, value or function blocks it.
- No writes while another master talks. If the firmware feeds the guard what it hears on the line and a request appears that the guard did not send, writes are blocked until the trust root sends a new allow-list.
- Everything else blocks.
The bytes checked are the bytes sent. decide copies the frame before checking it and returns a Pass that owns the copy. The firmware hands each port's transmitter to a GuardedLine, whose only way to send is transmit of a Pass by value. There is no raw slice and no second send, which closes a check-then-use race (red-team card bus-009).
One encoder
The policy engine reasons about named signals, the guard about wire bytes. Before #212, nothing proved that the frame the guard passed encoded the action the policy engine had classified: whoever turned one into the other was a confused deputy. Now sawbones-modbus-encode is the only place an action becomes bytes. The policy engine's digest, the interlock's lease, the trust root's approval and the guard's pass are all the same action. A write-single-register frame is 8 bytes and a write-multiple frame is 9 bytes plus two per register; golden tests pin examples from the Modbus specification. The action's canonical encoding is injective, so two different actions cannot share a digest.
Signed approvals
sawbones-approvals defines the message the guard checks itself: what is approved (with the digest of the exact thing), the device it is for, who signed it, a per-signer counter and an expiry, in one fixed layout. The signature is Ed25519 over a domain tag plus those bytes. A compromised Pi can relay an approval but cannot forge or replay one.
Fuzzing
The Modbus parser is fuzzed weekly in CI (the busguard_modbus_rtu target), rebuilding each frame byte for byte.
What is not built
The signature check works with fixed test keys; real keys are switched on when hardware testing starts. The guard firmware on an RP2350, framing by silence, the driver-enable pin and timing are not written. The guard judges requests going out, not replies. The first hardware phase is listen-only.