Skip to content

Nightly-multi-test valgrind fix#10190

Merged
douzzer merged 1 commit intowolfSSL:masterfrom
rlm2002:mlkem_valgrind
Apr 11, 2026
Merged

Nightly-multi-test valgrind fix#10190
douzzer merged 1 commit intowolfSSL:masterfrom
rlm2002:mlkem_valgrind

Conversation

@rlm2002
Copy link
Copy Markdown
Contributor

@rlm2002 rlm2002 commented Apr 10, 2026

Description

Increase rand buffer, fix valgrind invalid read size 16

Testing

./configure --srcdir=. --disable-jobserver --enable-option-checking=fatal \
--enable-all --enable-acert --enable-dtls13 --enable-dtls-mtu --enable-dtls-frag-ch \
--enable-dtlscid --enable-quic --with-sys-crypto-policy --enable-intelasm \
--enable-sp-math-all --enable-smallstack --enable-smallstackcache \
CPPFLAGS= "-DNO_WOLFSSL_CIPHER_SUITE_TEST -DWOLFSSL_OLD_PRIME_CHECK -pedantic -Wdeclaration-after-statement -Wnull-dereference -DTEST_LIBWOLFSSL_SOURCES_INCLUSION_SEQUENCE -Werror" \
CFLAGS="-DTEST_ALWAYS_RUN_TO_END -g -fno-omit-frame-pointer" LDFLAGS="-g -fno-omit-frame-pointer -lm"

make

LD_LIBRARY_PATH=./src/.libs valgrind --leak-check=full --show-leak-kinds=all \
--errors-for-leak-kinds=all  --show-reachable=yes  --leak-resolution=high \
--track-fds=yes --track-origins=yes --fullpath-after=  --error-exitcode=10 \
./testsuite/.libs/testsuite.test

@rlm2002 rlm2002 self-assigned this Apr 10, 2026
@rlm2002 rlm2002 marked this pull request as ready for review April 10, 2026 22:23
Copy link
Copy Markdown
Contributor

@douzzer douzzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good fix, thanks @rlm2002 !

Before fix:

valgrind --leak-check=full unit.test...==4214== Invalid read of size 16
25b2c664f4 wolfcrypt/src/wc_kyber_asm.S (<sean@wolfssl.com> 2024-03-12 09:43:26 +1000 12626)         vmovdqu    (%rdx), %xmm0
==4214==    at 0x4E78742: mlkem_rej_uniform_n_avx2 (/tmp/tmp.4346_28411/wolfssl_test_workdir.35209/wolfssl/wolfcrypt/src/wc_mlkem_asm.S:12626)
==4214==    by 0x1FFEFFDC8F: ???
==4214==    by 0x663FA0F: ???
==4214==    by 0xFF: ???
==4214==    by 0xFF: ???
==4214==    by 0xFF: ???
==4214==    by 0xFF: ???
a7690ca24b (<sean@wolfssl.com> 2025-03-06 14:19:00 +1000 2619)         ctr3 = mlkem_rej_uniform_n_avx2(a + 3 * MLKEM_N, MLKEM_N, p,
==4214==    by 0x4E68F9E: mlkem_gen_matrix_k4_avx2 (/tmp/tmp.4346_28411/wolfssl_test_workdir.35209/wolfssl/wolfcrypt/src/wc_mlkem_poly.c:2619)
a7690ca24b (<sean@wolfssl.com> 2025-03-06 14:19:00 +1000 3579)             ret = mlkem_gen_matrix_k4_avx2(a, seed, transposed);
==4214==    by 0x4E68F9E: mlkem_gen_matrix (/tmp/tmp.4346_28411/wolfssl_test_workdir.35209/wolfssl/wolfcrypt/src/wc_mlkem_poly.c:3579)
==4214==    by 0x7B3CD28132D18804: ???
==4214==    by 0x51C077BB56A50523: ???
==4214==    by 0xA47CD716A8536862: ???
==4214==    by 0x91222D499DA7131A: ???
==4214==  Address 0x684c6c4 is 2,004 bytes inside a block of size 2,018 alloc'd
==4214==    at 0x4C94858: malloc (/tmp/portage/dev-debug/valgrind-3.26.0_p1/work/valgrind-3.26.0/coregrind/m_replacemalloc/vg_replace_malloc.c:447)
401868908a (<douzzer@wolfssl.com> 2025-05-15 15:28:11 -0500 2572)     rand = (byte*)XMALLOC(4 * GEN_MATRIX_SIZE + 2, NULL,
==4214==    by 0x4E68A03: mlkem_gen_matrix_k4_avx2 (/tmp/tmp.4346_28411/wolfssl_test_workdir.35209/wolfssl/wolfcrypt/src/wc_mlkem_poly.c:2572)
a7690ca24b (<sean@wolfssl.com> 2025-03-06 14:19:00 +1000 3579)             ret = mlkem_gen_matrix_k4_avx2(a, seed, transposed);
==4214==    by 0x4E68A03: mlkem_gen_matrix (/tmp/tmp.4346_28411/wolfssl_test_workdir.35209/wolfssl/wolfcrypt/src/wc_mlkem_poly.c:3579)
3b4e51c150 (<tobias@wolfssl.com> 2026-02-10 19:07:15 +0100 992)         ret = mlkem_gen_matrix(&key->prf, a, (int)k, key->pubSeed, 1);
==4214==    by 0x4E61AEE: mlkemkey_encapsulate (/tmp/tmp.4346_28411/wolfssl_test_workdir.35209/wolfssl/wolfcrypt/src/wc_mlkem.c:992)
a7690ca24b (<sean@wolfssl.com> 2025-03-06 14:19:00 +1000 1329)             ret = mlkemkey_encapsulate(key, msg, kr + WC_ML_KEM_SYM_SZ, c);
==4214==    by 0x4E62D71: wc_MlKemKey_EncapsulateWithRandom (/tmp/tmp.4346_28411/wolfssl_test_workdir.35209/wolfssl/wolfcrypt/src/wc_mlkem.c:1329)
5c497c62e7 (<douzzer@wolfssl.com> 2024-05-23 00:15:32 -0500 47138)     ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, kyber1024enc_rand,
==4214==    by 0x4162F07: mlkem1024_kat (/tmp/tmp.4346_28411/wolfssl_test_workdir.35209/wolfssl/wolfcrypt/test/test.c:47138)
a7690ca24b (<sean@wolfssl.com> 2025-03-06 14:19:00 +1000 47506)     ret = mlkem1024_kat();
==4214==    by 0x4162F07: mlkem_test (/tmp/tmp.4346_28411/wolfssl_test_workdir.35209/wolfssl/wolfcrypt/test/test.c:47506)
a7690ca24b (<sean@wolfssl.com> 2025-03-06 14:19:00 +1000 2801)     if ( (ret = mlkem_test()) != 0)
==4214==    by 0x416A168: wolfcrypt_test (/tmp/tmp.4346_28411/wolfssl_test_workdir.35209/wolfssl/wolfcrypt/test/test.c:2801)
9a84dfc86a (<douzzer@wolfssl.com> 2025-03-11 14:59:07 -0500 264)         wolfcrypt_test(&wc_args);
==4214==    by 0x405A29E: unit_test (/tmp/tmp.4346_28411/wolfssl_test_workdir.35209/wolfssl/tests/unit.c:264)
f643ca5f48 (<vikram.adiga@ti.com> 2014-05-08 15:52:20 -0700 70) int unit_test(int argc, char** argv)
==4214==    by 0x405A29E: unit_test (/tmp/tmp.4346_28411/wolfssl_test_workdir.35209/wolfssl/tests/unit.c:70)
==4214==    by 0x5534253: (below main) (/usr/src/debug/sys-libs/glibc-2.43/glibc-2.43/csu/../sysdeps/nptl/libc_start_call_main.h:59)
==4214== 
==4214== Invalid read of size 16
25b2c664f4 wolfcrypt/src/wc_kyber_asm.S (<sean@wolfssl.com> 2024-03-12 09:43:26 +1000 12626)         vmovdqu    (%rdx), %xmm0
==4214==    at 0x4E78742: mlkem_rej_uniform_n_avx2 (/tmp/tmp.4346_28411/wolfssl_test_workdir.35209/wolfssl/wolfcrypt/src/wc_mlkem_asm.S:12626)
==4214==    by 0x1FFEFFD66F: ???
==4214==    by 0x672C46F: ???
==4214==    by 0xFF: ???
==4214==    by 0xFF: ???
==4214==    by 0xFF: ???
==4214==    by 0xFF: ???
a7690ca24b (<sean@wolfssl.com> 2025-03-06 14:19:00 +1000 2619)         ctr3 = mlkem_rej_uniform_n_avx2(a + 3 * MLKEM_N, MLKEM_N, p,
==4214==    by 0x4E68F9E: mlkem_gen_matrix_k4_avx2 (/tmp/tmp.4346_28411/wolfssl_test_workdir.35209/wolfssl/wolfcrypt/src/wc_mlkem_poly.c:2619)
a7690ca24b (<sean@wolfssl.com> 2025-03-06 14:19:00 +1000 3579)             ret = mlkem_gen_matrix_k4_avx2(a, seed, transposed);
==4214==    by 0x4E68F9E: mlkem_gen_matrix (/tmp/tmp.4346_28411/wolfssl_test_workdir.35209/wolfssl/wolfcrypt/src/wc_mlkem_poly.c:3579)
==4214==    by 0x7B3CD28132D18804: ???
==4214==    by 0x51C077BB56A50523: ???
==4214==    by 0xA47CD716A8536862: ???
==4214==    by 0x91222D499DA7131A: ???
==4214==  Address 0x6643264 is 2,004 bytes inside a block of size 2,018 alloc'd
==4214==    at 0x4C94858: malloc (/tmp/portage/dev-debug/valgrind-3.26.0_p1/work/valgrind-3.26.0/coregrind/m_replacemalloc/vg_replace_malloc.c:447)
401868908a (<douzzer@wolfssl.com> 2025-05-15 15:28:11 -0500 2572)     rand = (byte*)XMALLOC(4 * GEN_MATRIX_SIZE + 2, NULL,
==4214==    by 0x4E68A03: mlkem_gen_matrix_k4_avx2 (/tmp/tmp.4346_28411/wolfssl_test_workdir.35209/wolfssl/wolfcrypt/src/wc_mlkem_poly.c:2572)
a7690ca24b (<sean@wolfssl.com> 2025-03-06 14:19:00 +1000 3579)             ret = mlkem_gen_matrix_k4_avx2(a, seed, transposed);
==4214==    by 0x4E68A03: mlkem_gen_matrix (/tmp/tmp.4346_28411/wolfssl_test_workdir.35209/wolfssl/wolfcrypt/src/wc_mlkem_poly.c:3579)
3b4e51c150 (<tobias@wolfssl.com> 2026-02-10 19:07:15 +0100 992)         ret = mlkem_gen_matrix(&key->prf, a, (int)k, key->pubSeed, 1);
==4214==    by 0x4E61AEE: mlkemkey_encapsulate (/tmp/tmp.4346_28411/wolfssl_test_workdir.35209/wolfssl/wolfcrypt/src/wc_mlkem.c:992)
a7690ca24b (<sean@wolfssl.com> 2025-03-06 14:19:00 +1000 1683)         ret = mlkemkey_encapsulate(key, msg, kr + WC_ML_KEM_SYM_SZ, cmp);
==4214==    by 0x4E63070: wc_MlKemKey_Decapsulate (/tmp/tmp.4346_28411/wolfssl_test_workdir.35209/wolfssl/wolfcrypt/src/wc_mlkem.c:1683)
82b50f19c6 (<sean@wolfssl.com> 2025-02-18 18:51:14 +1000 47153)     ret = wc_KyberKey_Decapsulate(key, ss_dec, kyber1024_ct,
==4214==    by 0x4162F74: mlkem1024_kat (/tmp/tmp.4346_28411/wolfssl_test_workdir.35209/wolfssl/wolfcrypt/test/test.c:47153)
a7690ca24b (<sean@wolfssl.com> 2025-03-06 14:19:00 +1000 47506)     ret = mlkem1024_kat();
==4214==    by 0x4162F74: mlkem_test (/tmp/tmp.4346_28411/wolfssl_test_workdir.35209/wolfssl/wolfcrypt/test/test.c:47506)
a7690ca24b (<sean@wolfssl.com> 2025-03-06 14:19:00 +1000 2801)     if ( (ret = mlkem_test()) != 0)
==4214==    by 0x416A168: wolfcrypt_test (/tmp/tmp.4346_28411/wolfssl_test_workdir.35209/wolfssl/wolfcrypt/test/test.c:2801)
9a84dfc86a (<douzzer@wolfssl.com> 2025-03-11 14:59:07 -0500 264)         wolfcrypt_test(&wc_args);
==4214==    by 0x405A29E: unit_test (/tmp/tmp.4346_28411/wolfssl_test_workdir.35209/wolfssl/tests/unit.c:264)
f643ca5f48 (<vikram.adiga@ti.com> 2014-05-08 15:52:20 -0700 70) int unit_test(int argc, char** argv)
==4214==    by 0x405A29E: unit_test (/tmp/tmp.4346_28411/wolfssl_test_workdir.35209/wolfssl/tests/unit.c:70)
==4214==    by 0x5534253: (below main) (/usr/src/debug/sys-libs/glibc-2.43/glibc-2.43/csu/../sysdeps/nptl/libc_start_call_main.h:59)
==4214== 

After fix:

valgrind --leak-check=full unit.test...   real 21m12.150s  user 21m4.123s  sys 0m0.387s
scenario started 2026-04-11T17:41:54.083974Z, real elapsed 22m19.210478s

(Yes it really takes 22m on a Threadripper 7960X...)

@douzzer douzzer merged commit d343ea6 into wolfSSL:master Apr 11, 2026
427 of 437 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants