Skip to content

Backport a few patches for v0.10.3 - #613

Open
stefanberger wants to merge 7 commits into
stable-0.10from
stable-0.10.next
Open

Backport a few patches for v0.10.3#613
stefanberger wants to merge 7 commits into
stable-0.10from
stable-0.10.next

Conversation

@stefanberger

@stefanberger stefanberger commented Sep 4, 2026

Copy link
Copy Markdown
Owner

Backport a few patches to v0.10.3.

Summary by CodeRabbit

  • Bug Fixes
    • Improved profile switching so failed changes reliably restore the previous profile.
    • Fixed command scanning to terminate correctly in all cases.
    • Added validation to reject oversized runtime profiles and invalid persistent data.
    • Improved handling of malformed object data by returning an error instead of continuing.
    • Corrected elliptic-curve validation when earlier input errors occur or no curve is selected.

Cast size_t i to ssize_t i to check for underrun. An underrun could never
occur since it is not possible that all commands are disabled.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
When rolling back after an unsuccessful switch to the new
attributes/algorithms/commands profile, use the maximum possible
StateFormatLevel value to set the old profile.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Rather than asserting, display an error log message in case an ANY_OBJECT
could not be unmarshalled.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Check the untrusted array_size of AuditCommandList and PPList against
a reasonable maximum value of 1024.

Artificially setting BYTE buf[0xffff], which would be the maximum value
array_size could get with the unmarshalling, does not cause any issues
(crash due to large on-stack buffer) on my Linux system.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Limit the size of a profile to 32kb. There is no reason that a valid
profile would have even close to 32kb. This also prevents issues in
String_Marshal() that assumes a reasonably sized string below 64kb.

Place the check for the size of the profile into GetParametersFromJSON
since this function is used by RuntimeProfileSet and RuntimeProfileTest.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
@coderabbitai

coderabbitai Bot commented Sep 4, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: 31de7fa9-e69f-493f-ab80-1c2c536a7b7e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: 71105f7a-8941-436d-baeb-82bd50823f29

📥 Commits

Reviewing files that changed from the base of the PR and between fd5b417 and 1467875.

📒 Files selected for processing (7)
  • src/tpm2/NVMarshal.c
  • src/tpm2/RuntimeAlgorithm.c
  • src/tpm2/RuntimeAttributes.c
  • src/tpm2/RuntimeCommands.c
  • src/tpm2/RuntimeProfile.c
  • src/tpm2/RuntimeProfile_fp.h
  • src/tpm2/Unmarshal.c

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

The changes add bounds checks for unmarshalled data and JSON profiles, propagate NVRAM object errors, correct ECC validation gating, preserve previous runtime profiles during rollback, and fix reverse scanning of enabled commands.

Changes

TPM validation and profile handling

Layer / File(s) Summary
Unmarshalling validation and error handling
src/tpm2/NVMarshal.c, src/tpm2/Unmarshal.c
Unmarshal functions reject array sizes above 1024, return ANY_OBJECT_Unmarshal failures, and limit ECC key-size checks to valid non-TPM_ECC_NONE curves after successful prior validation.
JSON profile size limit
src/tpm2/RuntimeProfile_fp.h, src/tpm2/RuntimeProfile.c
MAX_PROFILE_SIZE is defined as 32 KiB. GetParametersFromJSON rejects longer profiles before parsing.
Profile rollback state limits
src/tpm2/RuntimeAlgorithm.c, src/tpm2/RuntimeAttributes.c, src/tpm2/RuntimeCommands.c
Profile restoration calls use ~0 for the maximum state format level.
Enabled command index termination
src/tpm2/RuntimeCommands.c
RuntimeCommandsGetArraySize casts the reverse-loop index to ssize_t before comparison.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 14678

This backport adds input bounds checks, propagates unmarshalling failures, preserves prior profiles during rollback, and corrects command scanning and ECC validation gating. No concrete current-head merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 44.44% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 7 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately states the main change: backporting multiple patches for v0.10.3. It is concise and relevant to the six changes described.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch stable-0.10.next

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Check for rc == TPM_RC_SUCCESS before calling function to check whether
the EC algorithm is allowed by the profile. This is necessary since rc
could already have been set to TPM_RC_CURVE before. In case the function
call failed, it would again be set to TPM_RC_CURVE, which is unnecessary.
Also do not call the function when TPM_ECC_NONE was unmarshalled since
this would always fail and unmarshalling TPM_ECC_NONE would never work.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
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