Skip to content

Backport a coupld of NVRAM marshalling/unmarshalling related patches#572

Merged
stefanberger merged 3 commits intostable-0.10from
stable-0.10.next
Mar 11, 2026
Merged

Backport a coupld of NVRAM marshalling/unmarshalling related patches#572
stefanberger merged 3 commits intostable-0.10from
stable-0.10.next

Conversation

@stefanberger
Copy link
Copy Markdown
Owner

@stefanberger stefanberger commented Mar 10, 2026

This PR resolves a few issues with unmarshalling of NVRAM

  • gets rid of the usage of sizeof(OBJECT) for testing for available space in NVRAM and uses the size of the marshalled OBJECT instead
  • only marshalls the number of bytes that are necessary (for default-v1 profile). This way we v0.10 produces the same size of state file as v0.11 and any future version when they marshall the ppList or auditCommands bitmaps.

Use the marshalled size of an OBJECT to check whether it still fits into
NVRAM rather than using the size of the OBJECT (sizeof(obj), which is much
bigger. Using the marshalled size also handles the case where the OBJECT is
still copied into NVRAM using memcpy for the NULL profile case of
libtpms v0.9. This should have been converted once NvObjectToBuffer()
was started to be called there.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Base the enabledCommands array on the command index rather than the command
code since the latter left the first few bytes always unused since command
codes start at 0x11f only.

After this change, ppList, auditCommands, and enabledCommandsByIdx bitmaps
are all based on command indices.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Only write the necessary number of bytes of the ppList and auditCommands
bitmaps. The entries in both of these bitmaps are set by a command's
index and the necessary number of bytes can be determined by finding the
command with the highest command code that is enabled in the current
profile (1). This in turn can be found by by searching for the last byte
in the enableCommandsByIdx bitmap that has any bit set.

1) It would be possible to skip writing these arrays entirely if they have
   no bits set. The unmarshalling functions would clear the arrays.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
@stefanberger stefanberger merged commit 426cc78 into stable-0.10 Mar 11, 2026
4 checks passed
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