Skip to content

feat(uefi): read TianoCore EDK2 NVRAM variable stores - #14701

Merged
morluto merged 6 commits into
morluto:mainfrom
BeqaKs:cursor/edk2-nvram-a7dc
Nov 27, 2026
Merged

morluto merged 6 commits into
morluto:mainfrom
BeqaKs:cursor/edk2-nvram-a7dc

Conversation

@BeqaKs

@BeqaKs BeqaKs commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #13229. inspect_uefi_nvram previously returned stores: [] with only an AMI NVAR limitation for TianoCore EDK2 / OVMF *_VARS.fd images. It now also reports VARIABLE_STORE_HEADER regions under additive edk2_stores while leaving the AMI stores contract unchanged.

Problem and expected behavior

EDK2 / OVMF / ArmVirtQemu NVRAM flash images use gEfiVariableGuid or gEfiAuthenticatedVariableGuid store headers. Analysts need static BootOrder / SecureBoot style inventory with active (VAR_ADDED / 0x3f) versus superseded states without executing firmware. Expected: read-only EDK2 store cartography alongside the existing AMI path.

Change and scope

  • Add scanEdk2VariableStores for public UEFI PI / EDK2 VariableFormat.h layouts (authenticated and non-auth headers, 4-byte alignment, Format 0x5a / State 0xfe).
  • Expose results as additive edk2_stores (issue Option B) so AMI stores remain byte-compatible.
  • Classify variable state from the observed State byte (added, in-deleted-transition 0x3e, deleted including 0x3d = ADDED&DELETED, header-only, unknown); report state_raw, 32-bit EFI attributes, vendor_guid, and bounded data digests without interpreting bytes.
  • Preserve AMI NVAR scanning and empty-store messaging for AMI-only images.
  • Update tool/CLI/docs wording; synthetic fixture tests from the issue repro.

Contribution scope: ordinary extension of the existing read-only UEFI NVRAM inspector. Maintainer scope decision: not applicable (no target execution, injection, mutation, or protection recovery).

Contract and boundary impact

  • Semantic owner and earliest changed stage: inspect_uefi_nvram / UefiAnalysisProvider + UefiEdk2Nvram produce EDK2 store facts; AMI mapping unchanged. Consumers that only read stores keep prior AMI behavior; callers that need EDK2 read edk2_stores.
  • Contribution scope fit and linked maintainer decision: not applicable.
  • CLI and MCP/tool-catalog contract: additive optional edk2_stores on inspect_uefi_nvram output; input max_stores applies per format; description updated.
  • Provider, bridge, target-format, or platform compatibility: pure TypeScript read-only parser; no external tools.
  • Evidence, artifact, provenance, or reconstruction contract: edk2_stores optional for Evidence saved before this field; producers always emit it.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): not applicable.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: catalog regenerates in CI from contracts; no package metadata change.

Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated: src/uefi/UefiNvram.test.ts — synthetic authenticated BootOrder (0x3d deleted + 0x3f added), non-auth gEfiVariableGuid + in-deleted-transition (0x3e), max_stores partial coverage; existing AMI tests unchanged.
  • Base reproduction or other evidence: issue [Feature] Support TianoCore EDK2 variable stores (gEfiVariableGuid / gEfiAuthenticatedVariableGuid) in inspect_uefi_nvram #13229 minimal FV + authenticated store fixture; pre-change AMI scan still returns stores: [] with the AMI empty limitation.
  • User-visible CLI/MCP output (if applicable): edk2_stores arrays with state / state_raw / vendor_guid / data ranges.
  • Remaining proof gaps: no live OVMF_VARS.fd binary in CI; coverage is synthetic VariableFormat.h layout.

Boundary regressions: parser inventory for a new firmware region format (module tests). Lifecycle regressions: not applicable (no owned child processes).

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

Compatibility, safety, and release

  • Breaking changes or migration steps: none. Additive optional edk2_stores; AMI stores unchanged.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: read-only local image parse; variable bytes hashed/referenced, never executed or interpreted as policy.

Author readiness

Human owner: @BeqaKs

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Author checklist (completed by the PR author before requesting review)

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.
  • I ran every test, build, or measurement needed to validate this change, reported a browser, GPU, or environment gap only when that runtime or hardware is unavailable, and reported the checks I ran and their results without presenting inferred correctness or speedups as measured.
  • Comments explain constraints or non-obvious decisions; task history and conversations stay out of code and docs.
  • Documentation is concise and factual, without punchy slogans or promotional language.
  • This change fixes the root cause and follows the engineering rules in AGENTS.md.
  • Formatted input is interpreted once at the owning boundary, and consumers use the owner's parsed facts. See Interpret boundary facts once.
  • Combined failures preserve partial observations, remaining resources, and cleanup facts. See Own the lifecycle.
  • A hardcoded limit is an REA_ runtime setting with a default, floor, and maximum, unless a fixed ceiling has a stated reason. See Adding a runtime setting.

Add read-only parsing of gEfiVariableGuid /
gEfiAuthenticatedVariableGuid VARIABLE_STORE_HEADER regions to
inspect_uefi_nvram via additive edk2_stores, preserving the AMI NVAR
stores contract and reporting added vs superseded variable states.
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-26T11:41:13.469081Z
We couldn’t complete this review. Comment @codex review to try again.
e959757 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@greptile-apps

greptile-apps Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge; no blocking findings remain.RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Medium impact] The PR appears safe to merge; no blocking findings remain.

Summary

Adds read-only EDK2 / OVMF variable-store inventory under edk2_stores, while preserving AMI records under stores.

  • UEFI NVRAM reports EDK2 stores beside AMI results.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Read local image] --> B[Create shared record budget]
  B --> C[Scan AMI NVAR chains]
  C --> D[Scan EDK2 variable stores]
  D --> E[Combine coverage and limitations]
  E --> F[Return stores and edk2_stores]
Loading

Reviews (5) · Last reviewed commit: "fix(uefi): distinguish unchecked EDK2 st..." · Reviewed by Greptile

Comment thread src/uefi/UefiEdk2Nvram.ts Resolved
Comment thread src/uefi/UefiEdk2Nvram.ts Resolved
Comment thread src/uefi/UefiEdk2Nvram.ts Resolved
Comment thread src/uefi/UefiEdk2Nvram.ts Resolved
Comment thread src/uefi/UefiAnalysisProvider.ts Resolved
Comment thread src/uefi/UefiNvram.test.ts Resolved
Occupy store ranges and charge decoded names before retention, keep
truncated and damaged-name facts, examine unread tails, and compose
empty-format diagnostics from scanner facts with a provider-level test.
Comment thread src/uefi/UefiEdk2Nvram.ts Resolved
Comment thread src/uefi/UefiEdk2Nvram.ts Resolved
…locks

Walk store GUID candidates in ascending offset order, claim only verified
spans so damaged oversized headers cannot hide later stores, and checkpoint
erased suffixes per 64 KiB block.
@morluto morluto added area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior enhancement New feature or request provider: uefi Analysis provider / engine: uefi labels Nov 26, 2026
A gEfiVariableGuid or gEfiAuthenticatedVariableGuid match whose header
lacks the formatted marker was skipped silently, so an image holding only
such a header reported that no EDK2 store exists. It is now reported as a
rejected signature, and the absence statement is qualified.

A formatted store that is not HEALTHY is walked with EDK2's verdict as a
caveat: EDK2 treats it as invalid, while UEFITool still parses it. A store at
an unaligned image offset states the HEADER_ALIGN assumption.

An in-use EDK2 fault-tolerant-write queue is noted, because REA does not
replay FTW writes or rebuild a store from the spare area.

AMI NVAR and EDK2 scans now share one structural record budget, as the
limit documents. GUID signature encoding moves to UefiGuid beside its
decoder, header field offsets are named after VariableFormat.h, the
limitation-line cap is a named limit, and the store walk is split from
header admission with unreachable branches removed.
Comment thread src/uefi/UefiAnalysisProvider.ts Resolved
Carry an explicit completed-search absence fact from the EDK2 scanner.
Partial or budget-stopped searches report that presence is unknown
instead of claiming no store exists.
@morluto

morluto commented Nov 27, 2026

Copy link
Copy Markdown
Owner

Thanks for this. I reviewed the whole PR against EDK2's own headers and UEFITool, and pushed two commits on top of your branch: a merge of main, and 6d277819b3 with the fixes below. Your commits are unchanged.

The layout you implemented matches EDK2: both variable header forms, the store header, the 0x55AA StartId, the State values, 4-byte HEADER_ALIGN, and no padding between name and data (ALIGNMENT is 1, so GET_PAD_SIZE is 0).

Defects fixed

  1. An unusable store signature read as "no EDK2 store". A store GUID whose header lacked Format == 0x5A, or was not HEALTHY, was skipped silently. An image holding only such a header then reported that no EDK2 variable store exists. These matches are now listed as rejected, with their Format and Size. When nothing usable is found, the absence statement says signatures were examined and rejected. Edk2NvramScan.rejectedSignatures carries the count. Rejected matches don't mark coverage partial: the bytes were examined, and are often just the GUID constant inside the variable driver.
  2. A formatted store that is not HEALTHY is now walked. EDK2 treats such a store as invalid, while UEFITool still parses it. REA now walks its variables and adds a limitation giving EDK2's verdict, so neither reading hides the other.
  3. Fault-tolerant writes are now flagged. EDK2 reclaims a full store through the FTW working block and spare area. If a reclaim is interrupted, live variables can sit in the spare area, which this reader doesn't rebuild, so the store it reports may be the stale copy. When a working block's write queue holds records, the result now says so.
    • The header check follows FtwInitWorkSpaceHeader (0xff-filled reserved bytes and a bounded WriteQueueSize). A bare GUID constant in a driver is therefore not counted.
    • An erased queue adds nothing.
  4. The two scans now share one record budget. UEFI_FIRMWARE_LIMITS.scanRecords is documented as one structural record ceiling per inspection, but the AMI and EDK2 scans each created their own, so one inspection could examine twice the limit.
  5. The alignment assumption is now stated. HEADER_ALIGN aligns the mapped address. A store at an unaligned image offset now gets a limitation saying variable positions assume that alignment applies to image offsets.

Brittleness cleanup

  • GUID encoding: it had a second, unvalidated copy, where Number.parseInt on bad text silently wrote NaN. It now lives in UefiGuid.ts as guidBytesLittleEndian, beside the decoder. It accepts only canonical GUID text and has a known-answer test against the PI spec's FFS2 and FFS3 bytes. The test fixtures keep their own encoder so they don't depend on the code they test.
  • Header field offsets: the raw 36/40/44 versus 8/12/16 branches are replaced by one layout table per header form, named after VARIABLE_HEADER and AUTHENTICATED_VARIABLE_HEADER. The store header fields are named too.
  • The 512-line limitation cap: it was repeated in four places and is now UEFI_FIRMWARE_LIMITS.limitationLines.
  • The store walk:
    • It is split from header admission (walkStoreVariables, storeCaveats).
    • sawInvalid is removed: every path that set it broke out of the loop on the next line, so the checks that read it were always true.
    • The "did not advance" check is removed: a variable always ends at least one header past its start.

Left as is: parseEdk2Variable still takes five parameters, a lint warning that predates this PR.

Validation

  • Your follow-up d0f813e61c builds on this: the explicit absent fact, and "search did not finish" for a partial scan. It is correct, and the tests pass with it. CI is green on d0f813e61c.

  • Source tests: src/uefi/UefiNvram.test.ts (30), src/uefi/UefiGuid.test.ts, and src/uefi/UefiAnalysisProvider.test.ts. New regressions cover each defect above.

  • Public MCP workflow: a new case in tests/acceptance/uefiFirmware.test.ts checks that an EDK2 store is published through inspect_uefi_nvram and that a rejected signature does not read as absence. All 10 tests in that file pass.

  • Typecheck, lint, architecture guards, oxfmt and the generated-docs check pass locally. The firmware guide describes the new limitations.

  • Real firmware: not tested. All fixtures are synthetic; no real OVMF or vendor dump was run.

Sources

  • EDK2 MdeModulePkg/Include/Guid/VariableFormat.h: header structs, ALIGNMENT, GET_PAD_SIZE, HEADER_ALIGN, store Format and State, and variable State values.
  • EDK2 MdeModulePkg/Include/Guid/SystemNvDataGuid.h: EDKII_WORKING_BLOCK_SIGNATURE_GUID and EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER.
  • EDK2 variable PEI and RuntimeDxe walkers, via DeepWiki: data-pointer and next-header computation, and which State values are read.
  • UEFITool common/nvramparser.cpp and nvram.h, via DeepWiki: it accepts GUID-signed stores with Format == 0x5A without requiring HEALTHY, and parses FTW blocks separately. That disagreement with EDK2 is why change 2 reports both readings.

@morluto
morluto merged commit 6b269db into morluto:main Nov 27, 2026
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior enhancement New feature or request provider: uefi Analysis provider / engine: uefi

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Support TianoCore EDK2 variable stores (gEfiVariableGuid / gEfiAuthenticatedVariableGuid) in inspect_uefi_nvram

2 participants