Skip to content

Harden the serial path, boot input and the boot log against denial of service - #10

Merged
Quant-TheodoreFelix merged 3 commits into
mainfrom
feature/availability-protect
Nov 20, 2026
Merged

Quant-TheodoreFelix merged 3 commits into
mainfrom
feature/availability-protect

Conversation

@Quant-TheodoreFelix

@Quant-TheodoreFelix Quant-TheodoreFelix commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

What and why

An availability review of main (6324648) was checked claim by claim against the code and by runs under QEMU. It found no way for an EL0 task or for serial input to stop the kernel, but it found four places where an outside party or boot input could cost more than intended. This pull request closes them.

  • Serial error characters: a character with a break, framing or parity error is dropped and uses no place in the receive ring, so the ring-full gate never bounded it. The party on the serial line could cause receive interrupts at line rate, whatever the reader did. The kernel now counts these characters and masks the receive interrupt until the next tick after 256 of them (DROP_MAX in crates/k0-conin). Only the tick reopens it.
  • Boot input: four inputs ended in a kernel panic or an EL1 abort instead of a refusal with a reason.
    • A DTB pointer at the end of the address range overflowed an addition in map_dtb, and a pointer below 2^47 but beyond the CPU's physical address width faulted on the first read. Both are now k0: dtb rejected: bad pointer.
    • A redistributor-stride near 2^64 overflowed the frame walk. A stride at or above 2^52 is now refused, and the walk treats an overflowing step as the end of the range.
    • RAM declared beyond the CPU's physical address width passed validation (the limit was 2^47 only) and the kernel faulted on the first access. The limit is now the smaller of 2^47 and the address width, in the kernel and in the UEFI loader's check.
    • A memory gap without one whole page was handed out as an Untyped capability that nothing can be made from. It is no longer handed out, and the kernel prints k0: memory <base> + <size> not handed out (no whole page).
  • Boot log: the lines the kernel prints when a task ends (a fault, an exit, an unknown system call) could fill the whole 16 KiB log, so later kernel lines were lost. They now share 4 KiB, are kept or dropped as whole lines, and stop before the last 2 KiB.
  • Tests and tools: host tests for the above, model tests for capabilities that refer to their own container and for capability, registry and page table operations run together, six boot matrix rows for hostile boot input, and a small device tree editor (tools/fdt-patch.py) so the rows need no dtc.

The documents in English and Korean describe the new behaviour and its limits.

How it was tested

  • tools/host-test.sh
  • tools/qemu-boot-test.sh
  • New or changed behavior has a test

Details:

  • Host tests: 377 pass on an AArch64 host (289 without k0-mm on other hosts), also from a git archive export of the branch. The new k0-conin tests fail without the budget ("5000 error characters taken in one tick"), and the new k0-efi case fails without the loader change.

  • Boot matrix: all 82 rows of tools/boot-matrix.sh pass locally (Apple M5 Pro, QEMU 11.1.3, K0_MATRIX_HVF=1). tools/qemu-boot-test.sh runs as the judge of its pass rows.

  • CI: the run for this pull request passed on both runners: the host tests, and all 71 rows of the boot matrix on QEMU 7.2, with the six new rows among them.

  • Before and after, on QEMU virt with cortex-a72:

    Input main This branch
    DTB pointer 0xFFFFFFFFFFFFFFF8 k0: PANIC at kernel/src/main.rs:848 k0: dtb rejected: bad pointer
    DTB pointer 2^45 k0: EXCEPTION sync-spx k0: dtb rejected: bad pointer
    Stride 0xFFFFFFFFFFFF0000, 2 cores k0: PANIC at crates/k0-arch/src/irq.rs:303 k0: platform rejected: BadRedistributor
    RAM at 2^44 k0: EXCEPTION sync-spx k0: platform rejected: MemoryAboveLimit
    2 KiB memory range handed out as a fourth Untyped not handed out, 3 Untyped
  • Boot log share: checked once with a throwaway root task that made 406 faulting tasks. On main the log filled with 170 fault lines and lost every later line. On this branch it holds 46 fault lines, the note line and the later lines.

Not covered:

  • The boot log share has no test in the tree. The probe above is not part of this pull request.
  • The break flood step of tools/term-test.py runs only on QEMU 8.0 or later, so it is expected to be skipped in CI (the CI log does not show the skip line). QEMU 7.2 puts a break into its PL011 receive FIFO without a depth check (pl011_event calls pl011_put_fifo directly in hw/char/pl011.c at v7.2.0, read in the source, not run), and breaks pile up there while the kernel keeps the interrupt masked. The step checks only that input is not cut off and recovers. The bound itself is shown by the host tests.
  • Nothing ran on real hardware.

Security notes

  • Unsafe: one new block in the kernel, in TaskLine::begin (crates/k0-arch/src/earlycon.rs). It reads the log length with interrupts masked and has its // SAFETY: comment. The new host tests use unsafe the way the existing ones do.
  • Trust boundaries touched: the serial line (an outside party drives the receive code) and boot input (the DTB pointer from the boot loader, the device tree, and the UEFI memory map in the loader's check).
  • New kernel state reachable from EL0: the byte count and the one-time flag of the task line share, which a task changes by ending. The count of dropped error characters is changed by serial input, not by EL0.
  • Dependencies: none from outside the workspace. k0-mm takes k0-cap as a dev-dependency for the composed test.
  • Advisory: the RAM bound is the subject of the draft advisory GHSA-hj3f-38h9-hrpj. Its status is not changed here.
  • Limits that stay: all task end lines share the one 4 KiB share, so a task that can create tasks can still push such lines of other tasks out of the log. Under noise, bytes behind a spent budget wait in the device FIFO for up to a tick and are marked as lost if it overruns. CAP_REVOKE on a large Untyped is still not preemptible, and k0-ipc and k0-sched still have no host tests.

AI assistance

The verification of the review, the design, the code, the tests, the tools and the documents in this pull request were made with Claude (Anthropic), and reviewed by two additional Claude agents whose confirmed findings were fixed. The scope was chosen by the maintainer. The results under "How it was tested" are from real runs on the machine named there.

Contributor License Agreement

  • I have signed the CLA. If this is the first pull request that needs your signature, comment the sentence from CONTRIBUTING.md on this pull request. The CLA signatures check shows who still needs to sign.
  • Or: every change in this pull request is trivial as defined in section 12 of the CLA.

… service

- Count dropped error characters and mask the receive interrupt until the next tick after 256 of them
- Refuse a redistributor stride that overflows the frame walk and treat an overflowing step as the end of the range
- Refuse a DTB pointer at the end of the address range or beyond the address width of the CPU
- Bound RAM by the address width of the CPU in the kernel and in the loader check
- Do not hand out a memory gap without a whole page
- Give the lines printed when a task ends their own share of the boot log
- Add host tests for these, and model tests for self referencing capabilities and composed address space operations
- `tools/fdt-patch.py` edits a device tree blob without dtc
- `K0_IMAGE_DTB_POINTER` makes the runner boot with another DTB pointer
- Six rows cover a bad pointer, a bad stride, RAM beyond the address width and a range without a whole page
- The terminal test sends a flood of breaks on QEMU 8 or later
- Serial error character budget, boot input refusals and the boot log share in SECURITY, INTRODUCTION, USAGE and the design notes
- New test and boot matrix counts
@Quant-TheodoreFelix
Quant-TheodoreFelix merged commit 02cdd5b into main Nov 20, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant