Skip to content

Prevent excessive CPU use on corrupt MSI sector chains - #535

Open
mtrojnar wants to merge 1 commit into
masterfrom
fix/msi-sector-chain-cpu
Open

mtrojnar wants to merge 1 commit into
masterfrom
fix/msi-sector-chain-cpu

Conversation

@mtrojnar

Copy link
Copy Markdown
Owner

Pull Request Type

  • Bug fix

Related Issue

Issue number: N/A

Current Behavior

Malformed MSI sector chains can treat ENDOFCHAIN as a sector number, causing millions of unnecessary DIFAT-walk iterations during signing or verification.

New Behavior

Reject chain terminators and FAT sector numbers outside the header's declared range before walking the chain. Stop reading a mini stream once its requested bytes have been copied, avoiding an unnecessary lookup past its final sector.

Scope of Changes

MSI sector-chain validation and its release note.

Testing

  • Existing tests
  • New tests added
  • Manual testing

Release build succeeded with GCC 16.2 and OpenSSL 3.6.5. All 29 selected CTest checks passed: the MSI storage-tree tests and HTTP-server setup/cleanup (ctest -R '^(start_server|stop_server|msi_tree_.*)$' --output-on-failure).

License Declaration

  • I hereby agree to license my contribution under the project's license.

get_next_sector() rejected only values at or above FREESECT, so ENDOFCHAIN
was returned as if it were a sector number and locate_final_sector() kept
walking past the end of a chain instead of stopping at it.  The tiny
resulting FAT sector number, 0xFFFFFFFE divided by the entries per sector,
then made get_fat_sector_location() subtract entriesPerSector once per
loop iteration for millions of iterations, each resolving another sector.

On a 98 KiB file this costs roughly 0.4 seconds in a release build and
1.8 seconds with sanitizers.  Malformed MSI input therefore causes
unnecessary CPU work during signing and verification.

Treat ENDOFCHAIN and the other reserved markers as chain terminators, and
reject FAT sector numbers that the header does not account for before the
DIFAT walk, which bounds the loop by a validated value rather than by a
32-bit input.  read_mini_stream() also looked up a next mini sector after
copying the last bytes of a stream, unlike read_stream(); skip that lookup
so the stricter terminator check cannot reject valid streams.
@mtrojnar
mtrojnar requested a review from olszomal November 17, 2026 10:54
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