Skip to content

Commit ae15693

Browse files
committed
linuxkm/lkcapi_sha_glue.c: in wc_linuxkm_drbg_generate() and wc_linuxkm_drbg_seed(), check retval from wc_LockMutex().
wolfcrypt/src/random.c: in Hash_DRBG_Generate(), restore smallstack path for digest[], but use non-smallstack path for WOLFSSL_LINUXKM.
1 parent dbc3435 commit ae15693

2 files changed

Lines changed: 20 additions & 10 deletions

File tree

linuxkm/lkcapi_sha_glue.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -971,18 +971,17 @@ static int wc_linuxkm_drbg_generate(struct crypto_rng *tfm,
971971
{
972972
struct wc_linuxkm_drbg_ctx *ctx = (struct wc_linuxkm_drbg_ctx *)crypto_rng_ctx(tfm);
973973
int ret;
974-
int my_cpu =
975-
raw_smp_processor_id(); /* Note, core is not locked, so the actual core
976-
* ID may change while executing, hence the
977-
* mutex.
978-
* The mutex is also needed to coordinate with
979-
* wc_linuxkm_drbg_seed(), which seeds all
980-
* instances.
981-
*/
974+
/* Note, core is not locked, so the actual core ID may change while
975+
* executing, hence the mutex.
976+
* The mutex is also needed to coordinate with wc_linuxkm_drbg_seed(), which
977+
* seeds all instances.
978+
*/
979+
int my_cpu = raw_smp_processor_id();
982980
wolfSSL_Mutex *lock = &ctx->rngs[my_cpu].lock;
983981
WC_RNG *rng = &ctx->rngs[my_cpu].rng;
984982

985-
wc_LockMutex(lock);
983+
if (wc_LockMutex(lock) != 0)
984+
return -EINVAL;
986985

987986
if (slen > 0) {
988987
ret = wc_RNG_DRBG_Reseed(rng, src, slen);
@@ -1029,7 +1028,8 @@ static int wc_linuxkm_drbg_seed(struct crypto_rng *tfm,
10291028
seed_copy[0] = (u8)(i >> 8);
10301029
seed_copy[1] = (u8)i;
10311030

1032-
wc_LockMutex(lock);
1031+
if (wc_LockMutex(lock) != 0)
1032+
return -EINVAL;
10331033

10341034
ret = wc_RNG_DRBG_Reseed(rng, seed_copy, slen + 2);
10351035
if (ret != 0) {

wolfcrypt/src/random.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,14 @@ static int Hash_DRBG_Generate(DRBG_internal* drbg, byte* out, word32 outSz)
647647
return DRBG_NEED_RESEED;
648648
}
649649
else {
650+
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_LINUXKM)
651+
byte* digest = (byte*)XMALLOC(WC_SHA256_DIGEST_SIZE, drbg->heap,
652+
DYNAMIC_TYPE_DIGEST);
653+
if (digest == NULL)
654+
return DRBG_FAILURE;
655+
#else
650656
byte digest[WC_SHA256_DIGEST_SIZE];
657+
#endif
651658

652659
type = drbgGenerateH;
653660
reseedCtr = drbg->reseedCtr;
@@ -685,6 +692,9 @@ static int Hash_DRBG_Generate(DRBG_internal* drbg, byte* out, word32 outSz)
685692
drbg->reseedCtr++;
686693
}
687694
ForceZero(digest, WC_SHA256_DIGEST_SIZE);
695+
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_LINUXKM)
696+
XFREE(digest, drbg->heap, DYNAMIC_TYPE_DIGEST);
697+
#endif
688698
}
689699

690700
return (ret == 0) ? DRBG_SUCCESS : DRBG_FAILURE;

0 commit comments

Comments
 (0)