yifanlu / taiHEN

CFW framework for PS Vita
MIT License
307 stars 46 forks source link

Race condition between hooking function and setting up hook #12

Open yifanlu opened 7 years ago

yifanlu commented 7 years ago

Right now, if a function is called in middle of the hook, this series of events could be possible

  1. substitute_hook_functions is called
  2. Function is written to, old pointer is saved
  3. taiHEN sets the old pointer into the tai_hook_t object stored in user address space.
  4. Call returns to user with a reference to the tai_hook_t

It is possible, between 2 and 4 that the function is called. In that case, it jumps to the user function, which tries to call TAI_CONTINUE with an uninitialized reference.

There are a couple of possible solutions:

yifanlu commented 7 years ago

For now a workaround for the user is to set the hook reference to 0 before calling taihen and in the hook function only call TAI_CONTINUE if the reference is non-zero. Not a perfect solution but should prevent crashes.