Skip to content

Enlarge LIBSPDM_MAX_CERT_CHAIN_SIZE for SLH-DSA - #4382

Open
Jhongwe1 wants to merge 1 commit into
DMTF:mainfrom
Jhongwe1:slh-dsa-cert-chain-size
Open

Jhongwe1 wants to merge 1 commit into
DMTF:mainfrom
Jhongwe1:slh-dsa-cert-chain-size

Conversation

@Jhongwe1

@Jhongwe1 Jhongwe1 commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Fix #4381.

The SLH-DSA-256f AliasCert sample chains are longer than the 0x28000 bytes LIBSPDM_MAX_CERT_CHAIN_SIZE gives a chain with SLH-DSA. This makes the SLH-DSA value 0x40000, in spdm_lib_config.h and in the changelog line that names it.

Measured on x64 with GCC, main 19ac314 before, this branch after:

  • Without LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT, mbedtls Debug, OpenSSL Debug and OpenSSL Release: all 80 test executables of each build are byte-identical before and after.
  • With it, OpenSSL Release: the seven unit test programs that tier 1 runs give the same results before and after, and sizeof(libspdm_context_t) goes from 2,961,368 to 3,944,408 bytes.
  • spdm-emu dd4b434 built with transcript data, ALIAS_CERT and SLH-DSA-SHA2-256f: the Requester used to stop at slot 0's chain with LIBSPDM_STATUS_BUFFER_TOO_SMALL, after 86 messages. Now it keeps that chain and stops at slot 4's, after 108: the Responder cannot append slot 4's CERTIFICATE to message_b, which holds one chain and already holds slot 0's (a Debug build prints libspdm_append_managed_buffer 0x24d74 fail, rest 0xef66 only). Without ALIAS_CERT, slots 0 and 4 hold 150,832-byte chains, and the flow stops there before and after this change.
  • ML-DSA-87 with ALIAS_CERT, and the default flow, give the same messages before and after, in both builds.

The unit tests' own copies of the value, used without transcript data, stay at 0x28000. At 0x40000 the Windows Debug builds with OpenSSL overflowed their 1 MiB stack in req_get_certificate_case12 (this PR's second version: windows-x64-vs-openssl-debug, windows-ia32-vs-openssl-debug and windows-x64-clang-openssl-debug). With transcript data the unit tests take libspdm's value, so a Windows Debug build of them with OpenSSL and transcript data would put 0x40000 chain buffers on the stack too; no tier builds that configuration.

@LeonLinAtAMI LeonLinAtAMI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you consider to change LIBSPDM_MAX_CERT_CHAIN_SIZE under unit_test folder too?

@Jhongwe1
Jhongwe1 force-pushed the slh-dsa-cert-chain-size branch from bc34591 to effd81b Compare November 30, 2026 16:56
@Jhongwe1

Copy link
Copy Markdown
Contributor Author

Yes. The three copies under unit_test now use 0x40000 too.

With transcript data the unit tests already take libspdm's value, so with this change they get 0x40000 either way.

The cost is stack: with OpenSSL the deepest unit test, req_get_certificate_case12, goes from 504 to 788 KiB. The unit tests still pass with a 1 MiB stack, MSVC's default. With mbedtls nothing changes. The description has the numbers.

I also rebased onto main, so the chain sizes in the commit message are the ones after #4377.

Fix DMTF#4381.

The SLH-DSA-SHA2-256f and SLH-DSA-SHAKE-256f AliasCert chains in
unit_test/sample_key hold 201,146 and 201,154 bytes of certificates,
more than the 0x28000 bytes LIBSPDM_MAX_CERT_CHAIN_SIZE gives a chain
when an SLH-DSA parameter set is enabled. With
LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT, the only configuration in
which libspdm defines the macro, the context keeps each peer chain in
a buffer of that size, so a Requester cannot keep such a chain.

Make the SLH-DSA value 0x40000. It holds those chains with their
4-byte header and a root hash of up to 64 bytes, and it is the value
the Tier 2 row config-record-transcript-large already builds with.
Without RECORD_TRANSCRIPT_DATA_SUPPORT nothing changes. With it,
sizeof(libspdm_context_t) on x64 grows from 2,961,368 to 3,944,408
bytes: eight per-slot chain buffers and two transcript buffers.

The unit tests, the fuzzing harnesses and test_size keep their own
copies of the block, at 0x28000, for builds without transcript data.
At 0x40000 the unit tests' Windows Debug builds with OpenSSL run out
of their 1 MiB stack in req_get_certificate_case12, whose path holds
several chain buffers.

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Chung-Wei Lan <zwwe1f@gmail.com>
@Jhongwe1
Jhongwe1 force-pushed the slh-dsa-cert-chain-size branch from effd81b to 169fc97 Compare November 30, 2026 17:21
@Jhongwe1

Copy link
Copy Markdown
Contributor Author

Correction: the second version failed on Windows. In the Debug builds with OpenSSL, req_get_certificate_case12 overflows the 1 MiB stack (EXCEPTION_STACK_OVERFLOW in windows-x64-vs-openssl-debug, windows-ia32-vs-openssl-debug and windows-x64-clang-openssl-debug). My stack check was with GCC on Linux; the Windows Debug builds use more stack.

So the unit_test copies are back at 0x28000, and the PR is the first version again, rebased onto main. For the copies to follow, the unit tests' chain buffers have to come off the stack first. I can send that as a separate PR if you want.

This branch has not been deployed

No deployments
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.

The SLH-DSA-256f AliasCert sample chains exceed LIBSPDM_MAX_CERT_CHAIN_SIZE

3 participants