Skip to content

Fenrir fixes batch 12#511

Open
aidangarske wants to merge 8 commits into
wolfSSL:masterfrom
aidangarske:fenrir-fixes-12
Open

Fenrir fixes batch 12#511
aidangarske wants to merge 8 commits into
wolfSSL:masterfrom
aidangarske:fenrir-fixes-12

Conversation

@aidangarske
Copy link
Copy Markdown
Member

F-4373, F-4374, F-4375, F-4742, F-4170, F-4171

Copilot AI review requested due to automatic review settings May 26, 2026 19:03
@aidangarske aidangarske requested a review from dgarske May 26, 2026 19:04
@aidangarske aidangarske self-assigned this May 26, 2026

This comment was marked as resolved.

Copy link
Copy Markdown
Member

@dgarske dgarske left a comment

Choose a reason for hiding this comment

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

One one minor emdash

Comment thread src/fwtpm/fwtpm_command.c Outdated
@aidangarske aidangarske requested a review from dgarske May 26, 2026 22:55
dgarske
dgarske previously approved these changes May 26, 2026
@dgarske
Copy link
Copy Markdown
Member

dgarske commented May 26, 2026

@aidangarske please resolve merge conflicts. Thanks

FWTPM_ProcessCommand parsed the auth area only under
if (cmdTag == TPM_ST_SESSIONS), so a NO_SESSIONS command with
authHandleCnt > 0 left cmdAuthCnt at 0 and bypassed every downstream
policy, password, and HMAC enforcement loop. An 18-byte unauthenticated
TPM2_Clear wiped owner and endorsement state, reseeded both hierarchies,
and reset PCRs.

Add a centralized gate immediately after the command-table lookup that
returns TPM_RC_AUTH_MISSING when the tag is TPM_ST_NO_SESSIONS but the
handler declares authHandleCnt > 0. Matches the spec rule that any auth
role requires TPM_ST_SESSIONS, and closes the same gap that already had
per-handler guards on a few callers.

Add a negative test that issues TPM2_Clear with TPM_ST_NO_SESSIONS and
asserts TPM_RC_AUTH_MISSING is returned without any state mutation.
FwCmd_PolicyTicket gated the entire HMAC verification block on
ticketDigestSz > 0. A caller could submit ticketTag=TPM_ST_AUTH_SIGNED
with ticketDigestSz=0, pass the tag check, skip FwComputeTicketHmac and
TPM2_ConstantCompare entirely, and fall through to FwPolicyExtend with
attacker-supplied authName/policyRef as if a valid PolicySigned or
PolicySecret ticket had been presented. The forged extension then
satisfied any PolicySigned or PolicySecret clause for an arbitrary
named entity without possession of any signing key.

Reject ticketDigestSz==0 with TPM_RC_TICKET immediately after the tag
check, and drop the redundant ticketDigestSz > 0 guard from the HMAC
block so verification runs unconditionally for every accepted ticket.

Add a negative test that issues TPM2_PolicyTicket with ticketTag
TPM_ST_AUTH_SIGNED and digest size 0 against a policy session and
asserts TPM_RC_TICKET.
FwCmd_LoadExternal's SYMCIPHER copy path gated the XMEMCPY into
privKeyDer only on qSz > FWTPM_MAX_DER_SIG_BUF, duplicating the outer
parse check rather than testing the destination size. On v1.85 builds
with any ML-DSA parameter set enabled FWTPM_MAX_DER_SIG_BUF grows to
2548–4755 while FWTPM_MAX_PRIVKEY_DER stays at 1280 (or 256 in NO_RSA
builds), so any qSz between FWTPM_MAX_PRIVKEY_DER + 1 and
FWTPM_MAX_DER_SIG_BUF wrote up to 3475 attacker-controlled bytes past
the destination buffer.

Replace the dead guard with an explicit valid-AES-key-size check per
TPM 2.0 Part 2 Sec.11.1.9 — accept only 16, 24, or 32 bytes for a
SYMCIPHER sensitive area and return TPM_RC_SIZE otherwise. Every
allowed length is well within FWTPM_MAX_PRIVKEY_DER on every supported
build, so the destination overflow is no longer reachable.

Add a negative test that submits SYMCIPHER LoadExternal with qSz=33
(passes the FWTPM_MAX_DER_SIG_BUF gate on non-v1.85 builds, exceeds
both the AES set and the destination on v1.85 builds) and asserts
TPM_RC_SIZE.
FwCmd_PolicyAuthorize gated the entire HMAC verification block on
ticketDigestSz > 0 (same pattern as the prior FwCmd_PolicyTicket fix).
An attacker could submit ticketTag=TPM_ST_VERIFIED with
ticketDigestSz=0, pass the tag check, skip FwComputeTicketHmac and
TPM2_ConstantCompare entirely, and fall through to the policyDigest
extension using attacker-supplied approvedPolicy and keySignName.

This is the root of the F-4742 chain: combined with an empty-HMAC
policy session, the forged policyDigest matches the entity's authPolicy
in FWTPM_ProcessCommand and grants access to any PolicyAuthorize-
protected object whose userWithAuth is clear, without possession of
any signing key. Cutting the chain at PolicyAuthorize blocks the whole
sequence. The empty-HMAC behavior on policy sessions is intentional
per the existing in-code comment (spec-conformant when neither
PolicyAuthValue nor PolicyPassword has been called) and is not
modified here.

Reject ticketDigestSz==0 with TPM_RC_TICKET after the tag check, and
drop the redundant ticketDigestSz > 0 guard from the HMAC block so
verification runs unconditionally for every accepted ticket.

Add a negative test that issues TPM2_PolicyAuthorize with
TPM_ST_VERIFIED and digest size 0 against a policy session and asserts
TPM_RC_TICKET.
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.

3 participants