Skip to content

Tcgtpm v184 cmake#20

Closed
stefano-garzarella wants to merge 1 commit into
mainfrom
tcgtpm-v184-cmake
Closed

Tcgtpm v184 cmake#20
stefano-garzarella wants to merge 1 commit into
mainfrom
tcgtpm-v184-cmake

Conversation

@stefano-garzarella

@stefano-garzarella stefano-garzarella commented Oct 6, 2025

Copy link
Copy Markdown
Owner

Summary by Sourcery

Migrate libtcgtpm’s TPM reference implementation build to CMake with explicit library targets and integrate a new vendor command framework.

New Features:

  • Build the TPM reference implementation with CMake and define separate targets for core, platform, and two crypto libraries.
  • Introduce a new CMake subproject for vendor command handlers.
  • Implement a sample vendor test command (Vendor_TCG_Test) with its command list, dispatch logic, attributes, prototypes, and handler.

Enhancements:

  • Refactor Makefile to use a CMake build directory and explicit LIBTPM_TARGET, LIBPLATFORM_TARGET, LIBTPMBIGNUM_TARGET, and LIBBNMATH_TARGET variables.
  • Update TpmConfiguration headers to add debug and trace macros, new error codes, secure channel support, and remove stale build switches and files.
  • Rename and reorganize include paths (e.g., tpm_public headers) and extend CMakeLists in TpmConfiguration to install vendor command headers and include the new handlers directory.
  • Remove deprecated VendorInfo.h references and prune obsolete configuration headers.

CI:

  • Update GitHub Actions workflows to install and use cmake for building the TPM reference implementation.

Documentation:

  • Change installation instructions to require cmake instead of autoconf, automake, and pkg-config.

Summary by CodeRabbit

  • Chores

    • Migrated build system from autotools to CMake; CI workflows updated to install CMake and the new toolchain.
    • Centralized build output into a dedicated build directory, introduced new crypto library artifacts, and improved clean/distclean behavior.
  • Documentation

    • Updated installation prerequisites and package list to reflect the CMake-based build and required compilers/tools.

@sourcery-ai

sourcery-ai Bot commented Oct 6, 2025

Copy link
Copy Markdown

Reviewer's Guide

This PR overhauls the libtcgtpm build by migrating the TPM 2.0 reference implementation from autotools to CMake, defines new cryptolib build targets, refactors TpmConfiguration headers and CMake modules, introduces a Vendor_TCG_Test command module, and updates documentation and CI workflows to reflect the new CMake-based workflow.

Class diagram for Vendor_TCG_Test command integration

classDiagram
    class Vendor_TCG_Test_In {
        +TPM2B_DATA inputData
    }
    class Vendor_TCG_Test_Out {
        +TPM2B_DATA outputData
    }
    class Vendor_TCG_Test_Entry {
        +operator()(Vendor_TCG_Test_In* in, Vendor_TCG_Test_Out* out): TPM_RC
    }
    class Vendor_TCG_Test_COMMAND_DESCRIPTOR_t {
        +Vendor_TCG_Test_Entry* entry
        +UINT16 inSize
        +UINT16 outSize
        +UINT16 offsetOfTypes
        +BYTE types[4]
    }
    Vendor_TCG_Test_Entry <|-- Vendor_TCG_Test_COMMAND_DESCRIPTOR_t
    Vendor_TCG_Test_In <|-- Vendor_TCG_Test_COMMAND_DESCRIPTOR_t
    Vendor_TCG_Test_Out <|-- Vendor_TCG_Test_COMMAND_DESCRIPTOR_t
Loading

File-Level Changes

Change Details Files
Migrate TPM build to CMake and introduce new cryptolib targets
  • Define TCGTPM_BUILD_DIR and replace bootstrap/configure steps with a CMake invocation
  • Introduce LIBBNMATH_TARGET and LIBTPMBIGNUM_TARGET and add them to LIBS
  • Update library build rules for libbnmath, libtpmbignum, libtpm, libplatform
  • Adjust clean and distclean targets to operate on the CMake build directory
libtcgtpm/Makefile
Enhance TpmConfiguration CMake setup and install vendor commands
  • Remove VendorInfo installation and add install rules for VendorCommands headers
  • Export CMake targets for TpmConfiguration and add TpmVendorCommandHandlers subdirectory
  • Create a CMakeLists.txt for the TpmVendorCommandHandlers module
libtcgtpm/deps/TpmConfiguration/CMakeLists.txt
libtcgtpm/deps/TpmConfiguration/TpmVendorCommandHandlers/CMakeLists.txt
Refine TpmConfiguration headers for debug, simulation, and feature toggles
  • Add ENABLE_TPM_DEBUG_PRINT, ENABLE_TPM_DEBUG_TRACE, ENABLE_CRYPTO_DEBUG flags
  • Toggle CRYPTO_LIB_REPORTING and CERTIFYX509_DEBUG based on SIMULATION and DEBUG
  • Rename include path to <tpm_public/CompilerDependencies.h> and remove unused bit-field defines
  • Define MAX_VENDOR_PROPERTY and SEC_CHANNEL_SUPPORT
  • Add new error codes FATAL_ERROR_NV_INIT, FATAL_ERROR_CRYPTO_INIT, FATAL_ERROR_NO_INIT
libtcgtpm/deps/TpmConfiguration/TpmConfiguration/TpmBuildSwitches.h
libtcgtpm/deps/TpmConfiguration/TpmConfiguration/TpmProfile_CommandList.h
libtcgtpm/deps/TpmConfiguration/TpmConfiguration/TpmProfile_Common.h
libtcgtpm/deps/TpmConfiguration/TpmConfiguration/TpmProfile_ErrorCodes.h
libtcgtpm/deps/TpmConfiguration/TpmConfiguration/TpmProfile.h
Introduce Vendor_TCG_Test command implementation and inline dispatch data
  • Add VendorCommandList.h to define CC_Vendor_TCG_Test and command count
  • Provide prototypes header for Vendor_TCG_Test_fp.h
  • Add .inl files for command attributes, dispatch structures, dispatch switch, and handle process
  • Implement the Vendor_TCG_Test handler in TpmVendorCommandHandlers/Vendor_TCG_Test.c
libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorCommands/VendorCommandList.h
libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorCommands/prototypes/Vendor_TCG_Test_fp.h
libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorCommands/CommandAttributeData_s_ccAttr.inl
libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorCommands/CommandAttributeData_s_commandAttributes.inl
libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorCommands/CommandDispatchData_CommandStructures.inl
libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorCommands/CommandDispatchData_s_CommandDataArray.inl
libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorCommands/CommandDispatcher.inl
libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorCommands/HandleProcess.inl
libtcgtpm/deps/TpmConfiguration/TpmVendorCommandHandlers/Vendor_TCG_Test.c
Update documentation and CI workflows to use CMake
  • Replace autoconf and automake with cmake in install dependencies
  • Update INSTALL.md to list cmake as a requirement
  • Adjust GitHub workflows (publish-docs, qemu, rust) to install cmake instead of autoconf/automake
Documentation/docs/installation/INSTALL.md
.github/workflows/publish-docs.yml
.github/workflows/qemu.yml
.github/workflows/rust.yml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `libtcgtpm/deps/TpmConfiguration/TpmVendorCommandHandlers/CMakeLists.txt:4-7` </location>
<code_context>
+##########################################################
+# DO NOT MODIFY - TPM Configuration Library
+##########################################################
+# The contents of the source files may be modified to specify any valid
+# desired configuraton.  However, the CMake library name "TpmVendorCommands"
+# is required by the CoreLib to reference this project.  Recommend making
+# no changes in this file.
</code_context>

<issue_to_address>
**issue (typo):** Typo in comment: 'configuraton' should be 'configuration'.

Please update the comment to fix the spelling error.

```suggestion
# The contents of the source files may be modified to specify any valid
# desired configuration.  However, the CMake library name "TpmVendorCommands"
# is required by the CoreLib to reference this project.  Recommend making
# no changes in this file.
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +4 to +7
# The contents of the source files may be modified to specify any valid
# desired configuraton. However, the CMake library name "TpmVendorCommands"
# is required by the CoreLib to reference this project. Recommend making
# no changes in this file.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (typo): Typo in comment: 'configuraton' should be 'configuration'.

Please update the comment to fix the spelling error.

Suggested change
# The contents of the source files may be modified to specify any valid
# desired configuraton. However, the CMake library name "TpmVendorCommands"
# is required by the CoreLib to reference this project. Recommend making
# no changes in this file.
# The contents of the source files may be modified to specify any valid
# desired configuration. However, the CMake library name "TpmVendorCommands"
# is required by the CoreLib to reference this project. Recommend making
# no changes in this file.

@coderabbitai

coderabbitai Bot commented Oct 6, 2025

Copy link
Copy Markdown

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Migrates the TPM 2.0 build from autotools to CMake: CI workflows and docs replace autotools packages with cmake; libtcgtpm Makefile is restructured to use a centralized TCGTPM_BUILD_DIR, new library target variables, and CMake-based configuration and build rules.

Changes

Cohort / File(s) Summary
CI/CD Workflow Updates
\.github/workflows/publish-docs.yml, \.github/workflows/qemu.yml, \.github/workflows/rust.yml
Replace dependency installation autoconf autoconf-archive pkg-config build-essential automake with build-essential cmake pkg-config (remove autotools, add cmake).
Installation Documentation
Documentation/docs/installation/INSTALL.md
OpenSUSE prerequisites updated: removed autoconf, autoconf-archive, automake; added gcc-c++ and cmake; adjusted toolchain/package list accordingly.
Build System Migration
libtcgtpm/Makefile
Rework Makefile to use TCGTPM_BUILD_DIR and CMake instead of bootstrap/configure; introduce targets LIBTPM_TARGET, LIBPLATFORM_TARGET, LIBTPMBIGNUM_TARGET, LIBBNMATH_TARGET and corresponding paths, update LIBS, clean/distclean, and build dependency rules to reference centralized build artifacts.

Sequence Diagram(s)

sequenceDiagram
    participant CI as CI Workflows
    participant Make as Top-level Make
    participant CMake as CMake (TCGTPM_BUILD_DIR)
    participant Lib as Libraries (TPM, Platform, Crypto)
    participant Art as Build Artifacts

    rect rgb(241,250,255)
    Note over CI,Make: New CI installs cmake & pkg-config
    CI->>Make: invoke build
    end

    rect rgb(255,249,240)
    Note over Make,CMake: New Flow (CMake-based)
    Make->>CMake: run cmake in TCGTPM_BUILD_DIR (pass CFLAGS, crypto paths, config dir)
    CMake->>Lib: configure and build LIBBNMATH, LIBTPMBIGNUM, LIBTPM, LIBPLATFORM
    Lib->>Art: produce centralized artifacts under TCGTPM_BUILD_DIR
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 I hopped from autotools' maze,
To CMake's clear and sunny ways,
One build dir snug, libs in a row,
Crypto bundled, ready to go,
I nibble bugs and dance — bravo! 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title Check ❓ Inconclusive The PR title "Tcgtpm v184 cmake" references a real component of the changes — the migration to CMake — and is not misleading. However, the title is somewhat vague and generic. It mentions "cmake" but does not clearly communicate that this is a BUILD SYSTEM MIGRATION or what specific change is being made. A developer scanning the history might not immediately understand that the primary objective is replacing autotools and Makefile-based builds with CMake; the title could equally suggest just a version bump or incremental cmake support addition. The title would be significantly clearer if it explicitly indicated the migration nature of the change, such as "Migrate TPM reference implementation build to CMake." Consider revising the title to be more descriptive and action-oriented, such as "Migrate TPM reference implementation build from autotools to CMake" or "Switch libtcgtpm build system to CMake." This would make the primary intent of the changeset immediately clear to someone scanning the commit history and better distinguish this from other cmake-related changes.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch tcgtpm-v184-cmake

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 and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 7

♻️ Duplicate comments (1)
libtcgtpm/deps/TpmConfiguration/TpmVendorCommandHandlers/CMakeLists.txt (1)

4-7: Correct the typo in the guidance comment.

Line 5 spells “configuration” incorrectly; please fix the comment copy.

Apply this diff:

-# desired configuraton.  However, the CMake library name "TpmVendorCommands"
+# desired configuration.  However, the CMake library name "TpmVendorCommands"
🧹 Nitpick comments (2)
libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorCommands/CommandAttributeData_s_ccAttr.inl (1)

13-16: Consider adding inline parameter documentation.

The TPMA_CC_INITIALIZER call and conditional logic are correct. For improved maintainability, consider adding a brief inline comment documenting what each of the nine parameters represents, especially since this is vendor-specific configuration.

Example:

 #if (PAD_LIST || CC_Vendor_TCG_Test)
 // TPM_CC_Vendor_TCG_Test
+// TPMA_CC_INITIALIZER(commandCode, commandIndex, nv, extensive, flushed, cHandles, rHandle, V, Res)
 TPMA_CC_INITIALIZER(0x0000, 0, 0, 0, 0, 0, 0, 1, 0),
 #endif
libtcgtpm/deps/TpmConfiguration/TpmConfiguration/TpmProfile_CommandList.h (1)

166-167: Consider adding documentation for new command macros.

The new CC_ReadOnlyControl and CC_PolicyTransportSPDM command macros lack explanatory comments. For consistency with the file's existing style (see lines 28-42), consider adding brief comments describing the purpose of these commands or why they are enabled.

Example:

+// ReadOnlyControl command allows managing read-only control state
 #define CC_ReadOnlyControl            CC_YES
+// PolicyTransportSPDM enables policy-based SPDM transport
 #define CC_PolicyTransportSPDM        CC_YES
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a3982c5 and 308b27a.

📒 Files selected for processing (24)
  • .github/workflows/publish-docs.yml (1 hunks)
  • .github/workflows/qemu.yml (1 hunks)
  • .github/workflows/rust.yml (1 hunks)
  • Documentation/docs/installation/INSTALL.md (1 hunks)
  • libtcgtpm/Makefile (2 hunks)
  • libtcgtpm/deps/TpmConfiguration/CMakeLists.txt (1 hunks)
  • libtcgtpm/deps/TpmConfiguration/TpmConfiguration/TpmBuildSwitches.h (4 hunks)
  • libtcgtpm/deps/TpmConfiguration/TpmConfiguration/TpmProfile.h (0 hunks)
  • libtcgtpm/deps/TpmConfiguration/TpmConfiguration/TpmProfile_CommandList.h (2 hunks)
  • libtcgtpm/deps/TpmConfiguration/TpmConfiguration/TpmProfile_Common.h (2 hunks)
  • libtcgtpm/deps/TpmConfiguration/TpmConfiguration/TpmProfile_ErrorCodes.h (1 hunks)
  • libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorCommands/CommandAttributeData_s_ccAttr.inl (1 hunks)
  • libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorCommands/CommandAttributeData_s_commandAttributes.inl (1 hunks)
  • libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorCommands/CommandDispatchData_CommandStructures.inl (1 hunks)
  • libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorCommands/CommandDispatchData_s_CommandDataArray.inl (1 hunks)
  • libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorCommands/CommandDispatcher.inl (1 hunks)
  • libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorCommands/HandleProcess.inl (1 hunks)
  • libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorCommands/VendorCommandList.h (1 hunks)
  • libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorCommands/prototypes/Vendor_TCG_Test_fp.h (1 hunks)
  • libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorInfo.h (0 hunks)
  • libtcgtpm/deps/TpmConfiguration/TpmVendorCommandHandlers/CMakeLists.txt (1 hunks)
  • libtcgtpm/deps/TpmConfiguration/TpmVendorCommandHandlers/Vendor_TCG_Test.c (1 hunks)
  • libtcgtpm/deps/tpm-20-ref (1 hunks)
  • scripts/container/opensuse-rust.docker (1 hunks)
💤 Files with no reviewable changes (2)
  • libtcgtpm/deps/TpmConfiguration/TpmConfiguration/TpmProfile.h
  • libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorInfo.h
🔇 Additional comments (29)
libtcgtpm/deps/TpmConfiguration/TpmConfiguration/TpmProfile_ErrorCodes.h (1)

45-48: Verify usage of new error codes.

The new error code definitions are well-structured with sequential numbering and consistent naming. Since this appears to be a submodule update (per the PR summary), ensure these error codes are properly handled in the consuming code where they're raised.

Run the following script to verify usage:

libtcgtpm/deps/TpmConfiguration/TpmConfiguration/TpmProfile_Common.h (2)

175-176: Verify the vendor property constraint is properly enforced.

The comment states that MAX_VENDOR_PROPERTY "must currently be 1," but it's unclear whether this constraint is validated elsewhere in the codebase. Given that vendor command scaffolding is being introduced in this PR, ensure that:

  • This value aligns with the actual number of vendor properties being supported
  • The constraint is enforced at compile-time or runtime to prevent misconfigurations

Run the following script to check for related vendor property definitions and usages:


225-230: Verify PolicyTransportSPDM implementation is complete.

Enabling SEC_CHANNEL_SUPPORT introduces secure channel functionality with PolicyTransportSPDM. Please confirm that:

  • The referenced CC_PolicyTransportSPDM command is fully implemented
  • The PolicyTransportSPDM feature is production-ready and tested
  • This enablement is intentional for the current build configuration

Run the following script to verify the PolicyTransportSPDM implementation:

libtcgtpm/deps/TpmConfiguration/TpmConfiguration/TpmBuildSwitches.h (5)

75-75: Verify that disabling CERTIFYX509_DEBUG is intentional.

CERTIFYX509_DEBUG was changed from (YES * DEBUG) to (NO * DEBUG), which effectively disables it even when DEBUG is enabled. Please confirm this is intentional and not a mistake that should be (YES * DEBUG).


157-158: LGTM!

The LONGJMP_SUPPORTED macro is a clear feature flag with a reasonable default value.


54-63: Verify that SIMULATION cannot be enabled in production builds.

ENABLE_CRYPTO_DEBUG is controlled by ENABLE_TPM_DEBUG_PRINT, which is enabled when SIMULATION is YES. The comment on line 62 explicitly states this is "entirely insecure" because it prints actual crypto values. Ensure that SIMULATION is always NO in production builds to prevent this security risk.

Run the following script to verify build configurations and usage of SIMULATION:


195-195: Verify the new include path exists and is correct.

The include path was updated from <public/CompilerDependencies.h> to <tpm_public/CompilerDependencies.h> as part of the CMake migration. Ensure this path exists and the header file is accessible at the new location.

Run the following script to verify the new include path:


51-197: Verify that removed macros are not referenced elsewhere.

According to the AI summary, several macros were removed from this file: TABLE_DRIVEN_DISPATCH, USE_MARSHALING_DEFINES, COMPRESSED_LISTS, and USE_BIT_FIELD_STRUCTURES. Ensure these removals don't break any dependent code.

Run the following script to check for references to the removed macros:

libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorCommands/CommandAttributeData_s_ccAttr.inl (2)

1-9: LGTM!

The header comments clearly explain the file's purpose and usage constraints, including the important warning about array initializer context and the rationale for the .INL extension.


10-12: Effective safety guard.

The preprocessor check ensures this file is only included in the correct context, preventing misuse and providing a clear error message if included elsewhere.

libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorCommands/HandleProcess.inl (1)

8-9: Verify that the empty case statement is intentional.

The case for TPM_CC_Vendor_TCG_Test only contains a break without calling any handler function. According to the PR summary, the corresponding vendor command handler logic is implemented in Vendor_TCG_Test.c. Confirm whether:

  • This is intentional scaffolding for future implementation
  • The handler call is missing and should be added
  • The command is processed elsewhere in the flow

Run the following script to check for handler implementations:

libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorCommands/CommandDispatcher.inl (1)

11-14: Verify buffer allocation success.

While MemoryGetInBuffer and MemoryGetOutBuffer are likely guaranteed to succeed or handle errors internally in TPM reference code, consider verifying that these functions cannot return NULL or document this assumption.

libtcgtpm/deps/TpmConfiguration/TpmVendorCommandHandlers/Vendor_TCG_Test.c (2)

1-7: LGTM! Conditional compilation structure is appropriate.

The include directives and conditional compilation guard follow standard patterns for vendor-specific TPM command handlers.


13-13: Verify data structure assignment safety.

The assignment out->outputData = in->inputData performs a direct copy. Depending on the types of inputData and outputData, verify that:

  • If they are TPM2B buffer structures, size constraints are enforced to prevent buffer overruns
  • If they are pointers, the lifetime and ownership semantics are correct
  • If they contain nested structures or buffers, deep copying is handled appropriately

Run the following script to examine the struct definitions and identify potential safety concerns:

libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorCommands/CommandAttributeData_s_commandAttributes.inl (2)

1-12: LGTM!

The file structure, comments, and include guard are well-implemented. The include guard properly ensures the file is only included in the correct context within CommandAttributeData.h.


13-16: Verify the command code comment and attribute expression.

The comment on line 14 states 0x0000 for CC_Vendor_TCG_Test, which seems atypical for vendor TPM commands that usually occupy higher command code ranges. Additionally, confirm that the arithmetic expression CC_Vendor_TCG_Test * (DECRYPT_2 + ENCRYPT_2) correctly encodes the intended command attributes for this vendor command.

Run the following script to examine the command code definition and attribute macros:

libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorCommands/CommandDispatchData_s_CommandDataArray.inl (1)

1-15: LGTM! Include file follows the expected pattern.

The structure is correct for an .INL file designed to be included in an array initializer. The preprocessor guard ensures proper usage context, the conditional compilation is clear, and the trailing comma on line 14 is appropriate for an array element.

Verify that _Vendor_TCG_TestDataAddress and COMMAND_DESCRIPTOR_t are properly defined:

libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorCommands/prototypes/Vendor_TCG_Test_fp.h (4)

2-5: LGTM!

The conditional compilation guard and include guard pattern is correct and follows standard conventions for TPM private prototypes.


19-20: LGTM!

The response code modifier follows the standard TPM pattern for parameter-specific error codes.


23-24: LGTM!

The function prototype follows the standard TPM command handler signature with appropriate return type and parameter pointers.


7-17: Verify that TPM types are defined before this header is included.

The structures use TPM2B_DATA without including the header that defines it. Ensure this header is always included after the base TPM type definitions (e.g., Tpm.h or TpmTypes.h).

Run the following script to check the include order and verify that TPM2B_DATA is defined in the expected headers:

libtcgtpm/deps/TpmConfiguration/TpmConfiguration/TpmProfile_CommandList.h (2)

15-21: LGTM! Documentation and formatting improvements.

The clarified comment about the CC_YES/CC_NO debug feature and the clang-format directives properly document the formatting boundaries for this section.


169-171: LGTM! Formatting directive and vendor command include.

The clang-format on directive properly closes the formatting boundary, and the include of VendorCommandList.h aligns with the PR's vendor command infrastructure changes.

libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorCommands/CommandDispatchData_CommandStructures.inl (2)

14-41: LGTM with minor notes above.

The command descriptor structure and conditional compilation logic are well-designed:

  • Proper use of designated initializers for clarity
  • Correct sizeof() and offsetof() usage for portability
  • Clean conditional macro pattern enabling unconditional use
  • Types array marshaling descriptor follows expected pattern

The implementation correctly sets up vendor command dispatch metadata for table-driven command processing.


29-36: Verify identifier naming compliance with C/C++ standards.

The variable _Vendor_TCG_TestData begins with an underscore followed by an uppercase letter. Per C/C++ standards, such identifiers are reserved for the implementation in the global namespace. While this may be intentional for internal symbols, please verify that this naming convention aligns with your project's guidelines and doesn't conflict with implementation-reserved identifiers.

Run the following script to check for similar naming patterns in the codebase:

.github/workflows/publish-docs.yml (1)

30-31: CMake dependency switch looks good.

Dropping the autotools stack in favor of build-essential and cmake aligns with the new build flow. No issues noticed.

.github/workflows/qemu.yml (1)

115-115: CMake dependency update makes sense.

Switching the TPMLib build to CMake makes build-essential + cmake sufficient here, so the trimmed package list looks good.

.github/workflows/rust.yml (1)

31-32: CMake dependency update looks good

Swapping in cmake alongside build-essential aligns with the new CMake-based TPM build flow; no additional packages appear necessary.

scripts/container/opensuse-rust.docker (1)

26-27: LGTM! Migration to CMake looks correct.

The replacement of autotools packages (autoconf, autoconf-archive, pkg-config, automake, perl) with cmake aligns with the PR's objective to migrate the TPM library build system to CMake.

Please verify that the cmake package alone provides all necessary build capabilities for the TPM library without the removed autotools dependencies. You may also want to confirm whether the CMakeLists.txt files require a minimum cmake version and whether the openSUSE cmake package meets that requirement.

Comment on lines 50 to +61
export_targets_cmake_file(${PROJECT_NAME})

add_subdirectory(TpmVendorCommandHandlers)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Keep export_targets_cmake_file() as the final step.

export_targets_cmake_file(${PROJECT_NAME}) configures the package export and the file itself is annotated as “LAST”. By invoking add_subdirectory(TpmVendorCommandHandlers) afterwards, the handler targets are defined only after the export has already run, so they are not captured in the generated targets file/install set. Please move the add_subdirectory call above the export (or otherwise ensure the export runs last).

🤖 Prompt for AI Agents
In libtcgtpm/deps/TpmConfiguration/CMakeLists.txt around lines 59-61, the call
to export_targets_cmake_file(${PROJECT_NAME}) currently runs before
add_subdirectory(TpmVendorCommandHandlers), so the handler targets defined in
that subdirectory are not included in the generated export/install targets; move
the add_subdirectory(TpmVendorCommandHandlers) line so it appears before the
export_targets_cmake_file(${PROJECT_NAME}) call (or otherwise ensure the export
invocation happens last) so that all targets from the subdirectory are defined
and captured in the exported targets file.

// entry per vendor command. See the private Tpm header CommandAttributeData.h for
// more info.
// (This is why the file has the .INL extension, it's not a normal header.
//

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix the incomplete sentence.

The opening parenthesis on Line 9 is never closed, making the comment grammatically incomplete.

Apply this diff to fix the comment:

-// (This is why the file has the .INL extension, it's not a normal header.
+// (This is why the file has the .INL extension, it's not a normal header.)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
//
// TCG Vendor Command Structures - used in command dispatch table
#ifndef _COMMAND_TABLE_DISPATCH_
#error "Do not include this file without defining _COMMAND_TABLE_DISPATCH_"
#endif
// (This is why the file has the .INL extension, it's not a normal header.)
🤖 Prompt for AI Agents
libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorCommands/CommandDispatchData_CommandStructures.inl
around line 9: the comment contains an unclosed opening parenthesis leaving the
sentence incomplete; edit the comment on line 9 to close the parenthesis and
complete the sentence (or remove the stray parenthesis), ensuring the comment
reads as a grammatically complete sentence with matched parentheses.

Comment on lines +23 to +24
if(result != TPM_RC_SUCCESS)
return result;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Inconsistent error handling may skip cleanup code.

Line 24 returns directly on handler error, while lines 16 and 20 use the goto Exit pattern. If the Exit label (defined outside this inline file) performs cleanup operations such as releasing buffers or resetting state, returning early here bypasses that cleanup, potentially causing resource leaks or corrupted state.

Apply this diff to maintain consistent error handling:

-    result = TPM2_Vendor_TCG_Test(in, out);
-    if(result != TPM_RC_SUCCESS)
-        return result;
+    result = TPM2_Vendor_TCG_Test(in, out);
+    EXIT_IF_ERROR(result);

Alternatively, if the EXIT_IF_ERROR macro is not available without a parameter, use:

-    if(result != TPM_RC_SUCCESS)
-        return result;
+    if(result != TPM_RC_SUCCESS)
+        goto Exit;

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In
libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorCommands/CommandDispatcher.inl
around lines 23-24, the handler error is returned directly which bypasses the
external Exit label cleanup; change the direct return to follow the same pattern
as lines 16 and 20 by setting the error return value and branching to the Exit
label (or replace the return with the appropriate EXIT_IF_ERROR /
EXIT_OK_IF_ERROR macro invocation) so that the function always jumps to Exit for
cleanup before returning.

@@ -0,0 +1,10 @@
// This file contains an inlined portion of the HandleProcssor switch statement.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix typo in comment.

"HandleProcssor" should be "HandleProcessor".

Apply this diff:

-// This file contains an inlined portion of the HandleProcssor switch statement.
+// This file contains an inlined portion of the HandleProcessor switch statement.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// This file contains an inlined portion of the HandleProcssor switch statement.
// This file contains an inlined portion of the HandleProcessor switch statement.
🤖 Prompt for AI Agents
In
libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorCommands/HandleProcess.inl
around lines 1 to 1, there is a typo in the comment "HandleProcssor" which
should read "HandleProcessor"; update the comment text to correct the spelling
to "HandleProcessor" and ensure any related occurrences in this file are
similarly corrected for consistency.

Comment on lines +31 to +33
target_include_directories(TpmVendorCommands_Handlers PRIVATE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../tpm/include>"
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Fix the private include path.

Line 32 resolves ${CMAKE_CURRENT_SOURCE_DIR}/../../tpm/include to .../deps/tpm/include, which does not exist; the headers live under TpmConfiguration/tpm/include. This breaks compilation as soon as the handler sources include those headers.

Apply this diff:

 target_include_directories(TpmVendorCommands_Handlers PRIVATE
-    "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../tpm/include>"
+    "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../tpm/include>"
 )
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
target_include_directories(TpmVendorCommands_Handlers PRIVATE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../tpm/include>"
)
target_include_directories(TpmVendorCommands_Handlers PRIVATE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../tpm/include>"
)
🤖 Prompt for AI Agents
In libtcgtpm/deps/TpmConfiguration/TpmVendorCommandHandlers/CMakeLists.txt
around lines 31-33, the PRIVATE include path currently points to
../../tpm/include which resolves to deps/tpm/include (nonexistent); change the
include path to the correct relative location
${CMAKE_CURRENT_SOURCE_DIR}/../tpm/include (or adjust the
target_include_directories/INCLUDE directive to reference
TpmConfiguration/tpm/include) so the handler sources can find the headers.

Comment on lines +8 to +15
TPM_RC
TPM2_Vendor_TCG_Test(Vendor_TCG_Test_In* in, // IN: input parameter list
Vendor_TCG_Test_Out* out // OUT: output parameter list
)
{
out->outputData = in->inputData;
return TPM_RC_SUCCESS;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Add NULL pointer validation for input/output parameters.

The function dereferences in and out without validating that they are non-NULL. In TPM command handlers, input validation is critical to prevent crashes or undefined behavior when the dispatcher invokes the handler with invalid parameters.

Apply this diff to add validation:

 TPM_RC
 TPM2_Vendor_TCG_Test(Vendor_TCG_Test_In*  in,  // IN: input parameter list
                      Vendor_TCG_Test_Out* out  // OUT: output parameter list
 )
 {
+    if (in == NULL || out == NULL)
+        return TPM_RC_FAILURE;
+
     out->outputData = in->inputData;
     return TPM_RC_SUCCESS;
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
TPM_RC
TPM2_Vendor_TCG_Test(Vendor_TCG_Test_In* in, // IN: input parameter list
Vendor_TCG_Test_Out* out // OUT: output parameter list
)
{
out->outputData = in->inputData;
return TPM_RC_SUCCESS;
}
TPM_RC
TPM2_Vendor_TCG_Test(Vendor_TCG_Test_In* in, // IN: input parameter list
Vendor_TCG_Test_Out* out // OUT: output parameter list
)
{
if (in == NULL || out == NULL)
return TPM_RC_FAILURE;
out->outputData = in->inputData;
return TPM_RC_SUCCESS;
}
🤖 Prompt for AI Agents
In libtcgtpm/deps/TpmConfiguration/TpmVendorCommandHandlers/Vendor_TCG_Test.c
around lines 8-15, the function dereferences the pointers in and out without
validation; add NULL checks at the top of the function to verify both input
pointers are non-NULL and if either is NULL, return an appropriate TPM error
(e.g., TPM_RC_FAILURE or TPM_RC_BAD_PARAMETER) before any dereference, ensuring
any required cleanup or logging is done prior to returning.

Comment thread libtcgtpm/Makefile Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
libtcgtpm/Makefile (1)

31-180: Release build inherits debug CFLAGS

$(TCGTPM_MAKEFILE) is generated only once per build directory. The first configure (typically the debug build) records CMAKE_C_FLAGS in the cache; when we later invoke the Makefile with RELEASE=1, CMake is not re-run, so the release artifacts continue to use the debug flags (-g -O0 -DDEBUG=YES). As a result the release images are built unoptimized.

Please keep separate build directories (or another stamp) per variant so that a release configure actually applies the release flags. One option:

-TCGTPM_BUILD_DIR = $(TCGTPM_DIR)/build
+TCGTPM_BUILD_VARIANT = $(if $(RELEASE),release,debug)
+TCGTPM_BUILD_DIR = $(TCGTPM_DIR)/build/$(TCGTPM_BUILD_VARIANT)
@@
-distclean: clean
-	rm -f $(OPENSSL_MAKEFILE)
-	rm -rf $(TCGTPM_BUILD_DIR)
+distclean: clean
+	rm -f $(OPENSSL_MAKEFILE)
+	rm -rf $(TCGTPM_DIR)/build
♻️ Duplicate comments (3)
libtcgtpm/deps/TpmConfiguration/TpmVendorCommandHandlers/Vendor_TCG_Test.c (1)

8-15: Validate pointers before dereference

TPM2_Vendor_TCG_Test dereferences in and out without verifying they are non-NULL. A NULL pointer from the dispatcher will crash the handler. Please guard both pointers and return an appropriate TPM error before using them.

 TPM_RC
 TPM2_Vendor_TCG_Test(Vendor_TCG_Test_In*  in,  // IN: input parameter list
                      Vendor_TCG_Test_Out* out  // OUT: output parameter list
 )
 {
+    if (in == NULL || out == NULL)
+        return TPM_RC_FAILURE;
+
     out->outputData = in->inputData;
     return TPM_RC_SUCCESS;
 }
libtcgtpm/deps/TpmConfiguration/CMakeLists.txt (1)

59-61: Keep export_targets_cmake_file() as the final step.

export_targets_cmake_file(${PROJECT_NAME}) should run after all targets are defined. Since add_subdirectory(TpmVendorCommandHandlers) is called after the export, the handler targets defined in that subdirectory are not included in the generated export/install targets. Move the add_subdirectory call to appear before the export_targets_cmake_file call.

libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorCommands/CommandDispatchData_CommandStructures.inl (1)

9-9: Fix the incomplete sentence.

The opening parenthesis is never closed, making the comment grammatically incomplete.

Apply this diff to fix the comment:

-// (This is why the file has the .INL extension, it's not a normal header.
+// (This is why the file has the .INL extension, it's not a normal header.)
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 308b27a and d186704.

📒 Files selected for processing (24)
  • .github/workflows/publish-docs.yml (1 hunks)
  • .github/workflows/qemu.yml (1 hunks)
  • .github/workflows/rust.yml (1 hunks)
  • Documentation/docs/installation/INSTALL.md (1 hunks)
  • libtcgtpm/Makefile (2 hunks)
  • libtcgtpm/deps/TpmConfiguration/CMakeLists.txt (1 hunks)
  • libtcgtpm/deps/TpmConfiguration/TpmConfiguration/TpmBuildSwitches.h (4 hunks)
  • libtcgtpm/deps/TpmConfiguration/TpmConfiguration/TpmProfile.h (0 hunks)
  • libtcgtpm/deps/TpmConfiguration/TpmConfiguration/TpmProfile_CommandList.h (2 hunks)
  • libtcgtpm/deps/TpmConfiguration/TpmConfiguration/TpmProfile_Common.h (2 hunks)
  • libtcgtpm/deps/TpmConfiguration/TpmConfiguration/TpmProfile_ErrorCodes.h (1 hunks)
  • libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorCommands/CommandAttributeData_s_ccAttr.inl (1 hunks)
  • libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorCommands/CommandAttributeData_s_commandAttributes.inl (1 hunks)
  • libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorCommands/CommandDispatchData_CommandStructures.inl (1 hunks)
  • libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorCommands/CommandDispatchData_s_CommandDataArray.inl (1 hunks)
  • libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorCommands/CommandDispatcher.inl (1 hunks)
  • libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorCommands/HandleProcess.inl (1 hunks)
  • libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorCommands/VendorCommandList.h (1 hunks)
  • libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorCommands/prototypes/Vendor_TCG_Test_fp.h (1 hunks)
  • libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorInfo.h (0 hunks)
  • libtcgtpm/deps/TpmConfiguration/TpmVendorCommandHandlers/CMakeLists.txt (1 hunks)
  • libtcgtpm/deps/TpmConfiguration/TpmVendorCommandHandlers/Vendor_TCG_Test.c (1 hunks)
  • libtcgtpm/deps/tpm-20-ref (1 hunks)
  • scripts/container/opensuse-rust.docker (1 hunks)
💤 Files with no reviewable changes (2)
  • libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorInfo.h
  • libtcgtpm/deps/TpmConfiguration/TpmConfiguration/TpmProfile.h
🚧 Files skipped from review as they are similar to previous changes (13)
  • libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorCommands/CommandAttributeData_s_ccAttr.inl
  • libtcgtpm/deps/TpmConfiguration/TpmConfiguration/TpmProfile_ErrorCodes.h
  • libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorCommands/HandleProcess.inl
  • libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorCommands/VendorCommandList.h
  • libtcgtpm/deps/tpm-20-ref
  • Documentation/docs/installation/INSTALL.md
  • libtcgtpm/deps/TpmConfiguration/TpmVendorCommandHandlers/CMakeLists.txt
  • .github/workflows/qemu.yml
  • libtcgtpm/deps/TpmConfiguration/TpmConfiguration/TpmBuildSwitches.h
  • .github/workflows/publish-docs.yml
  • libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorCommands/CommandAttributeData_s_commandAttributes.inl
  • libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorCommands/CommandDispatcher.inl
  • libtcgtpm/deps/TpmConfiguration/TpmConfiguration/TpmProfile_CommandList.h
🧰 Additional context used
🧬 Code graph analysis (1)
libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorCommands/prototypes/Vendor_TCG_Test_fp.h (1)
libtcgtpm/deps/TpmConfiguration/TpmVendorCommandHandlers/Vendor_TCG_Test.c (1)
  • TPM2_Vendor_TCG_Test (8-15)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: QEMU NOCC boot test
  • GitHub Check: Check
  • GitHub Check: Sourcery review
🔇 Additional comments (6)
libtcgtpm/deps/TpmConfiguration/TpmConfiguration/TpmProfile_Common.h (2)

1-232: No references to removed macros found
Verified that MOST_SIGNIFICANT_BIT_0 and LEAST_SIGNIFICANT_BIT_0 are not used anywhere in the codebase.


225-230: Verify CC_PolicyTransportSPDM handler and SPDM secure channel implementation are present
Search returned no CC_PolicyTransportSPDM handler definitions or any SPDM secure channel code. Ensure the command handler and all required secure‐channel infrastructure are implemented before setting SEC_CHANNEL_SUPPORT to YES.

libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorCommands/prototypes/Vendor_TCG_Test_fp.h (1)

2-27: LGTM! Well-structured vendor command header.

The vendor command header follows TPM conventions correctly with proper conditional compilation, input/output structures, error code macros, and function prototypes. The implementation matches the prototype as seen in the related source file.

libtcgtpm/deps/TpmConfiguration/CMakeLists.txt (1)

43-55: LGTM! Vendor command headers properly installed.

The installation of VendorCommands headers and prototypes is correctly structured with appropriate destination paths for downstream consumers.

libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorCommands/CommandDispatchData_CommandStructures.inl (2)

10-12: LGTM! Proper inclusion guard.

The guard correctly ensures this file is only included in the appropriate context (inside CommandDispatchData.h with table dispatching enabled).


14-41: LGTM! Vendor command descriptor correctly structured.

The descriptor implementation is correct:

  • Function type and structure definition match the command prototypes
  • Initialization properly sets up entry point, sizes, and marshaling types
  • The types array {TPM2B_DATA_P_UNMARSHAL, END_OF_LIST, TPM2B_DATA_P_MARSHAL, END_OF_LIST} correctly matches the input/output structures (one TPM2B_DATA parameter each)
  • Conditional macro definition provides the address when enabled or zero otherwise

Comment on lines +175 to +176
// number of vendor properties, must currently be 1.
#define MAX_VENDOR_PROPERTY (1)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

🧩 Analysis chain

Verify the "must currently be 1" constraint is enforced.

The comment states that MAX_VENDOR_PROPERTY must currently be 1, which suggests a hard constraint in the implementation. Ensure that this constraint is validated at compile-time or runtime to prevent configuration errors.

Run the following script to search for validation or usage of this macro:


🏁 Script executed:

#!/bin/bash
# Description: Search for validation and usage of MAX_VENDOR_PROPERTY.

# Search for static assertions or validation
rg -nP --type=c --type=cpp -C3 'MAX_VENDOR_PROPERTY'

# Search for vendor property array declarations that may depend on this size
ast-grep --pattern 'vendorProperty[$_]'

Length of output: 771


Enforce MAX_VENDOR_PROPERTY == 1 via static_assert
Add a compile-time assertion in TpmProfile_Common.h, for example:

static_assert(MAX_VENDOR_PROPERTY == 1, "MAX_VENDOR_PROPERTY must be 1");

to guarantee the hard constraint.

🤖 Prompt for AI Agents
In libtcgtpm/deps/TpmConfiguration/TpmConfiguration/TpmProfile_Common.h around
lines 175-176, add a compile-time assertion to enforce that MAX_VENDOR_PROPERTY
equals 1. Insert a static_assert right after the #define to validate the
constant at compile time and provide a clear error message if the value changes,
ensuring builds fail early when the hard constraint is violated.

Comment on lines +2 to +8
// for vendor commands.
//
// IMPORTANT: This file is included in the middle of an array initializer
// therefore it must not contain anything other than comments and exactly one TPMA_CC
// entry per vendor command. See the private Tpm header CommandAttributeData.h for
// more info.
// (This is why the file has the .INL extension, it's not a normal header.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Update misleading comment to match actual file content.

The comment describes this file as containing "an inlined portion of the s_ccAttr array definition" with "exactly one TPMA_CC entry per vendor command", but the actual content defines descriptor structures (Vendor_TCG_Test_COMMAND_DESCRIPTOR_t and _Vendor_TCG_TestData), not TPMA_CC entries. This discrepancy suggests the comment was copied from a different .inl file template.

Update the comment to accurately describe the file's purpose:

-// This file contains an inlined portion of the s_ccAttr array definition
-// for vendor commands.
+// This file contains command descriptor structures for vendor commands.
 //
-// IMPORTANT:  This file is included in the middle of an array initializer
-// therefore it must not contain anything other than comments and exactly one TPMA_CC
-// entry per vendor command.  See the private Tpm header CommandAttributeData.h for
-// more info.
+// IMPORTANT: This file should only be included inside CommandDispatchData.h
+// when table dispatching is turned on. It defines descriptor structures that
+// are referenced by address in the command dispatch table.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// for vendor commands.
//
// IMPORTANT: This file is included in the middle of an array initializer
// therefore it must not contain anything other than comments and exactly one TPMA_CC
// entry per vendor command. See the private Tpm header CommandAttributeData.h for
// more info.
// (This is why the file has the .INL extension, it's not a normal header.
// This file contains command descriptor structures for vendor commands.
//
// IMPORTANT: This file should only be included inside CommandDispatchData.h
// when table dispatching is turned on. It defines descriptor structures that
// are referenced by address in the command dispatch table.
// (This is why the file has the .INL extension, it's not a normal header.
🤖 Prompt for AI Agents
In
libtcgtpm/deps/TpmConfiguration/TpmConfiguration/VendorCommands/CommandDispatchData_CommandStructures.inl
around lines 2 to 8, the top comment incorrectly states the file is an inlined
portion of an s_ccAttr array with TPMA_CC entries; instead the file contains
vendor command descriptor structures (e.g., Vendor_TCG_Test_COMMAND_DESCRIPTOR_t
and Vendor_TCG_TestData). Replace the misleading comment with a concise
description stating that this .inl defines vendor command descriptor structures
and data for command dispatch (and must be included where those structures are
expected), removing any reference to TPMA_CC entries or array initializers.

Comment thread scripts/container/opensuse-rust.docker Outdated
@stefano-garzarella stefano-garzarella force-pushed the tcgtpm-v184-cmake branch 4 times, most recently from b362225 to 80fb22a Compare October 6, 2025 15:59
The next TCG TPM reference implementation release (v185) will remove
the support for autotools [1]. Currently, v184 supports both, so let's
switch to cmake to be prepared.

The main difference is that dependency on TpmBigNum and Math_Ossl was
previously specified in the autotools files when producing libtpm.a and
libplatform.a, but now it is only specified for the final product
(e.g. the simulator in their project). Therefore, we must explicitly
build and link them when producing libtcgtpm.a.

Update documentation and CI about deps to install to build TPM.
`gcc-c++` is required by the cmake project, otherwise the
"No CMAKE_CXX_COMPILER could be found" error is printed.

[1] TrustedComputingGroup/TPM#6 (comment)

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
libtcgtpm/Makefile (1)

34-43: Do not nest static archives; flatten inputs when building libtcgtpm.a. Also fix static lib order.

ar rcsTPD $@ $^ nests .a files inside libtcgtpm.a; linkers won’t resolve symbols in nested archives. Extract object files and re-archive. Also list the dependent BigNum before its provider Math_Ossl to satisfy static resolution (left-to-right).

Apply:

-LIBS = $(LIBCRT) $(LIBCRYPTO) $(LIBBNMATH) $(LIBTPMBIGNUM) $(LIBTPM) $(LIBPLATFORM)
+LIBS = $(LIBCRT) $(LIBCRYPTO) $(LIBTPMBIGNUM) $(LIBBNMATH) $(LIBTPM) $(LIBPLATFORM)

 $(OUT_DIR)/libtcgtpm.a: $(LIBS)
-	rm -f $@
-	ar rcsTPD $@ $^
+	rm -f $@
+	tmpdir=$(@:.a=.objs) && rm -rf $$tmpdir && mkdir -p $$tmpdir && \
+	for a in $(LIBS); do (cd $$tmpdir && ar x $$a); done && \
+	ar rcsTPD $@ $$tmpdir/*.o && ranlib $@ && rm -rf $$tmpdir

Alternatively, use an MRI script with ar -M and addlib for each archive.

🧹 Nitpick comments (4)
libtcgtpm/Makefile (3)

173-181: Force the Makefiles generator to match subsequent make -C usage.

On systems defaulting to Ninja (via env or CMake prefs), $(TCGTPM_BUILD_DIR)/Makefile won’t exist and make -C will fail. Pin the generator.

-		cmake \
+		cmake -G "Unix Makefiles" \
 			-DCMAKE_C_FLAGS="${TCGTPM_CFLAGS}" \

156-167: Make parallelism probe more portable.

nproc may be unavailable on some distros/containers. Use a fallback.

-	$(MAKE) -j$$(nproc) -C $(TCGTPM_BUILD_DIR) $(LIBBNMATH_TARGET)
+	$(MAKE) -j$$(getconf _NPROCESSORS_ONLN 2>/dev/null || nproc || echo 1) -C $(TCGTPM_BUILD_DIR) $(LIBBNMATH_TARGET)

Apply similarly to other -j$$(nproc) calls.


31-33: Consider out-of-tree build dir to avoid polluting submodule.

Placing the CMake build under the TPM source tree can dirty the vendored code. Consider TCGTPM_BUILD_DIR := $(DEPS_DIR)/.build/tpm-20-ref/TPMCmd (or similar).

Documentation/docs/installation/INSTALL.md (1)

206-208: Add minimum CMake version (3.16.3) to INSTALL.md
Specify “CMake ≥ 3.16.3” in Documentation/docs/installation/INSTALL.md (lines 206–208) to match the top-level CMakeLists.txt.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3e691bc and f381899.

📒 Files selected for processing (5)
  • .github/workflows/publish-docs.yml (1 hunks)
  • .github/workflows/qemu.yml (1 hunks)
  • .github/workflows/rust.yml (1 hunks)
  • Documentation/docs/installation/INSTALL.md (1 hunks)
  • libtcgtpm/Makefile (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • .github/workflows/rust.yml
  • .github/workflows/publish-docs.yml
  • .github/workflows/qemu.yml
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Check
  • GitHub Check: Sourcery review
  • GitHub Check: QEMU NOCC test-in-svsm

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