aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / docs / IMAC_DMAR_INVENTORY.md
| 1 | # iMac DMAR firmware inventory |
| 2 | |
| 3 | This implements the first discovery step of |
| 4 | [aienux #411](https://github.com/aien-dev/aienux/issues/411). It does not |
| 5 | implement or qualify device DMA confinement. Existing device startup continues |
| 6 | unchanged after the inventory, including when the table is absent or refused. |
| 7 | The image must not be treated as safe for sensitive memory or unrestricted |
| 8 | remote operations on the strength of this inventory. |
| 9 | |
| 10 | ## Implementation |
| 11 | |
| 12 | `native/kernel/core/dmar.c` reads one explicitly bounded byte buffer using |
| 13 | the format in the [Intel VT-d Architecture Specification, revision 5.0, |
| 14 | sections 8.1 through 8.4](https://cdrdv2-public.intel.com/831418/vt-directed-io-spec.pdf). |
| 15 | It checks the signature, declared size, checksum, revision, reserved fields, |
| 16 | entry ordering, nested lengths, device/function bounds, remapping-unit |
| 17 | alignment and reserved-region range/alignment. It retains DRHD units, their |
| 18 | device scopes, and RMRR reserved ranges with their scopes. Other structure |
| 19 | types are counted and skipped by declared length, as the specification requires. |
| 20 | Skipping them is not a declaration that their requirements are supported. |
| 21 | |
| 22 | Storage is fixed: at most 64 KiB of table bytes, eight units, sixteen regions, |
| 23 | 64 scopes across both owner types and eight device/function pairs per path. |
| 24 | Oversized inventories return a capacity error. Unknown scope types or table |
| 25 | revisions return unsupported. Every failure clears the output, including |
| 26 | failures after valid entries. There is no allocation, register access or |
| 27 | device configuration in the parser. |
| 28 | |
| 29 | `native/kernel/x86/dmar_x86.c` locates the table with the existing checked ACPI |
| 30 | lookup, inventories it before PCI drivers start, and prints `dmar:` diagnostics. |
| 31 | It retains segment numbers and complete paths. A one-hop path has a direct |
| 32 | source ID. A longer path remains unresolved until each bridge's secondary bus |
| 33 | has been read; the last path element alone is insufficient. A subhierarchy |
| 34 | also needs downstream enumeration. Reserved regions are reported as firmware |
| 35 | requirements, never treated as granted windows. |
| 36 | |
| 37 | The report ends with `inventory-only register_access=none; DMA confinement |
| 38 | NOT QUALIFIED`. Absence, invalid data and refusal also explicitly state that |
| 39 | confinement is not qualified. The optional lab diagnostic report allowlists |
| 40 | these lines. Its existing unauthenticated status remains unchanged. Default |
| 41 | images still contain no network report. |
| 42 | |
| 43 | ## Verification |
| 44 | |
| 45 | The host test `native/kernel/tests/test_dmar.c` covers a multi-segment fixture, |
| 46 | multi-hop device paths, an IOAPIC, a reserved region, an unknown structure, |
| 47 | every truncated prefix, corrupt fields, capacity exhaustion and a 64-bit |
| 48 | address boundary. The same test runs with address and undefined-behavior |
| 49 | sanitizers through the normal kernel host targets. |
| 50 | |
| 51 | `scripts/qemu_ck_imac_kernel_test.sh` checks that the default simulated machine |
| 52 | reports the absent table without claiming protection. Setting |
| 53 | `AIENOS_IMAC_DMAR=1` adds QEMU's Intel IOMMU device and requires a parsed unit, |
| 54 | IOAPIC scope and inventory-only marker under both existing CPU models. These |
| 55 | are firmware discovery tests. They neither enable remapping nor test blocked |
| 56 | DMA. The existing read-only disk checks and deliberate W^X failures remain. |
| 57 | |
| 58 | `scripts/ck_imac_report_test.sh` checks that inventory diagnostics survive the |
| 59 | allowlist while chat, keys and tokens remain excluded. Its lab build uses the |
| 60 | existing explicit test-key option solely for this hosted test. No hardware |
| 61 | staging image is produced by that script. |
| 62 | |
| 63 | ## Remaining work |
| 64 | |
| 65 | Read and preserve the actual iMac's map on an explicitly authorized, attended |
| 66 | boot. Resolve all relevant device paths against its PCI topology and account |
| 67 | for reserved memory and any additional DMAR structures. Then implement and |
| 68 | test domain construction, approved windows, invalidation, fault handling and |
| 69 | fail-closed driver lifecycles. Physical out-of-window DMA and device recovery |
| 70 | tests are still required by #411. No isolation claim follows from a successful |
| 71 | inventory or an emulator boot. |