Skip to content

Commit 204d933

Browse files
authored
Merge pull request #8702 from douzzer/20250422-linuxkm-tweaks
20250422-linuxkm-tweaks
2 parents 68eec91 + 1f9d0b1 commit 204d933

File tree

8 files changed

+70
-19
lines changed

8 files changed

+70
-19
lines changed

.wolfssl_known_macro_extras

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,6 @@ WOLFSSL_ARM_ARCH_NEON_64BIT
592592
WOLFSSL_ASCON_UNROLL
593593
WOLFSSL_ASNC_CRYPT
594594
WOLFSSL_ASN_EXTRA
595-
WOLFSSL_ASN_INT_LEAD_0_ANY
596595
WOLFSSL_ASN_TEMPLATE_NEED_SET_INT32
597596
WOLFSSL_ASN_TEMPLATE_TYPE_CHECK
598597
WOLFSSL_ATECC508

linuxkm/lkcapi_aes_glue.c

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,7 @@ static int AesGcmCrypt_1(struct aead_request *req, int decrypt_p, int rfc4106_p)
12041204
pr_err("%s: scatterwalk_map failed: %ld\n",
12051205
crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm)),
12061206
PTR_ERR(assoc));
1207+
in_map = NULL;
12071208
goto out;
12081209
}
12091210
assoc = in_map;
@@ -1220,6 +1221,7 @@ static int AesGcmCrypt_1(struct aead_request *req, int decrypt_p, int rfc4106_p)
12201221
pr_err("%s: scatterwalk_map failed: %ld\n",
12211222
crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm)),
12221223
PTR_ERR(assoc));
1224+
out_map = NULL;
12231225
goto out;
12241226
}
12251227
out_text = out_map + req->assoclen;
@@ -2329,6 +2331,7 @@ static int linuxkm_test_aescbc(void)
23292331
if (IS_ERR(tfm)) {
23302332
pr_err("error: allocating AES skcipher algorithm %s failed: %ld\n",
23312333
WOLFKM_AESCBC_DRIVER, PTR_ERR(tfm));
2334+
tfm = NULL;
23322335
goto test_cbc_end;
23332336
}
23342337

@@ -2355,6 +2358,7 @@ static int linuxkm_test_aescbc(void)
23552358
if (IS_ERR(req)) {
23562359
pr_err("error: allocating AES skcipher request %s failed\n",
23572360
WOLFKM_AESCBC_DRIVER);
2361+
req = NULL;
23582362
goto test_cbc_end;
23592363
}
23602364

@@ -2538,6 +2542,7 @@ static int linuxkm_test_aescfb(void)
25382542
if (IS_ERR(tfm)) {
25392543
pr_err("error: allocating AES skcipher algorithm %s failed: %ld\n",
25402544
WOLFKM_AESCFB_DRIVER, PTR_ERR(tfm));
2545+
tfm = NULL;
25412546
goto test_cfb_end;
25422547
}
25432548

@@ -2555,6 +2560,7 @@ static int linuxkm_test_aescfb(void)
25552560
if (IS_ERR(req)) {
25562561
pr_err("error: allocating AES skcipher request %s failed\n",
25572562
WOLFKM_AESCFB_DRIVER);
2563+
req = NULL;
25582564
goto test_cfb_end;
25592565
}
25602566

@@ -2761,29 +2767,29 @@ static int linuxkm_test_aesgcm(void)
27612767

27622768
/* now the kernel crypto part */
27632769
assoc2 = malloc(sizeof(assoc));
2764-
if (IS_ERR(assoc2)) {
2770+
if (! assoc2) {
27652771
pr_err("error: malloc failed\n");
27662772
goto test_gcm_end;
27672773
}
27682774
memset(assoc2, 0, sizeof(assoc));
27692775
memcpy(assoc2, assoc, sizeof(assoc));
27702776

27712777
iv = malloc(WC_AES_BLOCK_SIZE);
2772-
if (IS_ERR(iv)) {
2778+
if (! iv) {
27732779
pr_err("error: malloc failed\n");
27742780
goto test_gcm_end;
27752781
}
27762782
memset(iv, 0, WC_AES_BLOCK_SIZE);
27772783
memcpy(iv, ivstr, GCM_NONCE_MID_SZ);
27782784

27792785
enc2 = malloc(decryptLen);
2780-
if (IS_ERR(enc2)) {
2786+
if (! enc2) {
27812787
pr_err("error: malloc failed\n");
27822788
goto test_gcm_end;
27832789
}
27842790

27852791
dec2 = malloc(decryptLen);
2786-
if (IS_ERR(dec2)) {
2792+
if (! dec2) {
27872793
pr_err("error: malloc failed\n");
27882794
goto test_gcm_end;
27892795
}
@@ -2796,6 +2802,7 @@ static int linuxkm_test_aesgcm(void)
27962802
if (IS_ERR(tfm)) {
27972803
pr_err("error: allocating AES skcipher algorithm %s failed: %ld\n",
27982804
WOLFKM_AESGCM_DRIVER, PTR_ERR(tfm));
2805+
tfm = NULL;
27992806
goto test_gcm_end;
28002807
}
28012808

@@ -2819,15 +2826,23 @@ static int linuxkm_test_aesgcm(void)
28192826
if (IS_ERR(req)) {
28202827
pr_err("error: allocating AES aead request %s failed: %ld\n",
28212828
WOLFKM_AESCBC_DRIVER, PTR_ERR(req));
2829+
req = NULL;
28222830
goto test_gcm_end;
28232831
}
28242832

28252833
src = malloc(sizeof(struct scatterlist) * 2);
2834+
2835+
if (! src) {
2836+
pr_err("error: malloc src failed: %ld\n",
2837+
PTR_ERR(src));
2838+
goto test_gcm_end;
2839+
}
2840+
28262841
dst = malloc(sizeof(struct scatterlist) * 2);
28272842

2828-
if (IS_ERR(src) || IS_ERR(dst)) {
2829-
pr_err("error: malloc src or dst failed: %ld, %ld\n",
2830-
PTR_ERR(src), PTR_ERR(dst));
2843+
if (! dst) {
2844+
pr_err("error: malloc dst failed: %ld\n",
2845+
PTR_ERR(dst));
28312846
goto test_gcm_end;
28322847
}
28332848

@@ -3367,6 +3382,7 @@ static int aes_xts_128_test(void)
33673382
ret = PTR_ERR(tfm);
33683383
pr_err("error: allocating AES skcipher algorithm %s failed: %d\n",
33693384
WOLFKM_AESXTS_DRIVER, ret);
3385+
tfm = NULL;
33703386
goto test_xts_end;
33713387
}
33723388

@@ -3404,6 +3420,7 @@ static int aes_xts_128_test(void)
34043420
ret = PTR_ERR(req);
34053421
pr_err("error: allocating AES skcipher request %s failed: %d\n",
34063422
WOLFKM_AESXTS_DRIVER, ret);
3423+
req = NULL;
34073424
goto test_xts_end;
34083425
}
34093426

@@ -3847,6 +3864,7 @@ static int aes_xts_256_test(void)
38473864
ret = PTR_ERR(tfm);
38483865
pr_err("error: allocating AES skcipher algorithm %s failed: %d\n",
38493866
WOLFKM_AESXTS_DRIVER, ret);
3867+
tfm = NULL;
38503868
goto test_xts_end;
38513869
}
38523870

@@ -3883,6 +3901,7 @@ static int aes_xts_256_test(void)
38833901
ret = PTR_ERR(req);
38843902
pr_err("error: allocating AES skcipher request %s failed: %d\n",
38853903
WOLFKM_AESXTS_DRIVER, ret);
3904+
req = NULL;
38863905
goto test_xts_end;
38873906
}
38883907

linuxkm/lkcapi_ecdh_glue.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,13 +804,15 @@ static int linuxkm_test_ecdh_nist_driver(const char * driver,
804804
if (IS_ERR(tfm)) {
805805
pr_err("error: allocating kpp algorithm %s failed: %ld\n",
806806
driver, PTR_ERR(tfm));
807+
tfm = NULL;
807808
goto test_ecdh_nist_end;
808809
}
809810

810811
req = kpp_request_alloc(tfm, GFP_KERNEL);
811812
if (IS_ERR(req)) {
812813
pr_err("error: allocating kpp request %s failed\n",
813814
driver);
815+
req = NULL;
814816
goto test_ecdh_nist_end;
815817
}
816818

linuxkm/lkcapi_ecdsa_glue.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,13 +679,15 @@ static int linuxkm_test_ecdsa_nist_driver(const char * driver,
679679
if (IS_ERR(tfm)) {
680680
pr_err("error: allocating akcipher algorithm %s failed: %ld\n",
681681
driver, PTR_ERR(tfm));
682+
tfm = NULL;
682683
goto test_ecdsa_nist_end;
683684
}
684685

685686
req = akcipher_request_alloc(tfm, GFP_KERNEL);
686687
if (IS_ERR(req)) {
687688
pr_err("error: allocating akcipher request %s failed\n",
688689
driver);
690+
req = NULL;
689691
goto test_ecdsa_nist_end;
690692
}
691693

linuxkm/lkcapi_rsa_glue.c

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,25 +180,32 @@ static int km_rsa_init(struct crypto_akcipher *tfm, int hash_oid)
180180

181181
ctx->key = (RsaKey *)malloc(sizeof(RsaKey));
182182
if (!ctx->key) {
183-
return -ENOMEM;
183+
ret = -ENOMEM;
184+
goto out;
184185
}
185186

186187
ret = wc_InitRng(&ctx->rng);
187188
if (ret) {
188189
pr_err("%s: init rng returned: %d\n", WOLFKM_RSA_DRIVER, ret);
189-
return -ENOMEM;
190+
if (ret == WC_NO_ERR_TRACE(MEMORY_E))
191+
ret = -ENOMEM;
192+
else
193+
ret = -EINVAL;
194+
goto out;
190195
}
191196

192197
ret = wc_InitRsaKey(ctx->key, NULL);
193198
if (ret) {
194199
pr_err("%s: init rsa key returned: %d\n", WOLFKM_RSA_DRIVER, ret);
195-
return -ENOMEM;
200+
ret = -EINVAL;
201+
goto out;
196202
}
197203

198204
#ifdef WC_RSA_BLINDING
199205
ret = wc_RsaSetRNG(ctx->key, &ctx->rng);
200206
if (ret) {
201-
return -ENOMEM;
207+
ret = -EINVAL;
208+
goto out;
202209
}
203210
#endif /* WC_RSA_BLINDING */
204211

@@ -221,13 +228,25 @@ static int km_rsa_init(struct crypto_akcipher *tfm, int hash_oid)
221228
default:
222229
pr_err("%s: init: unhandled hash_oid: %d\n", WOLFKM_RSA_DRIVER,
223230
hash_oid);
224-
return -ENOMEM;
231+
ret = -EINVAL;
232+
goto out;
225233
}
226234

227235
#ifdef WOLFKM_DEBUG_RSA
228236
pr_info("info: exiting km_rsa_init: hash_oid %d\n", ctx->hash_oid);
229237
#endif /* WOLFKM_DEBUG_RSA */
230-
return 0;
238+
239+
out:
240+
241+
if (ret != 0) {
242+
if (ctx->key) {
243+
free(ctx->key);
244+
ctx->key = NULL;
245+
}
246+
wc_FreeRng(&ctx->rng);
247+
}
248+
249+
return ret;
231250
}
232251

233252
#if defined(LINUXKM_DIRECT_RSA)
@@ -1260,13 +1279,15 @@ static int linuxkm_test_rsa_driver(const char * driver, int nbits)
12601279
if (IS_ERR(tfm)) {
12611280
pr_err("error: allocating akcipher algorithm %s failed: %ld\n",
12621281
driver, PTR_ERR(tfm));
1282+
tfm = NULL;
12631283
goto test_rsa_end;
12641284
}
12651285

12661286
req = akcipher_request_alloc(tfm, GFP_KERNEL);
12671287
if (IS_ERR(req)) {
12681288
pr_err("error: allocating akcipher request %s failed\n",
12691289
driver);
1290+
req = NULL;
12701291
goto test_rsa_end;
12711292
}
12721293

@@ -1609,13 +1630,15 @@ static int linuxkm_test_pkcs1_driver(const char * driver, int nbits,
16091630
if (IS_ERR(tfm)) {
16101631
pr_err("error: allocating akcipher algorithm %s failed: %ld\n",
16111632
driver, PTR_ERR(tfm));
1633+
tfm = NULL;
16121634
goto test_pkcs1_end;
16131635
}
16141636

16151637
req = akcipher_request_alloc(tfm, GFP_KERNEL);
16161638
if (IS_ERR(req)) {
16171639
pr_err("error: allocating akcipher request %s failed\n",
16181640
driver);
1641+
req = NULL;
16191642
goto test_pkcs1_end;
16201643
}
16211644

linuxkm/module_hooks.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,6 @@ static void lkmFipsCb(int ok, int err, const char* hash)
110110
#endif
111111

112112
#ifdef WOLFCRYPT_FIPS_CORE_DYNAMIC_HASH_VALUE
113-
#ifndef CONFIG_MODULE_SIG
114-
#error WOLFCRYPT_FIPS_CORE_DYNAMIC_HASH_VALUE requires a CONFIG_MODULE_SIG kernel.
115-
#endif
116113
static int updateFipsHash(void);
117114
#endif
118115

@@ -137,10 +134,12 @@ static int wolfssl_init(void)
137134
int ret;
138135

139136
#ifdef WOLFCRYPT_FIPS_CORE_DYNAMIC_HASH_VALUE
137+
#ifdef CONFIG_MODULE_SIG
140138
if (THIS_MODULE->sig_ok == false) {
141139
pr_err("wolfSSL module load aborted -- bad or missing module signature with FIPS dynamic hash.\n");
142140
return -ECANCELED;
143141
}
142+
#endif
144143
ret = updateFipsHash();
145144
if (ret < 0) {
146145
pr_err("wolfSSL module load aborted -- updateFipsHash: %s\n",wc_GetErrorString(ret));

wolfcrypt/src/memory.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1754,7 +1754,7 @@ WOLFSSL_LOCAL int SAVE_VECTOR_REGISTERS2_fuzzer(void) {
17541754
}
17551755
(void)lrand48_r(&wc_svr_fuzzing_state, &result);
17561756
if (result & 1)
1757-
return IO_FAILED_E;
1757+
return WC_NO_ERR_TRACE(IO_FAILED_E);
17581758
else
17591759
return 0;
17601760
}
@@ -1794,7 +1794,7 @@ WOLFSSL_LOCAL int SAVE_VECTOR_REGISTERS2_fuzzer(void) {
17941794

17951795
balance_bit = !balance_bit;
17961796

1797-
return ((prn & 1) ^ balance_bit) ? IO_FAILED_E : 0;
1797+
return ((prn & 1) ^ balance_bit) ? WC_NO_ERR_TRACE(IO_FAILED_E) : 0;
17981798
}
17991799

18001800
#endif /* !HAVE_THREAD_LS */

wolfssl/wolfcrypt/settings.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3674,6 +3674,13 @@ extern void uITRON4_free(void *p) ;
36743674
#undef WOLFSSL_MIN_AUTH_TAG_SZ
36753675
#define WOLFSSL_MIN_AUTH_TAG_SZ 4
36763676

3677+
#if defined(LINUXKM_LKCAPI_REGISTER) && !defined(WOLFSSL_ASN_INT_LEAD_0_ANY)
3678+
/* kernel 5.10 crypto manager tests key(s) that fail unless leading
3679+
* bytes are tolerated in GetASN_Integer().
3680+
*/
3681+
#define WOLFSSL_ASN_INT_LEAD_0_ANY
3682+
#endif
3683+
36773684
#ifdef CONFIG_KASAN
36783685
#ifndef WC_SANITIZE_DISABLE
36793686
#define WC_SANITIZE_DISABLE() kasan_disable_current()

0 commit comments

Comments
 (0)