Skip to content

Commit 3586264

Browse files
committed
Unpoison opcache mem buf for file cache checksum calc
The buffer may contain uninitialized bytes, like padding, zval.value for IS_TRUE, IS_NULL, etc. and other unused fields. The checksum calculation loops over all bytes and thus will trigger uninitialized reads in MSAN. It doesn't matter too much, as the bytes in the file will still match the checksum.
1 parent b2dbf0a commit 3586264

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

ext/opcache/zend_file_cache.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -1118,9 +1118,6 @@ int zend_file_cache_script_store(zend_persistent_script *script, bool in_shm)
11181118

11191119
zend_string *const s = (zend_string*)ZCG(mem);
11201120

1121-
info.checksum = zend_adler32(ADLER32_INIT, buf, script->size);
1122-
info.checksum = zend_adler32(info.checksum, (unsigned char*)ZSTR_VAL(s), info.str_size);
1123-
11241121
#if __has_feature(memory_sanitizer)
11251122
/* The buffer may contain uninitialized regions. However, the uninitialized parts will not be
11261123
* used when reading the cache. We should probably still try to get things fully initialized
@@ -1129,6 +1126,9 @@ int zend_file_cache_script_store(zend_persistent_script *script, bool in_shm)
11291126
__msan_unpoison(buf, script->size);
11301127
#endif
11311128

1129+
info.checksum = zend_adler32(ADLER32_INIT, buf, script->size);
1130+
info.checksum = zend_adler32(info.checksum, (unsigned char*)ZSTR_VAL(s), info.str_size);
1131+
11321132
if (!zend_file_cache_script_write(fd, script, &info, buf, s)) {
11331133
zend_accel_error(ACCEL_LOG_WARNING, "opcache cannot write to file '%s': %s\n", filename, strerror(errno));
11341134
zend_string_release_ex(s, 0);

0 commit comments

Comments
 (0)