Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
546ac0a
linuxkm/lkcapi_aes_glue.c: clean up pr_err()s on allocation failures.
douzzer Jun 11, 2026
1c9abac
fix F-672: Copy-Paste Duplicate: pkcs1_sha384 Unregistered Twice in B…
douzzer Jun 11, 2026
9c1d9c1
fix F-673: Wrong sizeof Type in Allocation Failure Error Message
douzzer Jun 11, 2026
f48efe5
fix F-705: Missing wc_RsaSetRNG in sig_alg km_pkcs1_set_pub After Key…
douzzer Jun 11, 2026
682a09d
fix F-1424: Sysfs Node Resource Leak When Second Install Fails
douzzer Jun 11, 2026
8c1013a
fix F-1425: PTR_ERR on malloc Result Always Yields 0 in Error Message
douzzer Jun 11, 2026
b3cb06e
fix F-1426: PTR_ERR on malloc Results Always Yields 0 in AES-GCM Self…
douzzer Jun 11, 2026
21a57cf
Fixes for Fenrir items:
douzzer Jun 12, 2026
1df8d45
fix F-3948: Missing KAT mismatch check in aes_xts_256_test partial bl…
douzzer Jun 12, 2026
85091c7
fix F-676: Missing ForceZero on RSA Decrypted Plaintext Buffer
douzzer Jun 12, 2026
38c2477
fix F-677: SHA3 Init Memory Leak on wc_InitSha3 Failure
douzzer Jun 12, 2026
3057314
fix F-678: SHA3 Finup Memory Leak on Update Failure
douzzer Jun 12, 2026
cac0f23
fix F-679: HMAC Finup Memory Leak on Update Failure
douzzer Jun 12, 2026
ec4146a
fix F-680: ECDH Init Error Paths Leak RNG Resource
douzzer Jun 12, 2026
591f52f
fix F-681: DH/FFDHE Init Error Paths Leak RNG Resource
douzzer Jun 12, 2026
8110d56
fix F-708: DH km_dh_set_secret Missing Private Key Cleanup on Error Path
douzzer Jun 12, 2026
0272f0a
fix F-709: AES-XTS Stream Finalize Returns Untranslated wolfCrypt Err…
douzzer Jun 12, 2026
c84c44f
fix F-1238: Integer Overflow in ECDSA Verify Allocation of sig_len + …
douzzer Jun 12, 2026
c071c29
fixes for Skoll-flagged linuxkm/ flubs in #10658:
douzzer Jun 12, 2026
ab69af5
fixes for
douzzer Jun 12, 2026
5030846
fix F-1430: AES-GCM Non-Stream Path Returns -EINVAL Instead of Propag…
douzzer Jun 12, 2026
d3279a8
fixes for
douzzer Jun 12, 2026
476cfd6
fix for F-3946: Missing ForceZero on Heap-Allocated HMAC State Buffer…
douzzer Jun 12, 2026
8624bca
fix F-3294: IntelRDseed64_r Stack Buffer Containing Entropy Cleared w…
douzzer Jun 12, 2026
1b22e4b
fix F-4409: Integer Overflow in PKCS1 Sign Length Check Allows Heap B…
douzzer Jun 12, 2026
4d77baf
linuxkm/module_hooks.c: fix flub in IntelRDseed64_r() ForceZero() call;
douzzer Jun 13, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 65 additions & 26 deletions linuxkm/lkcapi_aes_glue.c
Original file line number Diff line number Diff line change
Expand Up @@ -1129,15 +1129,16 @@ static int AesGcmCrypt_1(struct aead_request *req, int decrypt_p, int rfc4106_p)
tfm = crypto_aead_reqtfm(req);
ctx = crypto_aead_ctx(tfm);

if (((word32)req->assoclen + (word32)req->cryptlen) !=
((word64)req->assoclen + (word64)req->cryptlen))
{
return -EOVERFLOW;
}

if (decrypt_p) {
/* Copy out original auth tag from req->src. */
if (req->cryptlen < tfm->authsize)
return -EINVAL;
if (((word32)req->assoclen + (word32)req->cryptlen) !=
((word64)req->assoclen + (word64)req->cryptlen))
{
return -EOVERFLOW;
}
scatterwalk_map_and_copy(authTag, req->src,
req->assoclen + req->cryptlen - tfm->authsize,
tfm->authsize, 0);
Expand Down Expand Up @@ -1355,15 +1356,16 @@ static int AesGcmCrypt_1(struct aead_request *req, int decrypt_p, int rfc4106_p)
tfm = crypto_aead_reqtfm(req);
ctx = crypto_aead_ctx(tfm);

if (((word32)req->assoclen + (word32)req->cryptlen) !=
((word64)req->assoclen + (word64)req->cryptlen))
{
return -EOVERFLOW;
}

if (decrypt_p) {
/* Copy out original auth tag from req->src. */
if (req->cryptlen < tfm->authsize)
return -EINVAL;
if (((word32)req->assoclen + (word32)req->cryptlen) !=
((word64)req->assoclen + (word64)req->cryptlen))
{
return -EOVERFLOW;
}
scatterwalk_map_and_copy(authTag, req->src,
req->assoclen + req->cryptlen - tfm->authsize,
tfm->authsize, 0);
Expand All @@ -1378,7 +1380,7 @@ static int AesGcmCrypt_1(struct aead_request *req, int decrypt_p, int rfc4106_p)
crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm)),
decrypt_p ? "skcipher_walk_aead_decrypt" : "skcipher_walk_aead_encrypt",
err);
return -EINVAL;
return err;
}

err = km_AesGet(ctx, decrypt_p, 1 /* copy_p */, &aes_copy);
Expand Down Expand Up @@ -1513,6 +1515,7 @@ static int AesGcmCrypt_1(struct aead_request *req, int decrypt_p, int rfc4106_p)
out:

if (sg_buf) {
ForceZero(sg_buf, req->assoclen + req->cryptlen);
free(sg_buf);
}
else {
Expand Down Expand Up @@ -1835,15 +1838,16 @@ static int AesCcmCrypt_1(struct aead_request *req, int decrypt_p, int rfc4309_p)
tfm = crypto_aead_reqtfm(req);
ctx = crypto_aead_ctx(tfm);

if (((word32)req->assoclen + (word32)req->cryptlen) !=
((word64)req->assoclen + (word64)req->cryptlen))
{
return -EOVERFLOW;
}

if (decrypt_p) {
/* Copy out the original auth tag from req->src. */
if (req->cryptlen < tfm->authsize)
return -EINVAL;
if (((word32)req->assoclen + (word32)req->cryptlen) !=
((word64)req->assoclen + (word64)req->cryptlen))
{
return -EOVERFLOW;
}
scatterwalk_map_and_copy(authTag, req->src,
req->assoclen + req->cryptlen - tfm->authsize,
tfm->authsize, 0);
Expand Down Expand Up @@ -2006,6 +2010,7 @@ static int AesCcmCrypt_1(struct aead_request *req, int decrypt_p, int rfc4309_p)
out:

if (sg_buf) {
ForceZero(sg_buf, req->assoclen + req->cryptlen);
free(sg_buf);
}
else {
Expand Down Expand Up @@ -2312,6 +2317,11 @@ static int km_AesXtsEncrypt(struct skcipher_request *req)
err = skcipher_walk_done(&walk, 0);
} else if (! (stream.bytes_crypted_with_this_tweak & ((word32)WC_AES_BLOCK_SIZE - 1U))) {
err = wc_AesXtsEncryptFinal(ctx->aesXts, NULL, NULL, 0, &stream);
if (unlikely(err)) {
pr_err("%s: wc_AesXtsEncryptFinal failed: %d\n",
crypto_tfm_alg_driver_name(crypto_skcipher_tfm(tfm)), err);
err = -EINVAL;
}
}
}

Expand Down Expand Up @@ -2458,6 +2468,11 @@ static int km_AesXtsDecrypt(struct skcipher_request *req)
err = skcipher_walk_done(&walk, 0);
} else if (! (stream.bytes_crypted_with_this_tweak & ((word32)WC_AES_BLOCK_SIZE - 1U))) {
err = wc_AesXtsDecryptFinal(ctx->aesXts, NULL, NULL, 0, &stream);
if (unlikely(err)) {
pr_err("%s: wc_AesXtsDecryptFinal failed: %d\n",
crypto_tfm_alg_driver_name(crypto_skcipher_tfm(tfm)), err);
err = -EINVAL;
}
}
}

Expand Down Expand Up @@ -3099,12 +3114,14 @@ static int linuxkm_test_aescbc(void)
enc2 = malloc(sizeof(p_vector));
if (!enc2) {
pr_err("error: malloc failed\n");
ret = MEMORY_E;
goto test_cbc_end;
}

dec2 = malloc(sizeof(p_vector));
if (!dec2) {
pr_err("error: malloc failed\n");
ret = MEMORY_E;
goto test_cbc_end;
}

Expand Down Expand Up @@ -3140,7 +3157,7 @@ static int linuxkm_test_aescbc(void)
req = skcipher_request_alloc(tfm, GFP_KERNEL);
if (! req) {
ret = -ENOMEM;
pr_err("error: allocating AES skcipher request %s failed\n",
pr_err("error: allocating AES skcipher request %s failed.\n",
WOLFKM_AESCBC_DRIVER);
goto test_cbc_end;
}
Expand Down Expand Up @@ -3310,12 +3327,14 @@ static int linuxkm_test_aescfb(void)
enc2 = malloc(sizeof(p_vector));
if (!enc2) {
pr_err("error: malloc failed\n");
ret = MEMORY_E;
goto test_cfb_end;
}

dec2 = malloc(sizeof(p_vector));
if (!dec2) {
pr_err("error: malloc failed\n");
ret = MEMORY_E;
goto test_cfb_end;
}

Expand All @@ -3342,7 +3361,7 @@ static int linuxkm_test_aescfb(void)
req = skcipher_request_alloc(tfm, GFP_KERNEL);
if (! req) {
ret = -ENOMEM;
pr_err("error: allocating AES skcipher request %s failed\n",
pr_err("error: allocating AES skcipher request %s failed.\n",
WOLFKM_AESCFB_DRIVER);
goto test_cfb_end;
}
Expand Down Expand Up @@ -3552,6 +3571,7 @@ static int linuxkm_test_aesgcm(void)
assoc2 = malloc(sizeof(assoc));
if (! assoc2) {
pr_err("error: malloc failed\n");
ret = MEMORY_E;
goto test_gcm_end;
}
memset(assoc2, 0, sizeof(assoc));
Expand All @@ -3560,6 +3580,7 @@ static int linuxkm_test_aesgcm(void)
iv = malloc(WC_AES_BLOCK_SIZE);
if (! iv) {
pr_err("error: malloc failed\n");
ret = MEMORY_E;
goto test_gcm_end;
}
memset(iv, 0, WC_AES_BLOCK_SIZE);
Expand All @@ -3568,12 +3589,14 @@ static int linuxkm_test_aesgcm(void)
enc2 = malloc(decryptLen);
if (! enc2) {
pr_err("error: malloc failed\n");
ret = MEMORY_E;
goto test_gcm_end;
}

dec2 = malloc(decryptLen);
if (! dec2) {
pr_err("error: malloc failed\n");
ret = MEMORY_E;
goto test_gcm_end;
}

Expand Down Expand Up @@ -3608,24 +3631,24 @@ static int linuxkm_test_aesgcm(void)
req = aead_request_alloc(tfm, GFP_KERNEL);
if (! req) {
ret = -ENOMEM;
pr_err("error: allocating AES aead request %s failed: %ld\n",
WOLFKM_AESCBC_DRIVER, PTR_ERR(req));
pr_err("error: allocating AES aead request %s failed.\n",
WOLFKM_AESCBC_DRIVER);
goto test_gcm_end;
}

src = malloc(sizeof(struct scatterlist) * 2);

if (! src) {
pr_err("error: malloc src failed: %ld\n",
PTR_ERR(src));
pr_err("error: malloc src failed.\n");
ret = MEMORY_E;
Comment thread
dgarske marked this conversation as resolved.
goto test_gcm_end;
}

dst = malloc(sizeof(struct scatterlist) * 2);

if (! dst) {
pr_err("error: malloc dst failed: %ld\n",
PTR_ERR(dst));
pr_err("error: malloc dst failed.\n");
ret = MEMORY_E;
goto test_gcm_end;
}

Expand Down Expand Up @@ -4511,11 +4534,27 @@ static int aes_xts_256_test(void)
goto out;
}

#if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_C_DYNAMIC_FALLBACK)
WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
ret = wc_AesXtsEncrypt(aes, buf, p1, sizeof(p1), i1, sizeof(i1));
WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
if (ret != 0)
goto out;
if (XMEMCMP(c1, buf, WC_AES_BLOCK_SIZE)) {
ret = LINUXKM_LKCAPI_AES_KAT_MISMATCH_E;
goto out;
}
#endif

/* partial block encryption test */
XMEMSET(cipher, 0, AES_XTS_256_TEST_BUF_SIZ);
ret = wc_AesXtsEncrypt(aes, cipher, pp, sizeof(pp), i1, sizeof(i1));
if (ret != 0)
goto out;
if (XMEMCMP(cp, cipher, sizeof(cp))) {
ret = LINUXKM_LKCAPI_AES_KAT_MISMATCH_E;
goto out;
}

/* partial block decrypt test */
XMEMSET(buf, 0, AES_XTS_256_TEST_BUF_SIZ);
Expand Down Expand Up @@ -4705,8 +4744,8 @@ static int aes_xts_256_test(void)
req = skcipher_request_alloc(tfm, GFP_KERNEL);
if (! req) {
ret = -ENOMEM;
pr_err("error: allocating AES skcipher request %s failed: %d\n",
WOLFKM_AESXTS_DRIVER, ret);
pr_err("error: allocating AES skcipher request %s failed.\n",
WOLFKM_AESXTS_DRIVER);
goto test_xts_end;
}

Expand Down
37 changes: 27 additions & 10 deletions linuxkm/lkcapi_dh_glue.c
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,9 @@ static int km_dh_set_secret(struct crypto_kpp *tfm, const void *buf,
ctx->has_pub_key = 0;
dh_secret_end:

if (err != 0)
km_dh_reset_ctx(ctx);

#ifdef WOLFKM_DEBUG_DH
pr_info("info: exiting km_dh_set_secret\n");
#endif /* WOLFKM_DEBUG_DH */
Expand Down Expand Up @@ -754,6 +757,7 @@ static int km_ffdhe_init(struct crypto_kpp *tfm, int name, word32 nbits)
{
struct km_dh_ctx * ctx = NULL;
int err = 0;
int key_inited = 0;

ctx = kpp_tfm_ctx(tfm);
memset(ctx, 0, sizeof(struct km_dh_ctx));
Expand All @@ -770,35 +774,48 @@ static int km_ffdhe_init(struct crypto_kpp *tfm, int name, word32 nbits)

ctx->key = (DhKey *)malloc(sizeof(DhKey));
if (!ctx->key) {
return -ENOMEM;
err = -ENOMEM;
goto out;
}

err = wc_InitDhKey(ctx->key);
if (err < 0) {
free(ctx->key);
ctx->key = NULL;
return -ENOMEM;
err = -ENOMEM;
goto out;
}

key_inited = 1;

if (ctx->name) {
err = wc_DhSetNamedKey(ctx->key, ctx->name);
if (err) {
#ifdef WOLFKM_DEBUG_DH
pr_err("%s: wc_DhSetNamedKey returned: %d\n", WOLFKM_DH_DRIVER,
err);
#endif /* WOLFKM_DEBUG_DH */
wc_FreeDhKey(ctx->key);
free(ctx->key);
ctx->key = NULL;
return -ENOMEM;
err = -ENOMEM;
goto out;
}
}

#ifdef WOLFKM_DEBUG_DH
pr_info("info: exiting km_dh_init: name %d, nbits %d\n",
ctx->name, ctx->nbits);
#endif /* WOLFKM_DEBUG_DH */
return 0;

out:

if (err != 0) {
if (ctx->key) {
if (key_inited)
wc_FreeDhKey(ctx->key);
free(ctx->key);
ctx->key = NULL;
}
wc_FreeRng(&ctx->rng);
}

return err;
}

#ifdef LINUXKM_DH
Expand Down Expand Up @@ -2888,7 +2905,7 @@ static int linuxkm_test_kpp_driver(const char * driver,

req = kpp_request_alloc(tfm, GFP_KERNEL);
if (! req) {
test_rc = -ENOMEM;
test_rc = MEMORY_E;
pr_err("error: allocating kpp request %s failed\n",
driver);
goto test_kpp_end;
Expand Down
Loading
Loading