Skip to content

Commit 17e992a

Browse files
authored
Merge pull request #9589 from douzzer/20251226-fixes
20251226-fixes
2 parents e70e7cb + 7bbd28d commit 17e992a

File tree

4 files changed

+51
-36
lines changed

4 files changed

+51
-36
lines changed

linuxkm/lkcapi_sha_glue.c

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2150,25 +2150,18 @@ static int wc_linuxkm_drbg_startup(void)
21502150
}
21512151

21522152
static int wc_linuxkm_drbg_cleanup(void) {
2153-
int cur_refcnt = WC_LKM_REFCOUNT_TO_INT(wc_linuxkm_drbg.base.cra_refcnt);
2153+
int cur_refcnt;
21542154

21552155
if (! wc_linuxkm_drbg_loaded) {
21562156
pr_err("ERROR: wc_linuxkm_drbg_cleanup called with ! wc_linuxkm_drbg_loaded");
21572157
return -EINVAL;
21582158
}
21592159

2160-
if (cur_refcnt - wc_linuxkm_drbg_default_instance_registered != 1) {
2161-
pr_err("ERROR: wc_linuxkm_drbg_cleanup called with refcnt = %d, with wc_linuxkm_drbg %sset as default rng",
2162-
cur_refcnt, wc_linuxkm_drbg_default_instance_registered ? "" : "not ");
2163-
return -EBUSY;
2164-
}
2165-
2166-
/* The below is racey, but the kernel doesn't provide any other way. It's
2167-
* written to be retryable.
2168-
*/
2169-
21702160
#ifdef LINUXKM_LKCAPI_REGISTER_HASH_DRBG_DEFAULT
21712161
if (wc_linuxkm_drbg_default_instance_registered) {
2162+
/* These deinstallations are racey, but the kernel doesn't provide any other
2163+
* way. It's written to be retryable.
2164+
*/
21722165
int ret;
21732166

21742167
#ifdef LINUXKM_DRBG_GET_RANDOM_BYTES
@@ -2193,16 +2186,16 @@ static int wc_linuxkm_drbg_cleanup(void) {
21932186
#elif defined(WOLFSSL_LINUXKM_USE_GET_RANDOM_KPROBES)
21942187

21952188
if (wc_get_random_bytes_kprobe_installed) {
2196-
wc_get_random_bytes_kprobe_installed = 0;
2197-
barrier();
21982189
unregister_kprobe(&wc_get_random_bytes_kprobe);
2190+
barrier();
2191+
wc_get_random_bytes_kprobe_installed = 0;
21992192
pr_info("libwolfssl: wc_get_random_bytes_kprobe uninstalled\n");
22002193
}
22012194
#ifdef WOLFSSL_LINUXKM_USE_GET_RANDOM_USER_KRETPROBE
22022195
if (wc_get_random_bytes_user_kretprobe_installed) {
2203-
wc_get_random_bytes_user_kretprobe_installed = 0;
2204-
barrier();
22052196
unregister_kretprobe(&wc_get_random_bytes_user_kretprobe);
2197+
barrier();
2198+
wc_get_random_bytes_user_kretprobe_installed = 0;
22062199
pr_info("libwolfssl: wc_get_random_bytes_user_kretprobe uninstalled\n");
22072200
}
22082201
#endif /* WOLFSSL_LINUXKM_USE_GET_RANDOM_USER_KRETPROBE */
@@ -2218,25 +2211,25 @@ static int wc_linuxkm_drbg_cleanup(void) {
22182211
pr_err("ERROR: crypto_del_default_rng failed: %d", ret);
22192212
return ret;
22202213
}
2221-
cur_refcnt = WC_LKM_REFCOUNT_TO_INT(wc_linuxkm_drbg.base.cra_refcnt);
2222-
if (cur_refcnt != 1) {
2223-
pr_warn("WARNING: wc_linuxkm_drbg refcnt = %d after crypto_del_default_rng()", cur_refcnt);
2224-
return -EINVAL;
2225-
}
2214+
2215+
wc_linuxkm_drbg_default_instance_registered = 0;
22262216
}
22272217
#endif /* LINUXKM_LKCAPI_REGISTER_HASH_DRBG_DEFAULT */
22282218

2219+
cur_refcnt = WC_LKM_REFCOUNT_TO_INT(wc_linuxkm_drbg.base.cra_refcnt);
2220+
2221+
if (cur_refcnt != 1) {
2222+
pr_err("ERROR: wc_linuxkm_drbg_cleanup called with refcnt = %d", cur_refcnt);
2223+
return -EBUSY;
2224+
}
2225+
22292226
crypto_unregister_rng(&wc_linuxkm_drbg);
22302227

22312228
if (! (wc_linuxkm_drbg.base.cra_flags & CRYPTO_ALG_DEAD)) {
22322229
pr_warn("WARNING: wc_linuxkm_drbg_cleanup: after crypto_unregister_rng, wc_linuxkm_drbg isn't dead.");
22332230
return -EBUSY;
22342231
}
22352232

2236-
#ifdef LINUXKM_LKCAPI_REGISTER_HASH_DRBG_DEFAULT
2237-
wc_linuxkm_drbg_default_instance_registered = 0;
2238-
#endif /* LINUXKM_LKCAPI_REGISTER_HASH_DRBG_DEFAULT */
2239-
22402233
wc_linuxkm_drbg_loaded = 0;
22412234

22422235
return 0;

wolfcrypt/benchmark/benchmark.c

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10554,35 +10554,39 @@ static void bench_mlkem_encap(int type, const char* name, int keySize,
1055410554
int ret = 0, times, count, pending = 0;
1055510555
double start;
1055610556
const char**desc = bench_desc_words[lng_index];
10557-
byte ct[WC_ML_KEM_MAX_CIPHER_TEXT_SIZE];
10558-
byte ss[WC_ML_KEM_SS_SZ];
10559-
byte pub[WC_ML_KEM_MAX_PUBLIC_KEY_SIZE];
10557+
WC_DECLARE_VAR(ct, byte, WC_ML_KEM_MAX_CIPHER_TEXT_SIZE, HEAP_HINT);
10558+
WC_DECLARE_VAR(ss, byte, WC_ML_KEM_SS_SZ, HEAP_HINT);
10559+
WC_DECLARE_VAR(pub, byte, WC_ML_KEM_MAX_PUBLIC_KEY_SIZE, HEAP_HINT);
1056010560
word32 pubLen;
1056110561
word32 ctSz;
1056210562
DECLARE_MULTI_VALUE_STATS_VARS()
1056310563

1056410564
bench_stats_prepare();
1056510565

10566+
WC_ALLOC_VAR(ct, byte, WC_ML_KEM_MAX_CIPHER_TEXT_SIZE, HEAP_HINT);
10567+
WC_ALLOC_VAR(ss, byte, WC_ML_KEM_SS_SZ, HEAP_HINT);
10568+
WC_ALLOC_VAR(pub, byte, WC_ML_KEM_MAX_PUBLIC_KEY_SIZE, HEAP_HINT);
10569+
1056610570
ret = wc_KyberKey_PublicKeySize(key1, &pubLen);
1056710571
if (ret != 0) {
10568-
return;
10572+
goto exit;
1056910573
}
1057010574
ret = wc_KyberKey_EncodePublicKey(key1, pub, pubLen);
1057110575
if (ret != 0) {
10572-
return;
10576+
goto exit;
1057310577
}
1057410578
ret = wc_KyberKey_Init(type, key2, HEAP_HINT, INVALID_DEVID);
1057510579
if (ret != 0) {
10576-
return;
10580+
goto exit;
1057710581
}
1057810582
ret = wc_KyberKey_DecodePublicKey(key2, pub, pubLen);
1057910583
if (ret != 0) {
10580-
return;
10584+
goto exit;
1058110585
}
1058210586

1058310587
ret = wc_KyberKey_CipherTextSize(key2, &ctSz);
1058410588
if (ret != 0) {
10585-
return;
10589+
goto exit;
1058610590
}
1058710591

1058810592
#ifndef WOLFSSL_MLKEM_NO_ENCAPSULATE
@@ -10641,7 +10645,19 @@ static void bench_mlkem_encap(int type, const char* name, int keySize,
1064110645
#ifdef MULTI_VALUE_STATISTICS
1064210646
bench_multi_value_stats(max, min, sum, squareSum, runs);
1064310647
#endif
10648+
1064410649
#endif
10650+
10651+
exit:
10652+
10653+
WC_FREE_VAR(ct, HEAP_HINT);
10654+
WC_FREE_VAR(ss, HEAP_HINT);
10655+
WC_FREE_VAR(pub, HEAP_HINT);
10656+
10657+
if (ret != 0)
10658+
printf("error: bench_mlkem_encap() failed with code %d.\n", ret);
10659+
10660+
return;
1064510661
}
1064610662
#endif
1064710663

wolfcrypt/src/aes.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4987,6 +4987,8 @@ static void AesSetKey_C(Aes* aes, const byte* key, word32 keySz, int dir)
49874987
}
49884988
#endif /* WOLFSSL_AESNI */
49894989

4990+
#ifndef WC_C_DYNAMIC_FALLBACK
4991+
49904992
#if defined(WOLFSSL_ARMASM)
49914993
#if !defined(WOLFSSL_ARMASM_NO_HW_CRYPTO)
49924994
#ifndef __aarch64__
@@ -5117,6 +5119,9 @@ static void AesSetKey_C(Aes* aes, const byte* key, word32 keySz, int dir)
51175119
#endif
51185120
return ret;
51195121
#endif
5122+
5123+
#endif /* !WC_C_DYNAMIC_FALLBACK */
5124+
51205125
} /* wc_AesSetKeyLocal */
51215126

51225127
int wc_AesSetKey(Aes* aes, const byte* userKey, word32 keylen,

wolfcrypt/src/random.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3497,10 +3497,6 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
34973497
}
34983498
#endif
34993499

3500-
#endif /* (!HAVE_INTEL_RDSEED && !HAVE_AMD_RDSEED) || !FORCE_FAILURE_RDSEED */
3501-
3502-
#endif /*!HAVE_ENTROPY_MEMUSE || !ENTROPY_MEMUSE_FORCE_FAILURE */
3503-
35043500
#ifndef NO_FILESYSTEM
35053501
#ifndef NO_DEV_URANDOM /* way to disable use of /dev/urandom */
35063502
os->fd = open("/dev/urandom", O_RDONLY);
@@ -3548,6 +3544,11 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
35483544
#endif /* NO_FILESYSTEM */
35493545

35503546
return ret;
3547+
3548+
#endif /* (!HAVE_INTEL_RDSEED && !HAVE_AMD_RDSEED) || !FORCE_FAILURE_RDSEED */
3549+
3550+
#endif /*!HAVE_ENTROPY_MEMUSE || !ENTROPY_MEMUSE_FORCE_FAILURE */
3551+
35513552
}
35523553

35533554
#endif

0 commit comments

Comments
 (0)