Skip to content

Commit 42e75b6

Browse files
Merge #304: ci: Backport MSan fixes for ctime_tests
b9a82b4 ci: Update macOS image (Hennadii Stepanov) a1be8ed ci: Silent Homebrew's noisy reinstall warnings (Hennadii Stepanov) fd259fe ci: Add job with -fsanitize-memory-param-retval (Tim Ruffing) 76b3396 configure: Move "experimental" warning to bottom (Tim Ruffing) e639e6c autotools: Disable eager MSan in ctime_tests (Tim Ruffing) Pull request description: Cherry-picked the upstream fixes from bitcoin-core/secp256k1#1517 to align behaviour here and silence the false 'use-of-uninitialized-value' reports in ctime_tests under Clang ≥16. #### Result: - `ctime_tests` is clean under MSan. - Other tests are unchanged. - No API or behaviour changes. #### Commits cherry-picked: - [55e5d975db9a641bcbeffcc3fc086e54d322fe26](bitcoin-core/secp256k1@55e5d97), - [e1bef0961c53b23dbaf35f5fa87149a1aadfad37](bitcoin-core/secp256k1@e1bef09), - [ebfb82ee2f8c15ae6129932380b1dfb0942ea35a](bitcoin-core/secp256k1@ebfb82e) #### References: Upstream: bitcoin-core/secp256k1#1517 ACKs for top commit: apoelstra: ACK b9a82b4; successfully ran local tests jonasnick: ACK b9a82b4 Tree-SHA512: b6c9ae38b142c7fadf1157a1b25cdc8e85e6cd271222b950b1246f14daf85b072979d4f2ee8791c8b81b2f6a94ad1094fc8110bbd4ff19153de6a6efad2e3cc0
2 parents f92fd5c + b9a82b4 commit 42e75b6

File tree

3 files changed

+114
-17
lines changed

3 files changed

+114
-17
lines changed

.github/workflows/ci.yml

Lines changed: 67 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -556,11 +556,18 @@ jobs:
556556
matrix:
557557
configuration:
558558
- env_vars:
559+
CTIMETESTS: 'yes'
559560
CFLAGS: '-fsanitize=memory -fsanitize-recover=memory -g'
560561
- env_vars:
561562
ECMULTGENPRECISION: 2
562563
ECMULTWINDOW: 2
564+
CTIMETESTS: 'yes'
563565
CFLAGS: '-fsanitize=memory -fsanitize-recover=memory -g -O3'
566+
- env_vars:
567+
# -fsanitize-memory-param-retval is clang's default, but our build system disables it
568+
# when ctime_tests when enabled.
569+
CFLAGS: '-fsanitize=memory -fsanitize-recover=memory -fsanitize-memory-param-retval -g'
570+
CTIMETESTS: 'no'
564571

565572
env:
566573
ECDH: 'yes'
@@ -576,7 +583,6 @@ jobs:
576583
ECDSAADAPTOR: 'yes'
577584
BPPP: 'yes'
578585
SCHNORRSIG_HALFAGG: 'yes'
579-
CTIMETESTS: 'yes'
580586
CC: 'clang'
581587
SECP256K1_TEST_ITERS: 32
582588
ASM: 'no'
@@ -674,10 +680,10 @@ jobs:
674680
run: env
675681
if: ${{ always() }}
676682

677-
macos-native:
678-
name: "x86_64: macOS Monterey"
683+
x86_64-macos-native:
684+
name: "x86_64: macOS Ventura, Valgrind"
679685
# See: https://github.com/actions/runner-images#available-images.
680-
runs-on: macos-12 # Use M1 once available https://github.com/github/roadmap/issues/528
686+
runs-on: macos-13
681687

682688
env:
683689
CC: 'clang'
@@ -705,7 +711,7 @@ jobs:
705711

706712
- name: Install Homebrew packages
707713
run: |
708-
brew install automake libtool gcc
714+
brew install --quiet automake libtool gcc
709715
ln -s $(brew --prefix gcc)/bin/gcc-?? /usr/local/bin/gcc
710716
711717
- name: Install and cache Valgrind
@@ -733,6 +739,62 @@ jobs:
733739
run: env
734740
if: ${{ always() }}
735741

742+
arm64-macos-native:
743+
name: "ARM64: macOS Sonoma"
744+
# See: https://github.com/actions/runner-images#available-images.
745+
runs-on: macos-14
746+
747+
env:
748+
CC: 'clang'
749+
HOMEBREW_NO_AUTO_UPDATE: 1
750+
HOMEBREW_NO_INSTALL_CLEANUP: 1
751+
WITH_VALGRIND: 'no'
752+
CTIMETESTS: 'no'
753+
754+
strategy:
755+
fail-fast: false
756+
matrix:
757+
env_vars:
758+
- { WIDEMUL: 'int64', RECOVERY: 'yes', ECDH: 'yes', EXTRAKEYS: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes' }
759+
- { WIDEMUL: 'int128_struct', ECMULTGENPRECISION: 2, ECMULTWINDOW: 4 }
760+
- { WIDEMUL: 'int128', ECDH: 'yes', EXTRAKEYS: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes' }
761+
- { WIDEMUL: 'int128', RECOVERY: 'yes' }
762+
- { WIDEMUL: 'int128', RECOVERY: 'yes', ECDH: 'yes', EXTRAKEYS: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes' }
763+
- { WIDEMUL: 'int128', RECOVERY: 'yes', ECDH: 'yes', EXTRAKEYS: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes', CC: 'gcc' }
764+
- { WIDEMUL: 'int128', RECOVERY: 'yes', ECDH: 'yes', EXTRAKEYS: 'yes', SCHNORRSIG: 'yes', ELLSWIFT: 'yes', CPPFLAGS: '-DVERIFY' }
765+
- BUILD: 'distcheck'
766+
767+
steps:
768+
- name: Checkout
769+
uses: actions/checkout@v4
770+
771+
- name: Install Homebrew packages
772+
run: |
773+
brew install --quiet automake libtool gcc
774+
ln -s $(brew --prefix gcc)/bin/gcc-?? /usr/local/bin/gcc
775+
776+
- name: CI script
777+
env: ${{ matrix.env_vars }}
778+
run: ./ci/ci.sh
779+
780+
- run: cat tests.log || true
781+
if: ${{ always() }}
782+
- run: cat noverify_tests.log || true
783+
if: ${{ always() }}
784+
- run: cat exhaustive_tests.log || true
785+
if: ${{ always() }}
786+
- run: cat ctime_tests.log || true
787+
if: ${{ always() }}
788+
- run: cat bench.log || true
789+
if: ${{ always() }}
790+
- run: cat config.log || true
791+
if: ${{ always() }}
792+
- run: cat test_env.log || true
793+
if: ${{ always() }}
794+
- name: CI env
795+
run: env
796+
if: ${{ always() }}
797+
736798
win64-native:
737799
name: ${{ matrix.configuration.job_name }}
738800
# See: https://github.com/actions/runner-images#available-images.

build-aux/m4/bitcoin_secp.m4

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ fi
4545
AC_MSG_RESULT($has_valgrind)
4646
])
4747

48+
AC_DEFUN([SECP_MSAN_CHECK], [
49+
AC_MSG_CHECKING(whether MemorySanitizer is enabled)
50+
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
51+
#if defined(__has_feature)
52+
# if __has_feature(memory_sanitizer)
53+
# error "MemorySanitizer is enabled."
54+
# endif
55+
#endif
56+
]])], [msan_enabled=no], [msan_enabled=yes])
57+
AC_MSG_RESULT([$msan_enabled])
58+
])
59+
4860
dnl SECP_TRY_APPEND_CFLAGS(flags, VAR)
4961
dnl Append flags to VAR if CC accepts them.
5062
AC_DEFUN([SECP_TRY_APPEND_CFLAGS], [

configure.ac

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,20 @@ if test x"$enable_ctime_tests" = x"auto"; then
296296
enable_ctime_tests=$enable_valgrind
297297
fi
298298

299+
print_msan_notice=no
300+
if test x"$enable_ctime_tests" = x"yes" && test x"$GCC" = x"yes"; then
301+
SECP_MSAN_CHECK
302+
# MSan on Clang >=16 reports unitialized memory in function parameters and return values, even if
303+
# the uninitalized variable is never actually "used". This is called "eager" checking, and it's
304+
# sounds like good idea for normal use of MSan. However, it yields many false positives in the
305+
# ctime_tests because many return values depend on secret (i.e., "uninitialized") values, and
306+
# we're only interested in detecting branches (which count as "uses") on secret data.
307+
if test x"$msan_enabled" = x"yes"; then
308+
SECP_TRY_APPEND_CFLAGS([-fno-sanitize-memory-param-retval], SECP_CFLAGS)
309+
print_msan_notice=yes
310+
fi
311+
fi
312+
299313
if test x"$enable_coverage" = x"yes"; then
300314
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DCOVERAGE=1"
301315
SECP_CFLAGS="-O0 --coverage $SECP_CFLAGS"
@@ -542,12 +556,7 @@ fi
542556
### Check for --enable-experimental if necessary
543557
###
544558

545-
if test x"$enable_experimental" = x"yes"; then
546-
AC_MSG_NOTICE([******])
547-
AC_MSG_NOTICE([WARNING: experimental build])
548-
AC_MSG_NOTICE([Experimental features do not have stable APIs or properties, and may not be safe for production use.])
549-
AC_MSG_NOTICE([******])
550-
else
559+
if test x"$enable_experimental" = x"no"; then
551560
# The order of the following tests matters. If the user enables a dependent
552561
# module (which automatically enables the module dependencies) we want to
553562
# print an error for the dependent module, not the module dependency. Hence,
@@ -660,9 +669,23 @@ if test x"$set_widemul" != xauto; then
660669
echo " wide multiplication = $set_widemul"
661670
fi
662671
echo
663-
echo " valgrind = $enable_valgrind"
664-
echo " CC = $CC"
665-
echo " CPPFLAGS = $CPPFLAGS"
666-
echo " SECP_CFLAGS = $SECP_CFLAGS"
667-
echo " CFLAGS = $CFLAGS"
668-
echo " LDFLAGS = $LDFLAGS"
672+
echo " valgrind = $enable_valgrind"
673+
echo " CC = $CC"
674+
echo " CPPFLAGS = $CPPFLAGS"
675+
echo " SECP_CFLAGS = $SECP_CFLAGS"
676+
echo " CFLAGS = $CFLAGS"
677+
echo " LDFLAGS = $LDFLAGS"
678+
679+
if test x"$print_msan_notice" = x"yes"; then
680+
echo
681+
echo "Note:"
682+
echo " MemorySanitizer detected, tried to add -fno-sanitize-memory-param-retval to SECP_CFLAGS"
683+
echo " to avoid false positives in ctime_tests. Pass --disable-ctime-tests to avoid this."
684+
fi
685+
686+
if test x"$enable_experimental" = x"yes"; then
687+
echo
688+
echo "WARNING: Experimental build"
689+
echo " Experimental features do not have stable APIs or properties, and may not be safe for"
690+
echo " production use."
691+
fi

0 commit comments

Comments
 (0)