Skip to content

Commit 4ca8daf

Browse files
committed
Fix GH-9068: Conditional jump or move depends on uninitialised value(s)
This patch preserves the scratch registers of the SysV x86-64 ABI by storing them to the stack and restoring them later. We need to do this to prevent the registers of the caller from being corrupted. The reason these get corrupted is because the compiler is unaware of the Valgrind replacement function and thus makes assumptions about the original function regarding registers which are not true for the replacement function. For implementation I used a GCC and Clang attribute. A more general approach would be to use inline assembly but that's also less portable and quite hacky. This attributes is supported since GCC 7.x, but the target option is only supported since 11.x. For Clang the target option does not matter. Closes GH-10221.
1 parent 11597d1 commit 4ca8daf

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.1.20
44

5+
- Core:
6+
. Fixed bug GH-9068 (Conditional jump or move depends on uninitialised
7+
value(s)). (nielsdos)
8+
59
- Opcache:
610
. Fixed bug GH-11134 (Incorrect match default branch optimization). (ilutov)
711
. Fixed too wide OR and AND range inference. (nielsdos)

Zend/zend_string.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,11 +372,28 @@ ZEND_API void zend_interned_strings_switch_storage(bool request)
372372
# define I_REPLACE_SONAME_FNNAME_ZU(soname, fnname) _vgr00000ZU_ ## soname ## _ ## fnname
373373
#endif
374374

375-
ZEND_API bool ZEND_FASTCALL I_REPLACE_SONAME_FNNAME_ZU(NONE,zend_string_equal_val)(zend_string *s1, zend_string *s2)
375+
/* See GH-9068 */
376+
#if defined(__GNUC__) && (__GNUC__ >= 11 || defined(__clang__)) && __has_attribute(no_caller_saved_registers)
377+
# define NO_CALLER_SAVED_REGISTERS __attribute__((no_caller_saved_registers))
378+
# ifndef __clang__
379+
# pragma GCC push_options
380+
# pragma GCC target ("general-regs-only")
381+
# define POP_OPTIONS
382+
# endif
383+
#else
384+
# define NO_CALLER_SAVED_REGISTERS
385+
#endif
386+
387+
ZEND_API bool ZEND_FASTCALL NO_CALLER_SAVED_REGISTERS I_REPLACE_SONAME_FNNAME_ZU(NONE,zend_string_equal_val)(zend_string *s1, zend_string *s2)
376388
{
377389
return !memcmp(ZSTR_VAL(s1), ZSTR_VAL(s2), ZSTR_LEN(s1));
378390
}
379391

392+
#ifdef POP_OPTIONS
393+
# pragma GCC pop_options
394+
# undef POP_OPTIONS
395+
#endif
396+
380397
#if defined(__GNUC__) && defined(__i386__)
381398
ZEND_API bool ZEND_FASTCALL zend_string_equal_val(zend_string *s1, zend_string *s2)
382399
{

0 commit comments

Comments
 (0)