Skip to content

20240126-LINUXKM_LKCAPI_REGISTER#7180

Merged
dgarske merged 16 commits intowolfSSL:masterfrom
douzzer:20240126-LINUXKM_LKCAPI_REGISTER
Feb 2, 2024
Merged

20240126-LINUXKM_LKCAPI_REGISTER#7180
dgarske merged 16 commits intowolfSSL:masterfrom
douzzer:20240126-LINUXKM_LKCAPI_REGISTER

Conversation

@douzzer
Copy link
Copy Markdown
Contributor

@douzzer douzzer commented Jan 27, 2024

linuxkm: completion and stabilization of LKCAPI integration for AES-CBC, AES-CFB, AES-GCM, and AES-XTS:

AES-XTS:
split XtsAes.aes in two, XtsAes.aes_encrypt and XtsAes.aes_decrypt, and add AES_ENCRYPTION_AND_DECRYPTION option constant, to accommodate Linux kernel crypto API model.
in wc_AesXtsSetKeyNoInit(), add FIPS check that main and tweak keys differ, and allow setting encrypt and decrypt keys simultaneously using AES_ENCRYPTION_AND_DECRYPTION.
in wc_AesXtsEncrypt() and wc_AesXtsDecrypt(), error if the required subkey has not been set.

add DEBUG_VECTOR_REGISTER_ACCESS_FUZZING && !DEBUG_VECTOR_REGISTER_ACCESS, with a kernel-compatible implementation of SAVE_VECTOR_REGISTERS2_fuzzer().

squash of philljj's POC work integrating libwolfssl.ko with crypto_register_skcipher/crypto_register_aead, start 2022-12-26, end 2023-01-14.

linuxkm/lkcapi_glue.c:
implement linuxkm_lkcapi_register() and linuxkm_lkcapi_unregister() with idempotency.
add AES-XTS algorithm glue and self-test implementations.
add per-algorithm gating: LINUXKM_LKCAPI_REGISTER_AESCBC, _AESCFB, _AESGCM, and _AESXTS.
carry forward philljj's implementations for AES-CBC, AES-CFB, and AES-GCM, with various cleanups.

linuxkm/module_hooks.c:
print the "wolfCrypt container hashes" message only if DEBUG_LINUXKM_PIE_SUPPORT is set.
render the FIPS version for the self-test success message using the HAVE_FIPS_VERSION* macros.
add a "skipping full wolfcrypt_test() ..." message for --disable-crypttests builds.
add CONFIG_FORTIFY_SOURCE gates.

configure.ac:
add support for --enable-linuxkm-lkcapi-register;
add AES-XTS to output config summary;
rename --enable-xts to --enable-aesxts (retaining old option for backward compatibility).

linuxkm/linuxkm_wc_port.h: add support for CONFIG_FORTIFY_SOURCE.

linuxkm/linuxkm_memory.c:
fix retvals in save_vector_registers_x86() (wc-style MEMORY_E, not sys-style ENOMEM).
add __my_fortify_panic() implementation.

linuxkm/Kbuild: for ENABLED_LINUXKM_PIE in rename-pie-text-and-data-sections recipe, create an .rodata.wolfcrypt section.

linuxkm/include.am: add linuxkm/lkcapi_glue.c to EXTRA_DIST.

wolfcrypt/test/test.c:
when defined(HAVE_FIPS_VERSION), inhibit a test clause in aes_xts_128_test() disallowed by FIPS ("FIPS AES-XTS main and tweak keys must differ").
fix out-of-order user message in ecc_test().

tested with wolfssl-multi-test.sh ... super-quick-check plus a slew (2 dozen) of LKCAPI scenarios with live module loads, including various combinations of AESNI, FIPS, CONFIG_FORTIFY_SOURCE, kernel sanitizers, --enable-crypttests and --disable-crypttests.

…crypto_register_skcipher/crypto_register_aead, start 2022-12-26, end 2023-01-14.
* LKCAPI integration tweaks for buildability and streamlining.
* add DEBUG_VECTOR_REGISTER_ACCESS_FUZZING && !DEBUG_VECTOR_REGISTER_ACCESS, with a kernel-compatible implementation of SAVE_VECTOR_REGISTERS2_fuzzer().
split XtsAes.aes in two, XtsAes.aes_encrypt and XtsAes.aes_decrypt, and add AES_ENCRYPTION_AND_DECRYPTION option constant, to accommodate Linux kernel crypto API model.
in wc_AesXtsSetKeyNoInit(), add FIPS check that main and tweak keys differ, and allow setting encrypt and decrypt keys simultaneously using AES_ENCRYPTION_AND_DECRYPTION.
in wc_AesXtsEncrypt() and wc_AesXtsDecrypt(), error if the required subkey has not been set.
…BC, AES-CFB, AES-GCM, and AES-XTS:

linuxkm/lkcapi_glue.c (added in earlier commit):
implement linuxkm_lkcapi_register() and linuxkm_lkcapi_unregister() with idempotency.
add AES-XTS algorithm glue and self-test implementations.
add per-algorithm gating: LINUXKM_LKCAPI_REGISTER_AESCBC, _AESCFB, _AESGCM, and _AESXTS.
carry forward philljj's implementations for AES-CBC, AES-CFB, and AES-GCM, with various cleanups.

linuxkm/module_hooks.c:
print the "wolfCrypt container hashes" message only if DEBUG_LINUXKM_PIE_SUPPORT is set.
render the FIPS version for the self-test success message using the HAVE_FIPS_VERSION* macros.
add a "skipping full wolfcrypt_test() ..." message for --disable-crypttests builds.
add CONFIG_FORTIFY_SOURCE gates.

configure.ac:
add support for --enable-linuxkm-lkcapi-register;
add AES-XTS to output config summary;
rename --enable-xts to --enable-aesxts (retaining old option for backward compatibility).

linuxkm/linuxkm_wc_port.h: add support for CONFIG_FORTIFY_SOURCE.

linuxkm/linuxkm_memory.c:
fix retvals in save_vector_registers_x86() (wc-style MEMORY_E, not sys-style ENOMEM).
add __my_fortify_panic() implementation.

linuxkm/Kbuild: for ENABLED_LINUXKM_PIE in rename-pie-text-and-data-sections recipe, create an .rodata.wolfcrypt section.

linuxkm/include.am: add linuxkm/lkcapi_glue.c to EXTRA_DIST.

wolfcrypt/test/test.c:
when defined(HAVE_FIPS_VERSION), inhibit a test clause in aes_xts_128_test() disallowed by FIPS ("FIPS AES-XTS main and tweak keys must differ").
fix out-of-order user message in ecc_test().
…emmove() (CONFIG_FORTIFY_SOURCE workarounds) with copy-by-words codepaths.
…ound struct km_AesCtx with separate aes_encrypt and aes_decrypt Aes pointers, and no cached key, to avoid AesSetKey operations at encrypt/decrypt time.
@douzzer douzzer requested a review from SparkiDev January 28, 2024 17:37
Comment thread linuxkm/lkcapi_glue.c Outdated
Comment thread linuxkm/lkcapi_glue.c
Comment thread linuxkm/lkcapi_glue.c
Comment thread linuxkm/lkcapi_glue.c Outdated
Comment thread linuxkm/lkcapi_glue.c
Comment thread linuxkm/lkcapi_glue.c Outdated
Comment thread linuxkm/lkcapi_glue.c Outdated
Comment thread linuxkm/lkcapi_glue.c Outdated
Comment thread wolfssl/wolfcrypt/aes.h
* support AES_ENCRYPTION_AND_DECRYPTION only if WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS is defined, and define it in linuxkm_wc_port.h if LINUXKM_LKCAPI_REGISTER.
* fix a typo in km_AesInitCommon().
* remove #if 0 code in lkcapi_glue.c.
@douzzer douzzer force-pushed the 20240126-LINUXKM_LKCAPI_REGISTER branch from ffce1a5 to 1fc6718 Compare January 29, 2024 05:59
@douzzer
Copy link
Copy Markdown
Contributor Author

douzzer commented Jan 29, 2024

retest this please.

Comment thread wolfcrypt/src/aes.c Outdated
}

if ((ret = wc_AesSetKey(&aes->aes, key, keySz, NULL, dir)) == 0) {
#ifdef HAVE_FIPS_VERSION
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.

Is it better to gate on HAVE_FIPS?

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.

yeah might be. I'll check the codebase and do whatever's consistent.

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.

fixed. defined(HAVE_FIPS) was definitely the right idea.

Comment thread linuxkm/linuxkm_wc_port.h
@dgarske dgarske requested a review from SparkiDev January 29, 2024 23:00
@dgarske dgarske assigned douzzer and unassigned wolfSSL-Bot Jan 29, 2024
…armonize error catching, reporting, and error codes; further address peer review feedback.
@douzzer douzzer requested a review from dgarske January 29, 2024 23:52
@douzzer
Copy link
Copy Markdown
Contributor Author

douzzer commented Jan 30, 2024

retest this please.

@douzzer douzzer assigned wolfSSL-Bot and unassigned douzzer Jan 30, 2024
@douzzer
Copy link
Copy Markdown
Contributor Author

douzzer commented Jan 30, 2024

retest this please.

Comment thread wolfcrypt/test/test.c Outdated
0x77, 0x8a, 0xe8, 0xb4, 0x3c, 0xb9, 0x8d, 0x5a
};

#ifndef HAVE_FIPS_VERSION /* FIPS requires different keys for main and tweak. */
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.

Should it be #ifndef HAVE_FIPS?

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.

fixed. also fixed this in 8 other places.

@douzzer douzzer requested a review from dgarske January 30, 2024 23:18
@douzzer
Copy link
Copy Markdown
Contributor Author

douzzer commented Jan 31, 2024

retest this please.

@douzzer
Copy link
Copy Markdown
Contributor Author

douzzer commented Jan 31, 2024

retest this please....

… "failed:" to error messages in km_AesGcmEncrypt() and km_AesGcmDecrypt().
@douzzer douzzer mentioned this pull request Jan 31, 2024
4 tasks
@douzzer
Copy link
Copy Markdown
Contributor Author

douzzer commented Jan 31, 2024

retest this please...

* configure.ac: in linuxkm-lkcapi-register section, force ENABLED_AESGCM_STREAM=yes if ENABLED_AESGCM is yes and there is asm or FIPS in the picture.
* linuxkm/module_hooks.c: in updateFipsHash(), if DEBUG_LINUXKM_PIE_SUPPORT || WOLFSSL_LINUXKM_VERBOSE_DEBUG, print the base16 hash to the kernel log.
* linuxkm/lkcapi_glue.c:
  * implement KATs for AES-CBC, AES-CFB, and AES-GCM.
  * clean out extraneous code and macro usage inherited from test/test.c.
  * add post-registration crypto_tfm_alg_driver_name() tests for AES-CBC, AES-CFB, and AES-GCM.
@douzzer douzzer assigned SparkiDev and unassigned douzzer Feb 2, 2024
@SparkiDev SparkiDev removed the request for review from wolfSSL-Bot February 2, 2024 06:36
@SparkiDev SparkiDev assigned dgarske and unassigned SparkiDev Feb 2, 2024
@dgarske dgarske merged commit 32aecf4 into wolfSSL:master Feb 2, 2024
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.

5 participants