Skip to content

Commit e142a96

Browse files
committed
linuxkm/linuxkm_wc_port.h and linuxkm/module_hooks.c: tweak gating for verifyCore and my_kallsyms_lookup_name, and use the latter to reach verifyCore on old FIPS. also tweak the In-core integrity hash check failure." message to supply module-update-fips-hash instructions.
1 parent 354c576 commit e142a96

3 files changed

Lines changed: 82 additions & 40 deletions

File tree

.wolfssl_known_macro_extras

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ CONFIG_ESP_WOLFSSL_NO_HW_RSA_PRI_MULMOD
105105
CONFIG_ESP_WOLFSSL_NO_STACK_SIZE_BUILD_WARNING
106106
CONFIG_FREERTOS_HZ
107107
CONFIG_FREERTOS_UNICORE
108+
CONFIG_HAVE_KPROBES
108109
CONFIG_IDF_TARGET
109110
CONFIG_IDF_TARGET_ARCH_RISCV
110111
CONFIG_IDF_TARGET_ARCH_XTENSA

linuxkm/linuxkm_wc_port.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -447,10 +447,8 @@
447447
#endif
448448
#include <linux/random.h>
449449

450-
#ifndef __PIE__
451-
#if defined(WOLFSSL_LINUXKM_USE_GET_RANDOM_KPROBES) || defined(FIPS_OPTEST)
452-
#include <linux/kprobes.h>
453-
#endif
450+
#if !defined(__PIE__) && defined(CONFIG_HAVE_KPROBES)
451+
#include <linux/kprobes.h>
454452
#endif
455453

456454
#ifdef LINUXKM_LKCAPI_REGISTER

linuxkm/module_hooks.c

Lines changed: 79 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ static int libwolfssl_cleanup(void) {
8585
return ret;
8686
}
8787

88+
#if defined(HAVE_FIPS) && (FIPS_VERSION3_GE(6,0,0) || defined(WOLFCRYPT_FIPS_CORE_DYNAMIC_HASH_VALUE))
89+
extern char verifyCore[WC_SHA256_DIGEST_SIZE*2 + 1];
90+
#endif
91+
8892
#ifdef HAVE_LINUXKM_PIE_SUPPORT
8993

9094
#ifdef DEBUG_LINUXKM_PIE_SUPPORT
@@ -117,7 +121,6 @@ static int set_up_wolfssl_linuxkm_pie_redirect_table(void);
117121
#ifdef HAVE_FIPS
118122
extern const unsigned int wolfCrypt_FIPS_ro_start[];
119123
extern const unsigned int wolfCrypt_FIPS_ro_end[];
120-
extern char verifyCore[WC_SHA256_DIGEST_SIZE*2 + 1];
121124
#endif
122125

123126
#endif /* HAVE_LINUXKM_PIE_SUPPORT */
@@ -128,9 +131,15 @@ static void lkmFipsCb(int ok, int err, const char* hash)
128131
if ((! ok) || (err != 0))
129132
pr_err("ERROR: libwolfssl FIPS error: %s\n", wc_GetErrorString(err));
130133
if (err == WC_NO_ERR_TRACE(IN_CORE_FIPS_E)) {
131-
pr_err("In-core integrity hash check failure.\n"
132-
"Update verifyCore[] in fips_test.c with new hash \"%s\" and rebuild.\n",
133-
hash ? hash : "<null>");
134+
if (hash) {
135+
pr_err("In-core integrity hash check failure.\n"
136+
"Update FIPS hash with \"make module-update-fips-hash FIPS_HASH=%s\".\n",
137+
hash);
138+
}
139+
else {
140+
pr_err("In-core integrity hash check failure.\n");
141+
pr_err("ERROR: could not compute new hash. Contact customer support.\n");
142+
}
134143
}
135144
}
136145
#endif
@@ -389,6 +398,10 @@ int wc_linuxkm_GenerateSeed_IntelRD(struct OS_Seed* os, byte* output, word32 sz)
389398
#include "linuxkm/x86_vector_register_glue.c"
390399
#endif
391400

401+
#ifdef CONFIG_HAVE_KPROBES
402+
static WC_MAYBE_UNUSED void *my_kallsyms_lookup_name(const char *name);
403+
#endif
404+
392405
#ifdef FIPS_OPTEST
393406
#ifndef HAVE_FIPS
394407
#error FIPS_OPTEST requires HAVE_FIPS.
@@ -398,7 +411,6 @@ int wc_linuxkm_GenerateSeed_IntelRD(struct OS_Seed* os, byte* output, word32 sz)
398411
#endif
399412
extern int linuxkm_op_test_1(int argc, const char* argv[]);
400413
extern int linuxkm_op_test_wrapper(void);
401-
static void *my_kallsyms_lookup_name(const char *name);
402414
static wolfSSL_Atomic_Int *conTestFailure_ptr = NULL;
403415
static ssize_t FIPS_optest_trig_handler(struct kobject *kobj, struct kobj_attribute *attr,
404416
const char *buf, size_t count);
@@ -422,9 +434,29 @@ static int wolfssl_init(void)
422434
* updateFipsHash() (WOLFCRYPT_FIPS_CORE_DYNAMIC_HASH_VALUE) to be safe from
423435
* overruns.
424436
*/
425-
if (strlen(verifyCore) != WC_SHA256_DIGEST_SIZE*2) {
426-
pr_err("ERROR: compile-time FIPS hash is the wrong length (expected %d hex digits).\n", WC_SHA256_DIGEST_SIZE*2);
427-
return -ECANCELED;
437+
{
438+
size_t verifyCore_len;
439+
#if FIPS_VERSION3_GE(6,0,0) || defined(WOLFCRYPT_FIPS_CORE_DYNAMIC_HASH_VALUE)
440+
verifyCore_len = strlen(verifyCore);
441+
#else
442+
#ifdef CONFIG_HAVE_KPROBES
443+
char *verifyCore_ptr = my_kallsyms_lookup_name("verifyCore");
444+
if (verifyCore_ptr)
445+
verifyCore_len = strlen(verifyCore_ptr);
446+
else
447+
#endif /* CONFIG_HAVE_KPROBES */
448+
{
449+
/* can't check -- have to assume. */
450+
#if defined(CONFIG_HAVE_KPROBES) && (defined(DEBUG_LINUXKM_PIE_SUPPORT) || defined(WOLFSSL_LINUXKM_VERBOSE_DEBUG))
451+
pr_err("INFO: couldn't get verifyCore_ptr -- skipping verifyCore length check.\n");
452+
#endif
453+
verifyCore_len = WC_SHA256_DIGEST_SIZE*2;
454+
}
455+
#endif
456+
if (verifyCore_len != WC_SHA256_DIGEST_SIZE*2) {
457+
pr_err("ERROR: compile-time FIPS hash is the wrong length (expected %d hex digits, got %zu).\n", WC_SHA256_DIGEST_SIZE*2, verifyCore_len);
458+
return -ECANCELED;
459+
}
428460
}
429461

430462
#ifdef WOLFCRYPT_FIPS_CORE_DYNAMIC_HASH_VALUE
@@ -573,8 +605,15 @@ static int wolfssl_init(void)
573605
pr_err("ERROR: wolfCrypt_GetStatus_fips() failed with code %d: %s\n", ret, wc_GetErrorString(ret));
574606
if (ret == WC_NO_ERR_TRACE(IN_CORE_FIPS_E)) {
575607
const char *newhash = wolfCrypt_GetCoreHash_fips();
576-
pr_err("Update verifyCore[] in fips_test.c with new hash \"%s\" and rebuild.\n",
577-
newhash ? newhash : "<null>");
608+
if (newhash) {
609+
pr_err("In-core integrity hash check failure.\n"
610+
"Update FIPS hash with \"make module-update-fips-hash FIPS_HASH=%s\".\n",
611+
newhash);
612+
}
613+
else {
614+
pr_err("In-core integrity hash check failure.\n");
615+
pr_err("ERROR: could not compute new hash. Contact customer support.\n");
616+
}
578617
}
579618
return -ECANCELED;
580619
}
@@ -1601,6 +1640,36 @@ static int updateFipsHash(void)
16011640

16021641
#endif /* WOLFCRYPT_FIPS_CORE_DYNAMIC_HASH_VALUE */
16031642

1643+
#ifdef CONFIG_HAVE_KPROBES
1644+
1645+
static WC_MAYBE_UNUSED void *my_kallsyms_lookup_name(const char *name) {
1646+
static typeof(kallsyms_lookup_name) *kallsyms_lookup_name_ptr = NULL;
1647+
static struct kprobe kallsyms_lookup_name_kp = {
1648+
.symbol_name = "kallsyms_lookup_name"
1649+
};
1650+
unsigned long a;
1651+
1652+
if (! kallsyms_lookup_name_ptr) {
1653+
int ret;
1654+
kallsyms_lookup_name_kp.addr = NULL;
1655+
if ((ret = register_kprobe(&kallsyms_lookup_name_kp)) != 0) {
1656+
pr_err_once("ERROR: register_kprobe(&kallsyms_lookup_name_kp) failed: %d", ret);
1657+
return 0;
1658+
}
1659+
kallsyms_lookup_name_ptr = (typeof(kallsyms_lookup_name_ptr))kallsyms_lookup_name_kp.addr;
1660+
unregister_kprobe(&kallsyms_lookup_name_kp);
1661+
if (! kallsyms_lookup_name_ptr) {
1662+
pr_err_once("ERROR: kallsyms_lookup_name_kp.addr is null.");
1663+
return 0;
1664+
}
1665+
}
1666+
1667+
a = kallsyms_lookup_name_ptr(name);
1668+
return (void *)a;
1669+
}
1670+
1671+
#endif /* CONFIG_HAVE_KPROBES */
1672+
16041673
#ifdef HAVE_FIPS
16051674

16061675
static ssize_t FIPS_rerun_self_test_handler(struct kobject *kobj, struct kobj_attribute *attr,
@@ -1651,32 +1720,6 @@ static ssize_t FIPS_rerun_self_test_handler(struct kobject *kobj, struct kobj_at
16511720

16521721
#ifdef FIPS_OPTEST
16531722

1654-
static void *my_kallsyms_lookup_name(const char *name) {
1655-
static typeof(kallsyms_lookup_name) *kallsyms_lookup_name_ptr = NULL;
1656-
static struct kprobe kallsyms_lookup_name_kp = {
1657-
.symbol_name = "kallsyms_lookup_name"
1658-
};
1659-
unsigned long a;
1660-
1661-
if (! kallsyms_lookup_name_ptr) {
1662-
int ret;
1663-
kallsyms_lookup_name_kp.addr = NULL;
1664-
if ((ret = register_kprobe(&kallsyms_lookup_name_kp)) != 0) {
1665-
pr_err_once("ERROR: register_kprobe(&kallsyms_lookup_name_kp) failed: %d", ret);
1666-
return 0;
1667-
}
1668-
kallsyms_lookup_name_ptr = (typeof(kallsyms_lookup_name_ptr))kallsyms_lookup_name_kp.addr;
1669-
unregister_kprobe(&kallsyms_lookup_name_kp);
1670-
if (! kallsyms_lookup_name_ptr) {
1671-
pr_err_once("ERROR: kallsyms_lookup_name_kp.addr is null.");
1672-
return 0;
1673-
}
1674-
}
1675-
1676-
a = kallsyms_lookup_name_ptr(name);
1677-
return (void *)a;
1678-
}
1679-
16801723
typedef struct test_func_args {
16811724
int return_code;
16821725
} test_func_args;

0 commit comments

Comments
 (0)