Index: libexec/rtld-elf/rtld.c =================================================================== --- libexec/rtld-elf/rtld.c +++ libexec/rtld-elf/rtld.c @@ -404,7 +404,16 @@ i = aux_info[AT_CANARYLEN]->a_un.a_val; if (i > sizeof(__stack_chk_guard)) i = sizeof(__stack_chk_guard); - memcpy(__stack_chk_guard, aux_info[AT_CANARY]->a_un.a_ptr, i); + + /* + * Avoid using functions which might have stack protection + * enabled, to update the __stack_chk_guard. + * Do a manual volatile copy to not allow the optimizer to + * call memcpy() behind us. + */ + while (--i >= 0) { + ((char *)__stack_chk_guard)[i] = ((volatile char *)(aux_info[AT_CANARY]->a_un.a_ptr))[i]; + } } else { mib[0] = CTL_KERN; mib[1] = KERN_ARND;