From 7e6db7006468483227ac04dc2f02feb349fab9e6 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 1 Jul 2019 10:37:34 +0200 Subject: [PATCH 1/4] Msan: Unpoison getrandom() syscall result --- ext/standard/random.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ext/standard/random.c b/ext/standard/random.c index f6568a658fd..82eee863e7a 100644 --- a/ext/standard/random.c +++ b/ext/standard/random.c @@ -38,6 +38,10 @@ # endif #endif +#if __has_feature(memory_sanitizer) +# include +#endif + #ifdef ZTS int random_globals_id; #else @@ -133,6 +137,10 @@ PHPAPI int php_random_bytes(void *bytes, size_t size, zend_bool should_throw) } } +#if __has_feature(memory_sanitizer) + /* MSan does not instrument manual syscall invocations. */ + __msan_unpoison(bytes + read_bytes, n); +#endif read_bytes += (size_t) n; } #endif From c8af6a7fa70c0722e1a87d48d69e236f4ed7b0e5 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 1 Jul 2019 10:44:44 +0200 Subject: [PATCH 2/4] Don't use fast_memcpy under msan --- ext/opcache/zend_accelerator_util_funcs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ext/opcache/zend_accelerator_util_funcs.c b/ext/opcache/zend_accelerator_util_funcs.c index 9692b4023ca..be927f64479 100644 --- a/ext/opcache/zend_accelerator_util_funcs.c +++ b/ext/opcache/zend_accelerator_util_funcs.c @@ -572,7 +572,9 @@ static void zend_accel_class_hash_copy_from_shm(HashTable *target, HashTable *so return; } -#if defined(__AVX__) +#if __has_feature(memory_sanitizer) +# define fast_memcpy memcpy +#elif defined(__AVX__) # include # if defined(__GNUC__) && defined(__i386__) static zend_always_inline void fast_memcpy(void *dest, const void *src, size_t size) From da06f7f383e2b54094975b3b49fd05076191976e Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 1 Jul 2019 11:02:31 +0200 Subject: [PATCH 3/4] Msan: Unpoison buffer written by file cache It would be great if this were fully initialized, but it's not really a problem either (as long as we don't care about reproducible file cache), so ignore this for now. --- ext/opcache/zend_file_cache.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ext/opcache/zend_file_cache.c b/ext/opcache/zend_file_cache.c index 31f7e20cd62..2c6c16002ea 100644 --- a/ext/opcache/zend_file_cache.c +++ b/ext/opcache/zend_file_cache.c @@ -49,6 +49,10 @@ # include #endif +#if __has_feature(memory_sanitizer) +# include +#endif + #ifndef ZEND_WIN32 #define zend_file_cache_unlink unlink #define zend_file_cache_open open @@ -947,6 +951,14 @@ int zend_file_cache_script_store(zend_persistent_script *script, int in_shm) info.checksum = zend_adler32(ADLER32_INIT, buf, script->size); info.checksum = zend_adler32(info.checksum, (signed char*)ZSTR_VAL((zend_string*)ZCG(mem)), info.str_size); +#if __has_feature(memory_sanitizer) + /* The buffer may contain uninitialized regions. However, the uninitialized parts will not be + * used when reading the cache. We should probably still try to get things fully initialized + * for reproducibility, but for now ignore this issue. */ + __msan_unpoison(&info, sizeof(info)); + __msan_unpoison(buf, script->size); +#endif + #ifdef HAVE_SYS_UIO_H vec[0].iov_base = &info; vec[0].iov_len = sizeof(info); From 7defd5f69c7360ab1755f8a467972b3b012632c8 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 1 Jul 2019 11:13:12 +0200 Subject: [PATCH 4/4] Fix unused variable warnings when mbregex disabled --- ext/mbstring/mbstring.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c index bf71270452f..057f192c9ff 100644 --- a/ext/mbstring/mbstring.c +++ b/ext/mbstring/mbstring.c @@ -444,6 +444,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_mb_chr, 0, 0, 1) ZEND_ARG_INFO(0, encoding) ZEND_END_ARG_INFO() +#if HAVE_MBREGEX ZEND_BEGIN_ARG_INFO_EX(arginfo_mb_regex_encoding, 0, 0, 0) ZEND_ARG_INFO(0, encoding) ZEND_END_ARG_INFO() @@ -527,6 +528,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_mb_regex_set_options, 0, 0, 0) ZEND_ARG_INFO(0, options) ZEND_END_ARG_INFO() +#endif /* HAVE_MBREGEX */ /* }}} */ /* {{{ zend_function_entry mbstring_functions[] */