-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add support for msan instead of valgrind (for memcheck and ctime test) #1169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4f1a54e
Move valgrind CPPFLAGS into SECP_CONFIG_DEFINES
sipa 0db05a7
Abstract interactions with valgrind behind new checkmem.h
sipa 8dc6407
Add compile-time error to valgrind_ctime_test
sipa 8e11f89
Add support for msan integration to checkmem.h
sipa 6eed6c1
Update error messages to suggest msan as well
sipa 5048be1
Rename valgrind_ctime_test -> ctime_tests
sipa 1897406
Make ctime tests building configurable
sipa 5e2e6fc
Run ctime test in Linux MSan CI job
sipa 74b026f
Add runtime checking for DECLASSIFY flag
sipa 0f088ec
Rename CTIMETEST -> CTIMETESTS
sipa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/*********************************************************************** | ||
* Copyright (c) 2022 Pieter Wuille * | ||
* Distributed under the MIT software license, see the accompanying * | ||
* file COPYING or https://www.opensource.org/licenses/mit-license.php.* | ||
***********************************************************************/ | ||
|
||
/* The code here is inspired by Kris Kwiatkowski's approach in | ||
* https://github.com/kriskwiatkowski/pqc/blob/main/src/common/ct_check.h | ||
* to provide a general interface for memory-checking mechanisms, primarily | ||
* for constant-time checking. | ||
*/ | ||
|
||
/* These macros are defined by this header file: | ||
* | ||
* - SECP256K1_CHECKMEM_ENABLED: | ||
* - 1 if memory-checking integration is available, 0 otherwise. | ||
* This is just a compile-time macro. Use the next macro to check it is actually | ||
* available at runtime. | ||
* - SECP256K1_CHECKMEM_RUNNING(): | ||
* - Acts like a function call, returning 1 if memory checking is available | ||
* at runtime. | ||
* - SECP256K1_CHECKMEM_CHECK(p, len): | ||
* - Assert or otherwise fail in case the len-byte memory block pointed to by p is | ||
* not considered entirely defined. | ||
* - SECP256K1_CHECKMEM_CHECK_VERIFY(p, len): | ||
* - Like SECP256K1_CHECKMEM_CHECK, but only works in VERIFY mode. | ||
* - SECP256K1_CHECKMEM_UNDEFINE(p, len): | ||
* - marks the len-byte memory block pointed to by p as undefined data (secret data, | ||
* in the context of constant-time checking). | ||
* - SECP256K1_CHECKMEM_DEFINE(p, len): | ||
* - marks the len-byte memory pointed to by p as defined data (public data, in the | ||
* context of constant-time checking). | ||
* | ||
*/ | ||
|
||
#ifndef SECP256K1_CHECKMEM_H | ||
#define SECP256K1_CHECKMEM_H | ||
|
||
/* Define a statement-like macro that ignores the arguments. */ | ||
#define SECP256K1_CHECKMEM_NOOP(p, len) do { (void)(p); (void)(len); } while(0) | ||
|
||
/* If compiling under msan, map the SECP256K1_CHECKMEM_* functionality to msan. | ||
* Choose this preferentially, even when VALGRIND is defined, as msan-compiled | ||
* binaries can't be run under valgrind anyway. */ | ||
#if defined(__has_feature) | ||
# if __has_feature(memory_sanitizer) | ||
# include <sanitizer/msan_interface.h> | ||
# define SECP256K1_CHECKMEM_ENABLED 1 | ||
# define SECP256K1_CHECKMEM_UNDEFINE(p, len) __msan_allocated_memory((p), (len)) | ||
# define SECP256K1_CHECKMEM_DEFINE(p, len) __msan_unpoison((p), (len)) | ||
# define SECP256K1_CHECKMEM_CHECK(p, len) __msan_check_mem_is_initialized((p), (len)) | ||
# define SECP256K1_CHECKMEM_RUNNING() (1) | ||
# endif | ||
#endif | ||
|
||
/* If valgrind integration is desired (through the VALGRIND define), implement the | ||
* SECP256K1_CHECKMEM_* macros using valgrind. */ | ||
#if !defined SECP256K1_CHECKMEM_ENABLED | ||
# if defined VALGRIND | ||
# include <stddef.h> | ||
# include <valgrind/memcheck.h> | ||
# define SECP256K1_CHECKMEM_ENABLED 1 | ||
# define SECP256K1_CHECKMEM_UNDEFINE(p, len) VALGRIND_MAKE_MEM_UNDEFINED((p), (len)) | ||
# define SECP256K1_CHECKMEM_DEFINE(p, len) VALGRIND_MAKE_MEM_DEFINED((p), (len)) | ||
# define SECP256K1_CHECKMEM_CHECK(p, len) VALGRIND_CHECK_MEM_IS_DEFINED((p), (len)) | ||
/* VALGRIND_MAKE_MEM_DEFINED returns 0 iff not running on memcheck. | ||
* This is more precise than the RUNNING_ON_VALGRIND macro, which | ||
* checks for valgrind in general instead of memcheck specifically. */ | ||
# define SECP256K1_CHECKMEM_RUNNING() (VALGRIND_MAKE_MEM_DEFINED(NULL, 0) != 0) | ||
# endif | ||
#endif | ||
|
||
/* As a fall-back, map these macros to dummy statements. */ | ||
#if !defined SECP256K1_CHECKMEM_ENABLED | ||
# define SECP256K1_CHECKMEM_ENABLED 0 | ||
# define SECP256K1_CHECKMEM_UNDEFINE(p, len) SECP256K1_CHECKMEM_NOOP((p), (len)) | ||
# define SECP256K1_CHECKMEM_DEFINE(p, len) SECP256K1_CHECKMEM_NOOP((p), (len)) | ||
# define SECP256K1_CHECKMEM_CHECK(p, len) SECP256K1_CHECKMEM_NOOP((p), (len)) | ||
# define SECP256K1_CHECKMEM_RUNNING() (0) | ||
#endif | ||
|
||
#if defined VERIFY | ||
#define SECP256K1_CHECKMEM_CHECK_VERIFY(p, len) SECP256K1_CHECKMEM_CHECK((p), (len)) | ||
#else | ||
#define SECP256K1_CHECKMEM_CHECK_VERIFY(p, len) SECP256K1_CHECKMEM_NOOP((p), (len)) | ||
#endif | ||
|
||
#endif /* SECP256K1_CHECKMEM_H */ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.