Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proper way to free all data in spdm_context #287

Open
steven-bellock opened this issue Aug 28, 2023 · 1 comment
Open

Proper way to free all data in spdm_context #287

steven-bellock opened this issue Aug 28, 2023 · 1 comment
Assignees

Comments

@steven-bellock
Copy link
Contributor

Discussed in DMTF/libspdm#2320

Originally posted by LeeTroy August 22, 2023
I'm running libspdm in a embedded project, the spdm context will be created and released over and over again.
However, I found there's no proper way to release some of data within context.

res = libspdm_read_responder_root_public_certificate(m_use_hash_algo,
m_use_asym_algo,
&data, &data_size,
&hash, &hash_size);
if (res) {
libspdm_x509_get_cert_from_cert_chain(
(uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size,
data_size - sizeof(spdm_cert_chain_t) - hash_size, 0,
&root_cert, &root_cert_size);
libspdm_zero_mem(&parameter, sizeof(parameter));
parameter.location = LIBSPDM_DATA_LOCATION_LOCAL;
libspdm_set_data(spdm_context,
LIBSPDM_DATA_PEER_PUBLIC_ROOT_CERT,
&parameter, (void *)root_cert, root_cert_size);

res = libspdm_read_responder_root_public_certificate(m_use_hash_algo,
                                                     m_use_asym_algo,
                                                     &data, &data_size,
                                                     &hash, &hash_size);
if (res) {
    libspdm_x509_get_cert_from_cert_chain(
        (uint8_t *)data + sizeof(spdm_cert_chain_t) + hash_size,
        data_size - sizeof(spdm_cert_chain_t) - hash_size, 0,
        &root_cert, &root_cert_size);
    libspdm_zero_mem(&parameter, sizeof(parameter));
    parameter.location = LIBSPDM_DATA_LOCATION_LOCAL;
    libspdm_set_data(spdm_context,
                     LIBSPDM_DATA_PEER_PUBLIC_ROOT_CERT,
                     &parameter, (void *)root_cert, root_cert_size);
}
  • libspdm_read_responder_root_public_certificate allocates data
  • data can't be release because root_cert sit inside data
  • libspdm_get_data doesn't support LIBSPDM_DATA_PEER_PUBLIC_ROOT_CERT, even if it is supported, the pointer is root_cert but not data.

One solution I can think of storing data pointer with LIBSPDM_DATA_APP_CONTEXT_DATA, and release it when the spdm context is not needed.

Thanks!

@jyao1
Copy link
Member

jyao1 commented Aug 28, 2023

I think the integrator (spdm-emu) can free those data instead of libspdm.

The reason is that libspdm does not has any alloc/free function. libspdm has no knowledge on if the data is in heap or global variable.

@jyao1 jyao1 transferred this issue from DMTF/libspdm Aug 28, 2023
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

No branches or pull requests

2 participants