autotools: Disable eager MSan in ctime_tests #1517

pull real-or-random wants to merge 3 commits into bitcoin-core:master from real-or-random:202404-msan-retval changing 3 files +48 −7
  1. real-or-random commented at 3:15 pm on April 15, 2024: contributor

    This is the autotools solution for #1516.

    Alternatively, we could have a full-blown --enable-msan option, but it’s more work, and I’m not convinced that it’s necessary or at least much better.

    hebasto If you’re Concept ACK, are you willing to work on an equivalent PR for CMake?

  2. real-or-random added the label assurance on Apr 15, 2024
  3. real-or-random added the label build on Apr 15, 2024
  4. real-or-random added the label side-channel on Apr 15, 2024
  5. sipa commented at 3:37 pm on April 15, 2024: contributor
    Concept ACK
  6. hebasto commented at 10:53 am on April 23, 2024: member

    Concept ACK.

    @hebasto If you’re Concept ACK, are you willing to work on an equivalent PR for CMake?

    Sure. I am :)

  7. hebasto commented at 11:45 am on April 23, 2024: member

    To have any effect, the ctime_tests_CFLAGS variable has to AC_SUBSTed.

    However, to achieve the goal, the -fno-sanitize-memory-param-retval option has to be applied to the library code as well. So, I suggest:

     0--- a/configure.ac
     1+++ b/configure.ac
     2@@ -142,7 +142,7 @@ if test "x$GCC" = "xyes"; then
     3   # We need to wrap the argument in a --(start/end)-no-unused-arguments block to suppress a
     4   # -Wunused-command-line-argument warning, which clang emits if MSan is not actually enabled, i.e.,
     5   # if -fsanitize=memory does not appear on the command line.
     6-  SECP_TRY_APPEND_CFLAGS([--start-no-unused-arguments -fno-sanitize-memory-param-retval --end-no-unused-arguments], ctime_tests_CFLAGS)
     7+  SECP_TRY_APPEND_CFLAGS([--start-no-unused-arguments -fno-sanitize-memory-param-retval --end-no-unused-arguments], SECP_CFLAGS)
     8 fi
     9 
    10 ###
    
  8. real-or-random commented at 12:13 pm on May 7, 2024: contributor

    To have any effect, the ctime_tests_CFLAGS variable has to AC_SUBSTed.

    No, this seems to happen automatically. make V=1 shows me that it’s effective.

    However, to achieve the goal, the -fno-sanitize-memory-param-retval option has to be applied to the library code as well.

    Okay, true. Sorry, I thought I had tested this before opening a PR.

    Then this is a bit annoying. Your suggestion will work for our “abuse” of MSan in the ctime_tests. But it will also disable the new eager checking behind the back of the user in the case of normal use, i.e., checking for actual memory issues.

    So if we want to have both eager checking in “normal” MSan mode, and clean ctime_tests, I see no other way than having two builds (and adding a build to CI is not a problem). I think one of the following approaches will be sensible:

    1. disable the ctime_tests if we find -fsanitize=memory or similar on the command line (but parsing this is complex in cases such as -fsanitize=unreachable,memory this may be fragile and overkill)
    2. work with your suggestion to add this to SECP_CFLAGS, but only if constant-time tests are enabled. We could additionally print a warning that tells the users to disable the constant-time tests if they want to avoid that we add -fno-sanitize-memory-param-retval.

    The second looks better to me. What do you think?

  9. hebasto commented at 5:00 pm on May 7, 2024: member

    To have any effect, the ctime_tests_CFLAGS variable has to AC_SUBSTed.

    No, this seems to happen automatically. make V=1 shows me that it’s effective.

    I mean, only ctime_tests.c is compiled with ctime_tests_CFLAGS. However, all code is needed to be compiled with -fno-sanitize-memory-param-retval.

  10. hebasto commented at 5:42 pm on May 7, 2024: member
    1. disable the ctime_tests if we find -fsanitize=memory or similar on the command line (but parsing this is complex in cases such as -fsanitize=unreachable,memory this may be fragile and overkill)

    The following check might be used:

     0AC_DEFUN([SECP_MSAN_CHECK], [
     1AC_MSG_CHECKING(whether MemorySanitizer is enabled)
     2AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
     3  #if defined(__has_feature)
     4  #  if __has_feature(memory_sanitizer)
     5  #    error "MemorySanitizer is enabled."
     6  #  endif
     7  #endif
     8  ]])], [msan_enabled=no], [msan_enabled=yes])
     9AC_MSG_RESULT([$msan_enabled])
    10])
    
  11. real-or-random force-pushed on May 22, 2024
  12. real-or-random force-pushed on May 22, 2024
  13. real-or-random commented at 1:30 pm on May 22, 2024: contributor

    2. work with your suggestion to add this to SECP_CFLAGS, but only if constant-time tests are enabled. We could additionally print a warning that tells the users to disable the constant-time tests if they want to avoid that we add -fno-sanitize-memory-param-retval.

    I did this, using your suggested check for msan. Also rebased. Ready for review from my side.

    Note: CI is currently failing on macOS. This should be resolved once the GitHub Actions image is updated to have brew 4.3.1, which has the fix (https://github.com/Homebrew/brew/pull/17336). The images are updated every week, so the issue should just disappear in a few days.

  14. real-or-random commented at 2:55 pm on May 22, 2024: contributor
    Pushed another commit that adds a CI job with eager checks enabled explicitly (-fsanitize-memory-param-retval).
  15. autotools: Disable eager MSan in ctime_tests
    Co-authored-by: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com>
    55e5d975db
  16. configure: Move "experimental" warning to bottom
    to make it more promiment
    e1bef0961c
  17. ci: Add job with -fsanitize-memory-param-retval ebfb82ee2f
  18. real-or-random force-pushed on May 26, 2024
  19. real-or-random commented at 12:02 pm on May 26, 2024: contributor
    Force pushed to fix a logic bug, should be really ready for review now. :)
  20. hebasto approved
  21. hebasto commented at 2:07 pm on May 26, 2024: member
    ACK ebfb82ee2f8c15ae6129932380b1dfb0942ea35a, tested on Ubuntu 24.04 with different clang versions (from 15 to 18) and different build configurations. CI changes look OK as well.
  22. hebasto commented at 2:57 pm on May 26, 2024: member

    @real-or-random

    @hebasto If you’re Concept ACK, are you willing to work on an equivalent PR for CMake?

    Please consider #1532.

  23. real-or-random merged this on May 27, 2024
  24. real-or-random closed this on May 27, 2024

  25. real-or-random referenced this in commit 4b8d5eeacf on Jun 10, 2024
  26. josibake referenced this in commit d17e1a9ac3 on Jun 18, 2024
  27. fanquake referenced this in commit b941c15808 on Jun 25, 2024
  28. hebasto referenced this in commit b20389c74a on Jun 25, 2024
  29. fanquake referenced this in commit 1408944d2e on Jun 25, 2024
  30. achow101 referenced this in commit 9ac4f69ec2 on Jun 26, 2024
  31. gatleas17 commented at 5:19 pm on June 27, 2024: none
    Thx

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin-core/secp256k1. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-11-21 11:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me