From bcf13bab5dd80254965dbcd3c42306a651b6e870 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Mon, 22 Jun 2015 18:06:17 +0200 Subject: [PATCH] Fix issue with MemSan and entropy Due to the recent change about entropy sources strength, it is no longer acceptable to just disable the platform source. So, instead "fix" it so that it is clear to MemSan that memory is initialized. I tried __attribute__((no_sanitize_memory)) and MemSan's blacklist file, but couldn't seem to get them to work. --- library/entropy_poll.c | 8 ++++++++ tests/scripts/all.sh | 1 - 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/library/entropy_poll.c b/library/entropy_poll.c index 92c757ec7..073acad8f 100644 --- a/library/entropy_poll.c +++ b/library/entropy_poll.c @@ -81,8 +81,16 @@ int mbedtls_platform_entropy_poll( void *data, unsigned char *output, size_t len #include #if defined(SYS_getrandom) #define HAVE_GETRANDOM + static int getrandom_wrapper( void *buf, size_t buflen, unsigned int flags ) { + /* MemSan cannot understand that the syscall writes to the buffer */ +#if defined(__has_feature) +#if __has_feature(memory_sanitizer) + memset( buf, 0, buflen ); +#endif +#endif + return( syscall( SYS_getrandom, buf, buflen, flags ) ); } diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index 448d519d4..1fb00a9ab 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -247,7 +247,6 @@ msg "build: MSan (clang)" # ~ 1 min 20s cleanup cp "$CONFIG_H" "$CONFIG_BAK" scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm -scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # memsan vs getrandom() CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan . make