Skip to content

20260204-linuxkm-fips-hash#9800

Open
douzzer wants to merge 1 commit intowolfSSL:masterfrom
douzzer:20260204-linuxkm-fips-hash
Open

20260204-linuxkm-fips-hash#9800
douzzer wants to merge 1 commit intowolfSSL:masterfrom
douzzer:20260204-linuxkm-fips-hash

Conversation

@douzzer
Copy link
Contributor

@douzzer douzzer commented Feb 19, 2026

Implement Linux kernel module FIPS integrity hash offline calculation:

Add:

  • linuxkm/linuxkm-fips-hash.c
  • linuxkm/linuxkm-fips-hash-wrapper.sh
  • linuxkm/linuxkm_memory.h

Move from linuxkm/module_hooks.c to linuxkm/linuxkm_memory.c:

  • reloc_layouts[]
  • find_reloc_tab_offset()
  • the body of wc_linuxkm_normalize_relocations() as wc_reloc_normalize_text()
  • most of updateFipsHash() as wc_fips_generate_hash()

Move from linuxkm/linuxkm_wc_port.h to linuxkm/linuxkm_memory.h:

  • struct wc_linuxkm_pie_reloc_tab_ent
  • enum wc_reloc_dest_segment
  • enum wc_reloc_type

linuxkm/Makefile:

  • Update GENERATE_RELOC_TAB recipe to populate new fields in struct wc_reloc_table_ent.
  • Add targets:
    • libwolfssl-user-build/src/.libs/libwolfssl.so
    • linuxkm-fips-hash
    • module-with-matching-fips-hash
    • module-with-matching-fips-hash-no-sign
  • Add support for alternate target module name, via LIBWOLFSSL_NAME make variable.

linuxkm/linuxkm_wc_port.h and linuxkm/module_hooks.c:

  • Fixes to make linuxkm-pie work with CONFIG_KASAN.
  • Implement WC_LINUXKM_STACK_DEBUG:
    • wc_linuxkm_stack_bottom()
    • wc_linuxkm_stack_top()
    • wc_linuxkm_stack_current()
    • wc_linuxkm_stack_left()
    • wc_linuxkm_stack_hwm_prepare()
    • wc_linuxkm_stack_hwm_measure_rel()
    • wc_linuxkm_stack_hwm_measure_total()

wolfssl/wolfcrypt/settings.h:

  • When WOLFSSL_KERNEL_MODE, make sure WOLFSSL_GENERAL_ALIGNMENT is at least SIZEOF_LONG.
  • When WOLFCRYPT_FIPS_CORE_DYNAMIC_HASH_VALUE, make sure WOLFSSL_BASE16 is defined.

configure.ac and wolfcrypt/benchmark/benchmark.c: Disable scrypt when KERNEL_MODE_DEFAULTS, due to excessive memory requirements.

tested with

wolfssl-multi-test.sh ...
pr-check
'.*insmod.*'
'.*linuxkm.*'

with tweaks to wolfssl-multi-test.sh to exercise and verify offline hash calculation by default in FIPS do_linuxkm_scenario_load_with_self_test() scenarios, and in the FIPS aarch64 linuxkm scenarios.

Add:

* linuxkm/linuxkm-fips-hash.c
* linuxkm/linuxkm-fips-hash-wrapper.sh
* linuxkm/linuxkm_memory.h

Move from linuxkm/module_hooks.c to linuxkm/linuxkm_memory.c:
* reloc_layouts[]
* find_reloc_tab_offset()
* the body of wc_linuxkm_normalize_relocations() as wc_reloc_normalize_text()
* most of updateFipsHash() as wc_fips_generate_hash()

Move from linuxkm/linuxkm_wc_port.h to linuxkm/linuxkm_memory.h:
* struct wc_linuxkm_pie_reloc_tab_ent
* enum wc_reloc_dest_segment
* enum wc_reloc_type

linuxkm/Makefile:
* Update GENERATE_RELOC_TAB recipe to populate new fields in struct wc_reloc_table_ent.
* Add targets:
  * libwolfssl-user-build/src/.libs/libwolfssl.so
  * linuxkm-fips-hash
  * module-with-matching-fips-hash
  * module-with-matching-fips-hash-no-sign
* Add support for alternate target module name, via LIBWOLFSSL_NAME make variable.

linuxkm/linuxkm_wc_port.h and linuxkm/module_hooks.c:
* Fixes to make linuxkm-pie work with CONFIG_KASAN.
* Implement WC_LINUXKM_STACK_DEBUG:
  * wc_linuxkm_stack_bottom()
  * wc_linuxkm_stack_top()
  * wc_linuxkm_stack_current()
  * wc_linuxkm_stack_left()
  * wc_linuxkm_stack_hwm_prepare()
  * wc_linuxkm_stack_hwm_measure_rel()
  * wc_linuxkm_stack_hwm_measure_total()

wolfssl/wolfcrypt/settings.h:
* When WOLFSSL_KERNEL_MODE, make sure WOLFSSL_GENERAL_ALIGNMENT is at least SIZEOF_LONG.
* When WOLFCRYPT_FIPS_CORE_DYNAMIC_HASH_VALUE, make sure WOLFSSL_BASE16 is defined.

configure.ac and wolfcrypt/benchmark/benchmark.c: Disable scrypt when KERNEL_MODE_DEFAULTS, due to excessive memory requirements.
#endif

/* use kB instead of mB for embedded benchmarking */
/* use kB instead of MB for embedded benchmarking */
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we make the k capital as well?

ret = wc_fips_generate_hash(
&seg_map,
FIPS_IN_CORE_DIGEST_SIZE,
coreKey,
Copy link
Contributor

Choose a reason for hiding this comment

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

user_coreKey is never used after assignment, only coreKey.

(seg_map.reloc_tab_len_start >= seg_map.reloc_tab_len_end) ||
(seg_map.reloc_tab_len_end >= st.st_size))
{
fprintf(stderr, "%s: supplied reloc_tab fencepost(s) are out of bounds.\n", progname, mod_path, st.st_size);
Copy link
Contributor

Choose a reason for hiding this comment

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

format arguments are missing


if (seg_map.verifyCore_end - seg_map.verifyCore_start != new_verifyCore_size) {
fprintf(stderr, "%s: unexpected verifyCore length %zu.\n", progname, (size_t)(seg_map.verifyCore_end - seg_map.verifyCore_start));
goto out;
Copy link
Contributor

Choose a reason for hiding this comment

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

should ret be set to non zero here?


if (new_verifyCore_size < sizeof new_verifyCore) {
fprintf(stderr, "%s: wc_fips_generate_hash() returned unexpected verifyCore length %u.\n", progname, new_verifyCore_size);
goto out;
Copy link
Contributor

Choose a reason for hiding this comment

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

what about ret here?

int mod_fd;
struct stat st;
byte *mod_map = NULL;
word32 reloc_tab_len;
Copy link
Contributor

Choose a reason for hiding this comment

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

unused?

{ }
};

ret = wolfCrypt_Init();
Copy link
Contributor

Choose a reason for hiding this comment

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

we need to call wolfCrypt_Cleanup() at the end


ret = wc_HmacInit(&hmac, NULL, INVALID_DEVID);
if (ret != 0) {
fprintf(stderr, "%s: wc_HmacInit() failed: %s.\n", progname, wc_GetErrorString(ret));
Copy link
Contributor

Choose a reason for hiding this comment

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

mmap cleanup on error path

@sameehj
Copy link
Contributor

sameehj commented Feb 19, 2026

Hey @douzzer,

Nice work on the offline FIPS hash PR! A few docs suggestions:

README update -- A section in linuxkm/README.md about the offline hash workflow and the new make targets (module-with-matching-fips-hash, etc.) would help discoverability.
linuxkm-fips-hash tool -- A brief usage write-up beyond --help (even just a header comment in the .c) would save folks from reading the wrapper script.
API docs -- wc_fips_generate_hash() and wc_reloc_normalize_text() are public API -- doxygen comments on them and the key structs/callbacks would be great.
Breaking change note -- wc_reloc_table_ent layout changed (new fields, packed, enums now start at 1 instead of 0). Worth a note for anyone with custom reloc tooling.

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

Comments