Skip to content

Add feature to run libspdm_fips_run_selftest at load time#1833

Merged
jyao1 merged 2 commits into
DMTF:mainfrom
Wenxing-hou:Add_LIBSPDM_FIPS_TEST_AT_LOAD
Apr 21, 2023
Merged

Add feature to run libspdm_fips_run_selftest at load time#1833
jyao1 merged 2 commits into
DMTF:mainfrom
Wenxing-hou:Add_LIBSPDM_FIPS_TEST_AT_LOAD

Conversation

@Wenxing-hou

@Wenxing-hou Wenxing-hou commented Mar 23, 2023

Copy link
Copy Markdown
Contributor

Commit1: Add LIBSPDM_FIPS_TEST_AT_LOAD for FIPS
Commit2: Add feature to run libspdm_fips_run_selftest at load time

The PR: DMTF/spdm-emu#238 will pass, when this PR is merged.

The emu and libspdm tests have passed when LIBSPDM_FIPS_TEST_AT_LOAD = 1 and LIBSPDM_FIPS_MODE = 1.

Refer: #1260

@Wenxing-hou Wenxing-hou force-pushed the Add_LIBSPDM_FIPS_TEST_AT_LOAD branch from f43e593 to 3d2c80f Compare March 23, 2023 10:19
@steven-bellock

Copy link
Copy Markdown
Contributor

@jyao1 @xiaoyuruan I don't think libspdm needs to support any of this. It should be left up to the Integrator when the self-tests are run.

@xiaoyuruan

Copy link
Copy Markdown
Contributor

I think 99% of implementations would run self-tests for algorithms either 1. all at load or 2. individually before first use.
It'd be convenient to support these two cases in libspdm.
The 1% would need to implement their own.

@steven-bellock

Copy link
Copy Markdown
Contributor

libspdm_fips_run_selftest is available to the Integrator to run as they see fit. My issues with this pull request are

  1. The self-test does not happen at load time. It happens when the first SPDM context is initialized.
  2. It's not thread safe. One of nice things for Integrators is that All statically allocated memory is read-only and the core libraries do not dynamically allocate memory. We would now need to put an asterisk(*) next to that statement.

@jyao1

jyao1 commented Mar 27, 2023

Copy link
Copy Markdown
Member

Discussed in 3/27/2023.

  1. We should not use global variable, that is our rule for libspdm.
  2. We may put tested flags to spdm_context, but that will cause self-test run multiple times, when a device supports multiple connection.

Jiewen will talk to Xiaoyu on that.

@jyao1

jyao1 commented Mar 27, 2023

Copy link
Copy Markdown
Member

@Wenxing-hou , please split EC patch to a standalone PR. not merge in this one.

@xiaoyuruan

Copy link
Copy Markdown
Contributor

Discussed with Jiewen. I suggest implementing, in the libspdm-crypto module, a "global crypto context" that covers all connection-based contexts. The "global crypto context" should save FIPS selftest status (run yet?; passed/failed) for every crypto algorithm, respectively. Whenever a crypto algorithm is called, libspdm-crypto should check that this algorithm has run and passed selftest; if not run, run it and update status in global context; if not passed, return error.

@steven-bellock

Copy link
Copy Markdown
Contributor

@xiaoyuruan And the global crypto context is single context that is stack or heap allocated and provided by the Integrator?

@jyao1

jyao1 commented Mar 28, 2023

Copy link
Copy Markdown
Member

Yes. it is provided by the integrator. It could be stack, or heap, or writable global variable.

The consumer needs to aware that, multiple SPDM contexts may access the global area at same time. That will add complexity to the implementation.
Not sure if we need to support a global lock, or leave it to individual fields.

@Wenxing-hou Wenxing-hou force-pushed the Add_LIBSPDM_FIPS_TEST_AT_LOAD branch from 3d2c80f to 4ba283f Compare March 28, 2023 03:19
@Wenxing-hou

Copy link
Copy Markdown
Contributor Author

@Wenxing-hou , please split EC patch to a standalone PR. not merge in this one.

Thanks. I have submitted a new PR: #1838. The CI will pass when the PR: #1838 is merged.

@jyao1 jyao1 marked this pull request as draft April 3, 2023 01:52
@Wenxing-hou Wenxing-hou force-pushed the Add_LIBSPDM_FIPS_TEST_AT_LOAD branch from 4ba283f to 7761165 Compare April 6, 2023 11:06
@Wenxing-hou Wenxing-hou marked this pull request as ready for review April 6, 2023 13:50
@Wenxing-hou Wenxing-hou force-pushed the Add_LIBSPDM_FIPS_TEST_AT_LOAD branch 2 times, most recently from 5006df7 to eaf89fb Compare April 10, 2023 06:23
Comment thread include/internal/libspdm_common_lib.h Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please remove bit enumeration here.
Just say "See LIBSPDM_FIPS_SELF_TEST_xxx".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks. I have changed the comments.

Comment thread include/internal/libspdm_common_lib.h Outdated
Comment thread include/library/spdm_common_lib.h Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we need size_t crypto_context_size

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks. I have added the size parameter.

Comment thread include/library/spdm_common_lib.h Outdated
@Wenxing-hou Wenxing-hou force-pushed the Add_LIBSPDM_FIPS_TEST_AT_LOAD branch 3 times, most recently from 002ba2c to 1e3afed Compare April 12, 2023 01:48
Comment thread include/internal/libspdm_common_lib.h Outdated

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.

The name "libspdm_crypto_context" is kind of misleading - "crypto" is too big a scope, it's really just FIPS selftest status.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes. I have changed the libspdm_crypto_context to libspdm_fips_selftest_context.

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.

I'm curious, why is parameter crypto_context_size needed here? If it's needed here for safety, for consistency, why not also have a parameter "spdm_context_size"?

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.

I'd define "MASK" for each algorithm, and use context->crypto_context.tested_algo & MASK. This would save the shift operation.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

right. Just define LIBSPDM_FIPS_SELF_TEST_HMAC_SHA256 as bit mask.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks. I have changed the SHIFT_BIT to MASK, which can save the shift operation.

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.

Why 0xFF? There are more than 8 algorithms. tested_algo is a uint32.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks. I have updated 0xFF -> 0xFFFF.

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.

Using 0xFFFF assumes the number of tests is 16. i.e., if we add or remove selftests later, it needs to change here, and it is easy to miss.
I'd suggest using OR result of all LIBSPDM_FIPS_SELF_TEST_XYZ instead of hardcoding to 0xFFFF.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks. I have changed the 0xFFFF by using OR result of all LIBSPDM_FIPS_SELF_TEST_XYZ.

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.

Is the following selftest code same as in libspdm_init_connection()? Why duplicate the code?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have added a api bool libspdm_update_fips_selftest_context(void *spdm_context), which can be called by requester and responder. Thanks.

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.

I think it's more logical to always run all selftests, even if one or more algorithms have failed. At the end, the function would have run all selftests and return overall failed/passed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes. In function bool libspdm_update_fips_selftest_context(void *spdm_context), all selftests will be run, even if one algo have failed.

@Wenxing-hou Wenxing-hou force-pushed the Add_LIBSPDM_FIPS_TEST_AT_LOAD branch 4 times, most recently from 24b7053 to 72ecdc0 Compare April 18, 2023 03:30

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.

It'd need #if LIBSPDM_XYZ_SUPPORT qualifier before participating in the | operation.

@Wenxing-hou Wenxing-hou force-pushed the Add_LIBSPDM_FIPS_TEST_AT_LOAD branch 3 times, most recently from e89fd81 to bd2126f Compare April 18, 2023 06:50

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.

this line is missing "|", did it compile?

@Wenxing-hou Wenxing-hou Apr 19, 2023

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry. I forget to add the "|". The code has been added. Thanks.

@Wenxing-hou Wenxing-hou force-pushed the Add_LIBSPDM_FIPS_TEST_AT_LOAD branch from bd2126f to 84f6eda Compare April 19, 2023 01:16
@Wenxing-hou Wenxing-hou reopened this Apr 19, 2023
@jyao1

jyao1 commented Apr 21, 2023

Copy link
Copy Markdown
Member

Please fix CI failure

Reference: DMTF#1260

Signed-off-by: Wenxing Hou <wenxing.hou@intel.com>
Reference: DMTF#1260

Signed-off-by: Wenxing Hou <wenxing.hou@intel.com>
@Wenxing-hou Wenxing-hou force-pushed the Add_LIBSPDM_FIPS_TEST_AT_LOAD branch from 84f6eda to fbd6625 Compare April 21, 2023 02:17
@Wenxing-hou

Copy link
Copy Markdown
Contributor Author

Please fix CI failure

yes. The CI passed. Thanks.

@jyao1 jyao1 merged commit 3642571 into DMTF:main Apr 21, 2023
@Wenxing-hou Wenxing-hou deleted the Add_LIBSPDM_FIPS_TEST_AT_LOAD branch July 3, 2024 06:45
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.

4 participants