Skip to content

soc: apple: aurora-boot-security: add KUnit tests - #2940

Open
RyanTheTide wants to merge 5 commits into
mainfrom
kunit/aurora-boot-security
Open

RyanTheTide wants to merge 5 commits into
mainfrom
kunit/aurora-boot-security

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Problem. aurora-boot-security turns the boot security record that the bootloader hands over in /chosen into what /sys/firmware/aurora/boot_security reports, including whether the boot chain counts as verified. It had no test.

Change. New suites aurora-boot-security and aurora-boot-security-init live in drivers/soc/apple/aurora-boot-security-test.c. The record-reader suite can run as a module. The init suite is built in. Each case builds the record in the live devicetree with an of_changeset and calls the driver's own functions:

  • the Stage 1 decision for every combination of stage, policy and verdict, one valid entry among many, none among many, values without a NUL terminator, and string lists (only the first string counts);
  • the effective chain state: "verified" is reported only when the record says exactly that and an enforcing Stage 1 verified it; otherwise it is demoted;
  • what each sysfs attribute (state, advisory, lockdown, policy, stage1_flavour, uefi_secure_boot, lp_coih, measurements) shows for absent, empty, unterminated, short, long and over-a-page values, with a guard area after the buffer that must stay untouched;
  • init with a synthetic record at /chosen/aurora,boot-security: no record, a compatible that is not v1, a verified chain, a "verified" claim over an auditing Stage 1 (reported as partial/advisory), and v1 listed second.

Plus a standalone drivers/soc/apple/aurora-boot-security.kunitconfig. Both suites leave existing boot-security state alone. The synthetic measurement case skips when IMA is enabled.

Testing.

  • kunit.py run --arch=arm64 (QEMU, gcc): 81/81, standalone kunitconfig 81/81, and again with this wave's three branches merged on the integration/aurora tip.

  • After review fixes, the suite passed again on the integration tip.

  • With IMA and boot-security lockdown enabled, arm64 QEMU passed 75 tests and skipped 6 as expected. The IMA submission and the init fixture were skipped.

  • Negative controls: the Stage 1 decision ignoring the policy (9 failures); the sha256 printed for len >= 32 instead of == 32 (1); the "verified" demotion inverted (7).

  • checkpatch --strict: 0 errors; the warning is the MAINTAINERS reminder for new files.

  • Follow-up arm64 QEMU with slub_debug=FZ passed 83/83 built in, including five init cases, with both the standard and KASAN builds, and 78/78 with KUNIT=m and the record-reader suite loaded as a module. Both runs cover the test-key verdict and an enforcing dev record.

Notes for reviewers
  • Not covered: the lockdown decision (enabling it would lock down the test kernel, and it needs EFI; the init suite skips itself if that option is set), the IMA measurement log (the submission case skips with IMA enabled), and kobject allocation failures.
  • Possible follow-up, not a bug: an unknown state string (e.g. "Verified" or "verified\n") is passed through to sysfs as is. Kernel decisions don't change, and the tests check it is never reported as "verified". Mapping anything else to "unverified" would be tidier for userspace.

Still to run. Nothing on hardware: the change is test-only.

The boot security record decides what /sys/firmware/aurora/boot-security
reports and whether the chain counts as verified. Add suites that build
the record in the live devicetree with an of_changeset and call the
driver's own functions:

- the Stage 1 decision for every combination of stage, policy and
  verdict, one valid entry among many, none among many, values without
  a NUL terminator and string lists;
- the effective chain state: "verified" only when the record says
  exactly that and an enforcing Stage 1 verified it, demoted otherwise;
- what each sysfs attribute shows for absent, empty, unterminated, short,
  long and over-a-page values, with a guard area after the buffer;
- init on a real /chosen record: none, a compatible that is not v1, a
  verified chain, a verified claim over an auditing Stage 1, and v1
  listed second.

Tests only, no functional change.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Review at 3539f5d.

The only driver change is the #include at aurora-boot-security.c:319-321, so behaviour is unchanged. The tests call the real stage1_enforced_verified(), effective_state(), show functions and aurora_boot_security_init(), and the malformed, unterminated, string-list and oversize cases are good. Three things before merge:

  1. Kconfig:436-438: bool plus depends on APPLE_AURORA_BOOT_SECURITY=y && KUNIT=y means the fleet kernel (KUNIT=m, driver =y) can never build this, so it only runs in kunit.py QEMU. Please make it a tristate module: export the decision and show helpers with VISIBLE_IF_KUNIT/EXPORT_SYMBOL_IF_KUNIT (taking the record node rather than the static rec), and keep the __init suite as the built-in-only part.
  2. Test key: stage1_enforced_verified() (aurora-boot-security.c:70-76) trusts the Stage 1 verdict string and ignores key-id and stage1-flavour. Today's enforcing Stage 1 records a Stage 2 signed with the published test key as verified (aura#472 is still open), so this driver reports that chain as verified, advisory 0 and, with LOCKDOWN, "the verified boot chain". The tests don't cover it: bs_init_verified (947-966) asserts verified for a record with no key-id at all. Please at least add BS_M("stage1", "enforce", "test-key") -> false to bs_one_cases (212-229) to pin the aura#472 contract, and add a case for an enforcing stage1-flavour = "dev" record whose expected result is stated, not just whatever the code does now.
  3. Minor: bs_init_init (848) skips whenever LOCKDOWN=y, which is the default whenever SECURITY_LOCKDOWN_LSM and EFI are set, so the init suite will also skip on the fleet. Please say so in the help text.
    The test vectors (sha 00..1f, lp-coih lengths) are synthetic, and the PR contains no keys.

@RyanTheTide
RyanTheTide marked this pull request as draft November 23, 2026 04:25
Check for live state before initializing either fixture and only tear down
resources owned by the test. Skip the IMA submission case when IMA is
enabled, and let the changeset own the fixture nodes.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
The policy formatting case does not call IMA. Only skip the case
that calls the measurement submission path.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formal §1–§6 pre-PR checklist review at c283241f8ad80cced13c086e79f3b8b7eff38a04 (Draft PR — posting COMMENT).

Verified Fixes in 0935b9d9..c283241f

  • Live-state isolation is solid: bs_init() skips whenever rec || aurora_kobj || bs_kobj is already populated and saves/restores chain_state, lockdown_reason, and stage1_enforced; bs_exit() and bs_init_exit() guard if (!test->priv) return;.
  • Fixture nodes now attach under /chosen instead of of_root, bs_create_node() drops the extra refcount from of_changeset_create_node() so the changeset cleanly owns lifetime, bs_raw() frees on allocation/of_changeset_add_property() failure, and bs_run_driver_init() clears aurora_kobj/bs_kobj on init failure to prevent double-kobject_put().
  • bs_measure_record_full_page() skips when CONFIG_IMA=y while keeping policy formatting coverage active, and Kconfig help text now documents the LOCKDOWN, live-state, and IMA skip conditions (thread item #3 resolved).

Remaining Blockers Before Undrafting / Merge

  1. bs_page() is not PAGE_ALIGNED-safe under CONFIG_KASAN / CONFIG_SLUB_DEBUG (drivers/soc/apple/aurora-boot-security-test.c:197-205): kunit_kzalloc(test, 2 * PAGE_SIZE, GFP_KERNEL) hits the kmalloc-2*PAGE_SIZE slab cache (KMALLOC_MAX_CACHE_SIZE == 2 * PAGE_SIZE), not the page allocator. With slab redzoning enabled (CONFIG_KASAN or slub_debug=FZ), the returned pointer is not PAGE_ALIGNED, causing KUNIT_ASSERT_TRUE(test, PAGE_ALIGNED(buf)) (and sysfs_emit()'s WARN(offset_in_page(buf))) to fail on every sysfs show test. Allocate via __get_free_pages(GFP_KERNEL | __GFP_ZERO, 1) (with a kunit_add_action_or_reset() free wrapper) or vzalloc(2 * PAGE_SIZE) so the buffer is unconditionally page-aligned.
  2. Kconfig blocks modular KUNIT=m fleet builds (drivers/soc/apple/Kconfig:436-438, open from thread item #1): bool + depends on APPLE_AURORA_BOOT_SECURITY=y && KUNIT=y && OF_DYNAMIC + #include "aurora-boot-security-test.c" cannot build on fleet/distro kernels (APPLE_AURORA_BOOT_SECURITY=y, KUNIT=m). Convert the non-__init suite to a tristate test module (VISIBLE_IF_KUNIT / EXPORT_SYMBOL_IF_KUNIT, keeping the __init suite built-in-only), or document why built-in-only is intended.
  3. Test-key / stage1-flavour = "dev" coverage gap (open from thread item #2): bs_one_cases still lacks BS_M("stage1", "enforce", "test-key") -> false (pinning the aura#472 contract), and there is still no explicit case stating the expected result for an enforcing stage1-flavour = "dev" record.

Non-blocking notes & CI

  • drivers/soc/apple/aurora-boot-security-test.c:83-110 (bs_raw()): if an assertion aborts a test before bs_apply() runs, p/p->name/p->value are never linked onto np->properties or np->deadprops and will leak on of_changeset_destroy() (unlike of_changeset_add_prop_helper(), which links new_pp onto np->deadprops immediately).
  • Production drivers/soc/apple/aurora-boot-security.c is untouched aside from the #if IS_ENABLED(CONFIG_APPLE_AURORA_BOOT_SECURITY_KUNIT_TEST) include guard.
  • CI: All 7/7 checks are green (SUCCESS), though note .github/workflows/sep-source.yml's kunit job only executes apple_sep*, not aurora-boot-security.

Checklist (§1–§6)

  • §1, §3, §6: Pass (synthetic OF changesets, no hardware MMIO, no keys, no model gates).
  • §2: Open blockers #1–#3 above before undrafting.
  • §4: Pass (all 3 commits carry human author/committer + human Signed-off-by:, zero AI trailers in commits; PR body Assisted-by: present).
  • §5: Pass (81/81 arm64 QEMU + 75 pass / 6 skip with IMA+LOCKDOWN + negative controls + 7/7 CI green; test-only change).

Assisted-by: LLM (Gemini 4 Neon)

Keep init-section tests built in and let modular KUnit exercise the
record reader. Allocate page-aligned sysfs fixtures and cover test-key
verdicts and enforcing dev-flavour records.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

The record-reader suite can now load with KUNIT=m, while the init cases stay built in so they can call the driver's init code. The sysfs buffer now uses vzalloc() for page alignment, with a second page for the write canary.

The new cases check that an enforcing Stage 1 with a test-key verdict does not count as verified and that an enforcing, verified record with stage1-flavour = "dev" reports dev and remains verified. This pins the kernel's interpretation of the record.

arm64 QEMU passed 83/83 built in with KASAN and slub_debug=FZ, and 78/78 with KUnit and the record-reader suite loaded as modules under slub_debug=FZ.

Assisted-by: LLM (Codex)

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-checked at 166c4b6. All three points from my 11-23 review are fixed:

  • the sysfs page comes from vzalloc(), so it is page-aligned under KASAN and slub_debug;
  • the record-reader suite builds as a module with KUNIT=m through EXPORT_SYMBOL_IF_KUNIT, and only the init suite stays built in;
  • the new cases pin test-key as not verified, and an enforcing dev record as verified with flavour dev.

The leak note is fixed too: bs_raw() now puts the property on the node's deadprops, as of_changeset_add_prop_helper() does. Nothing more from me. It's test-only, so no hardware row is needed. The hosted run at this head was cancelled on 11-30 before it got runners, so it needs a fresh run when this comes out of draft.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Forward-merged main f02bd68 as 0f33462 (clean merge, the four commits unchanged) so the hosted CI that was cancelled on 11-30 runs again. Local: arm64 LLVM W=1 with KUNIT=y, OF_DYNAMIC=y and the test as a module: aurora-boot-security.o and aurora-boot-security-test.o build with no warnings. DjDeveloperr's 11-23 points are fixed (re-checked at 166c4b6). Test-only, so no hardware row is needed. Ready for review.

@RyanTheTide
RyanTheTide marked this pull request as ready for review December 5, 2026 01:34
@RyanTheTide
RyanTheTide requested review from a team as code owners December 5, 2026 01:34

This branch has not been deployed

No deployments
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.

2 participants