Skip to content

Commit 5dbf2e7

Browse files
committed
linuxkm/linuxkm_memory.c: in wc_fips_generate_hash(), fix handling of failed hmac_update() in text segment loop;
linuxkm/module_hooks.c: in wolfssl_init() DEBUG_LINUXKM_PIE_SUPPORT section, render stabilized_rodata_hash; in my_kallsyms_lookup_name(), gate kprobe failure messages behind WOLFSSL_LINUXKM_VERBOSE_DEBUG.
1 parent 1d21858 commit 5dbf2e7

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

linuxkm/linuxkm_memory.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,11 @@ int wc_fips_generate_hash(
865865
text_p += progress;
866866
}
867867

868+
if (ret) {
869+
XFREE(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
870+
goto out;
871+
}
872+
868873
cur_reloc_index = -1;
869874
while (rodata_p < (const byte *)seg_map->fips_rodata_end) {
870875
size_t rodata_in_out_len = min(WOLFSSL_SEGMENT_CANONICALIZER_BUFSIZ,
@@ -905,6 +910,9 @@ int wc_fips_generate_hash(
905910
}
906911

907912
XFREE(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
913+
914+
if (ret)
915+
goto out;
908916
}
909917

910918
#else /* ! (WC_SYM_RELOC_TABLES || WC_SYM_RELOC_TABLES_SUPPORT) */
@@ -936,14 +944,14 @@ int wc_fips_generate_hash(
936944

937945
WC_SANITIZE_ENABLE();
938946

939-
#endif /* ! (WC_SYM_RELOC_TABLES || WC_SYM_RELOC_TABLES_SUPPORT) */
940-
941947
if (ret) {
942948
RELOC_DEBUG_PRINTF("ERROR: hmac_update failed: err %d\n", ret);
943949
ret = BAD_STATE_E;
944950
goto out;
945951
}
946952

953+
#endif /* ! (WC_SYM_RELOC_TABLES || WC_SYM_RELOC_TABLES_SUPPORT) */
954+
947955
ret = hmac_final(hmac_ctx, hash, digest_size);
948956
if (ret) {
949957
RELOC_DEBUG_PRINTF("ERROR: hmac_final failed: err %d\n", ret);

linuxkm/module_hooks.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -778,12 +778,13 @@ static int wolfssl_init(void)
778778
* the true module start address, which is potentially useful to an
779779
* attacker.
780780
*/
781-
pr_info("wolfCrypt segment hashes (spans): text 0x%x (%llu), rodata 0x%x (%llu), offset %c0x%llx, canon text 0x%x\n",
781+
pr_info("wolfCrypt segment hashes (spans): text 0x%x (%llu), rodata 0x%x (%llu), offset %c0x%llx, canon text 0x%x, canon rodata 0x%x\n",
782782
text_hash, (unsigned long long)((uintptr_t)__wc_text_end - (uintptr_t)__wc_text_start),
783783
rodata_hash, (unsigned long long)((uintptr_t)__wc_rodata_end - (uintptr_t)__wc_rodata_start),
784784
(uintptr_t)__wc_text_start < (uintptr_t)&__wc_rodata_start[0] ? '+' : '-',
785785
(uintptr_t)__wc_text_start < (uintptr_t)&__wc_rodata_start[0] ? (unsigned long long)((uintptr_t)&__wc_rodata_start[0] - (uintptr_t)__wc_text_start) : (unsigned long long)((uintptr_t)__wc_text_start - (uintptr_t)&__wc_rodata_start[0]),
786-
stabilized_text_hash);
786+
stabilized_text_hash,
787+
stabilized_rodata_hash);
787788

788789
pr_info("wolfCrypt segments: text=%llx-%llx, rodata=%llx-%llx, "
789790
"rwdata=%llx-%llx, bss=%llx-%llx\n",
@@ -1847,13 +1848,17 @@ static WC_MAYBE_UNUSED void *my_kallsyms_lookup_name(const char *name) {
18471848
int ret;
18481849
kallsyms_lookup_name_kp.addr = NULL;
18491850
if ((ret = register_kprobe(&kallsyms_lookup_name_kp)) != 0) {
1851+
#ifdef WOLFSSL_LINUXKM_VERBOSE_DEBUG
18501852
pr_err_once("ERROR: register_kprobe(&kallsyms_lookup_name_kp) failed: %d\n", ret);
1853+
#endif
18511854
return 0;
18521855
}
18531856
kallsyms_lookup_name_ptr = (typeof(kallsyms_lookup_name_ptr))kallsyms_lookup_name_kp.addr;
18541857
unregister_kprobe(&kallsyms_lookup_name_kp);
18551858
if (! kallsyms_lookup_name_ptr) {
1859+
#ifdef WOLFSSL_LINUXKM_VERBOSE_DEBUG
18561860
pr_err_once("ERROR: kallsyms_lookup_name_kp.addr is null.\n");
1861+
#endif
18571862
return 0;
18581863
}
18591864
}

0 commit comments

Comments
 (0)