Skip to content

Align the attested version to the device's Keymaster HAL on legacy devices - #257

Merged
JingMatrix merged 3 commits into
devfrom
fix/keymaster-hal-vintf-align
Aug 17, 2026
Merged

Align the attested version to the device's Keymaster HAL on legacy devices#257
JingMatrix merged 3 commits into
devfrom
fix/keymaster-hal-vintf-align

Conversation

@JingMatrix

Copy link
Copy Markdown
Owner

#247 clamps the attested attestationVersion to the KeyMint HAL version the device declares in VINTF, but Vintf only ever reads the AIDL KeyMint HAL (android.hardware.security.keymint.IKeyMintDevice). A device that ships the legacy Keymaster HIDL HAL instead — android.hardware.keymaster/IKeymasterDevice/default@4.1 — declares no KeyMint HAL, so keyMintHalVersion returns null, the clamp is a no-op, and the presented pair stays at whatever was captured or fabricated. On such a device that came out keymasterVersion=4/attestationVersion=3 (Keymaster 4.0), one minor version below the declared 4.1, and a checker that maps IKeymasterDevice@N to the attestation version a real device of that HAL reports (AOSP system/keymaster version_to_attestation_version / version_to_keymaster_version: 4.1 → attestation 4, keymaster 41) flags the mismatch.

Vintf now also parses the Keymaster HIDL HAL and returns its attestation-version equivalent (2.0 → 1, 3.0 → 2, 4.0 → 3, 4.1 → 4). When no KeyMint HAL is declared, the harvest aligns the presented attestationVersion/keymasterVersion — and the StrongBox instance's version — to the declared Keymaster HAL. Unlike the KeyMint ceiling, which only clamps down, this aligns in both directions: a captured or fabricated value may sit either side of the legacy HAL, and the checker wants an exact match rather than an upper bound. keymasterVersionFor already yields the matching keymasterVersion (attestation 4 → keymaster 41), so the pair stays self-consistent, and the resulting sub-400 version keeps MODULE_HASH off, as a Keymaster device expects.

…vices

#247 clamps the attested attestationVersion to the KeyMint HAL version the device
declares in VINTF, but Vintf only ever reads the AIDL KeyMint HAL
(android.hardware.security.keymint.IKeyMintDevice). A device that ships the legacy
Keymaster HIDL HAL instead -- android.hardware.keymaster/IKeymasterDevice/default@4.1 --
declares no KeyMint HAL, so keyMintHalVersion returns null, the clamp is a no-op, and the
presented pair stays at whatever was captured or fabricated. On such a device that came out
keymasterVersion=4/attestationVersion=3 (Keymaster 4.0), one minor version below the declared
4.1, and a checker that maps IKeymasterDevice@N to the attestation version a real device of
that HAL reports (AOSP system/keymaster version_to_attestation_version /
version_to_keymaster_version: 4.1 -> attestation 4, keymaster 41) flags the mismatch.

Vintf now also parses the Keymaster HIDL HAL and returns its attestation-version equivalent
(2.0 -> 1, 3.0 -> 2, 4.0 -> 3, 4.1 -> 4). When no KeyMint HAL is declared, the harvest aligns
the presented attestationVersion/keymasterVersion -- and the StrongBox instance's version -- to
the declared Keymaster HAL. Unlike the KeyMint ceiling, which only clamps down, this aligns in
both directions: a captured or fabricated value may sit either side of the legacy HAL, and the
checker wants an exact match rather than an upper bound. keymasterVersionFor already yields the
matching keymasterVersion (attestation 4 -> keymaster 41), so the pair stays self-consistent,
and the resulting sub-400 version keeps MODULE_HASH off, as a Keymaster device expects.
@kukIux

kukIux commented Aug 17, 2026

Copy link
Copy Markdown

Screenshot_20260817-180945_Key Attestation.png

Screenshot_20260817-180958_kknd Detector.png

@kukIux

kukIux commented Aug 17, 2026

Copy link
Copy Markdown

Screenshot_20260817-181144_Duck Detector.png

…styles

The first cut returned "declared Keymaster HAL attestationVersion = unknown" on the
reported Android 16 device, so no alignment happened and the VINTF mismatch stood. Two
gaps: Vintf only scanned the device manifests (/vendor, /odm), and the Keymaster parser
only read the <version> + <interface> form. On that device the Keymaster HAL is declared
framework-side and/or via <fqname>, so the scan found nothing -- while the integrity
checker, reading the assembled VINTF, sees android.hardware.keymaster/IKeymasterDevice/
default@4.1 and flags keymasterVersion=4/attestationVersion=3 against the expected 41/4.

Vintf now scans the framework manifests too (/system, /system_ext, /product) alongside
/vendor and /odm, and the Keymaster parser handles both the <fqname> form
(@4.1::IKeymasterDevice/default, version bound to its instance) and HIDL version ranges
("4.0-1"), matching how the checker's own manifest reader (Duck-Detector's
VintfKeyMintVersionProbe) reads them.

The KeyMint ceiling and the Keymaster exact-match now share one accessor,
Vintf.attestationVersionConstraint(instance) -> (version, exact), so
clampAttestationToVintf reconciles both levels through a single path: clamp down to an
AIDL ceiling, move exactly to a legacy HIDL target. The declaration-parsing and
constraint model follow the approach in #259 (Ahmad Addas).
@JingMatrix

Copy link
Copy Markdown
Owner Author

Hi @kukIux — the Keymaster VINTF fix is ready. Could you retest on the Android 16 device whose Duck Detector showed "KeyMint VINTF: MISMATCH" (IKeymasterDevice/default@4.1)?

Debug build TEESimulator-v4.0-59-71944c3-Debug:
https://github.com/JingMatrix/TEESimulator/actions/runs/32043083381/artifacts/9292402907

Please install it, reopen Duck Detector, and check whether the KeyMint VINTF row is now green — then attach the log and a screenshot. Thanks!

@kukIux

kukIux commented Aug 17, 2026

Copy link
Copy Markdown

Hi @kukIux — the Keymaster VINTF fix is ready. Could you retest on the Android 16 device whose Duck Detector showed "KeyMint VINTF: MISMATCH" (IKeymasterDevice/default@4.1)?

Debug build TEESimulator-v4.0-59-71944c3-Debug:
https://github.com/JingMatrix/TEESimulator/actions/runs/32043083381/artifacts/9292402907

Please install it, reopen Duck Detector, and check whether the KeyMint VINTF row is now green — then attach the log and a screenshot. Thanks!

Anyway detected!

Screenshot_20260817-222156_kknd Detector.png

Screenshot_20260817-222138_Duck Detector.png

@JingMatrix
JingMatrix merged commit fa867b7 into dev Aug 17, 2026
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