Skip to content

Commit

Permalink
Make MVM_HASH_RANDOMIZE properly control hash rand
Browse files Browse the repository at this point in the history
Before, if one set it to 0, some randomization could still happen. The
sure-fire way to make sure that doesn't happen is to just fix the hash
secrets to 0 also.
  • Loading branch information
jnthn committed Sep 5, 2019
1 parent 1fd0fdc commit 5f177f5
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/moar.c
Expand Up @@ -89,11 +89,16 @@ MVMInstance * MVM_vm_create_instance(void) {

/* Create the main thread's ThreadContext and stash it. */
instance->main_thread = MVM_tc_create(NULL, instance);
#if MVM_HASH_RANDOMIZE
/* Get the 128-bit hashSecret */
MVM_getrandom(instance->main_thread, instance->hashSecrets, sizeof(MVMuint64) * 2);
/* Just in case MVM_getrandom didn't work, XOR it with some (poorly) randomized data */
instance->hashSecrets[0] ^= ptr_hash_64_to_64((uintptr_t)instance);
instance->hashSecrets[1] ^= MVM_proc_getpid(instance->main_thread) * MVM_platform_now();
#else
instance->hashSecrets[0] = 0;
instance->hashSecrets[1] = 0;
#endif
instance->main_thread->thread_id = 1;

/* Next thread to be created gets ID 2 (the main thread got ID 1). */
Expand Down

0 comments on commit 5f177f5

Please sign in to comment.