Skip to content

Commit b1dc236

Browse files
committed
CI: Run backend unit tests under valgrind
Add unit_valgrind job to ci.yml that runs the unit tests under valgrind on x86_64 and aarch64 runners. This catches buffer overflows in hand-written assembly that ASan cannot detect, since ASan only instruments compiler-generated code. Signed-off-by: Hanno Becker <beckphan@amazon.co.uk>
1 parent b397afa commit b1dc236

2 files changed

Lines changed: 41 additions & 3 deletions

File tree

.github/workflows/ci.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,45 @@ jobs:
469469
examples: false
470470
stack: true
471471
check_namespace: false
472+
unit_valgrind:
473+
name: Unit tests + valgrind (${{ matrix.target.name }}, ${{ matrix.cflags }})
474+
strategy:
475+
fail-fast: false
476+
matrix:
477+
external:
478+
- ${{ github.repository_owner != 'pq-code-package' }}
479+
target:
480+
- runner: ubuntu-latest
481+
name: x86_64
482+
- runner: ubuntu-24.04-arm
483+
name: aarch64
484+
cflags: ['-O3', '-Os']
485+
exclude:
486+
- external: true
487+
runs-on: ${{ matrix.target.runner }}
488+
steps:
489+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
490+
- name: Unit tests under valgrind
491+
uses: ./.github/actions/functest
492+
with:
493+
gh_token: ${{ secrets.GITHUB_TOKEN }}
494+
nix-shell: valgrind-varlat_gcc15
495+
nix-cache: false
496+
opt: opt
497+
cflags: "${{ matrix.cflags }} -std=c11 -D_GNU_SOURCE -DMLK_CONFIG_FILE=\\\\\\\"../test/configs/custom_heap_alloc_config.h\\\\\\\""
498+
func: false
499+
kat: false
500+
acvp: false
501+
wycheproof: false
502+
examples: false
503+
stack: false
504+
unit: true
505+
alloc: false
506+
rng_fail: false
507+
check_namespace: false
508+
# Disable AArch64 SHA3 extension: valgrind cannot emulate it
509+
extra_env: "MK_COMPILER_SUPPORTS_SHA3=0"
510+
exec_wrapper: "valgrind --error-exitcode=1"
472511
config_variations:
473512
name: Non-standard configurations
474513
strategy:

test/mk/components.mk

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ $(MLKEM768_OBJS): CFLAGS += -DMLK_CONFIG_PARAMETER_SET=768
3232
MLKEM1024_OBJS = $(call MAKE_OBJS,$(MLKEM1024_DIR),$(SOURCES) $(FIPS202_SRCS))
3333
$(MLKEM1024_OBJS): CFLAGS += -DMLK_CONFIG_PARAMETER_SET=1024
3434

35-
# Unit test object files - same sources but with MLK_STATIC_TESTABLE= and custom heap alloc config
36-
UNIT_CFLAGS = -DMLK_STATIC_TESTABLE= -Wno-missing-prototypes \
37-
-DMLK_CONFIG_FILE=\"../test/configs/custom_heap_alloc_config.h\" -std=c11 -D_GNU_SOURCE
35+
# Unit test object files - same sources but with MLK_STATIC_TESTABLE=
36+
UNIT_CFLAGS = -DMLK_STATIC_TESTABLE= -Wno-missing-prototypes
3837

3938
MLKEM512_UNIT_OBJS = $(call MAKE_OBJS,$(MLKEM512_DIR)/unit,$(SOURCES) $(FIPS202_SRCS))
4039
$(MLKEM512_UNIT_OBJS): CFLAGS += -DMLK_CONFIG_PARAMETER_SET=512 $(UNIT_CFLAGS)

0 commit comments

Comments
 (0)