Skip to content

Commit

Permalink
darwin: Take Interceptor and Cloak locks in TSM
Browse files Browse the repository at this point in the history
To extend the ThreadSuspendMonitor scope to prevent deadlock scenarios
where threads holding the Cloak or Interceptor lock get suspended.
  • Loading branch information
mrmacete authored and oleavr committed May 13, 2024
1 parent 5623ac5 commit 05df3f7
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/payload/thread-suspend-monitor.vala
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,19 @@ namespace Frida {
if (script_backend == null || thread_id == caller_thread_id)
return thread_suspend (thread_id);

int result = 0;
var interceptor = Gum.Interceptor.obtain ();

int result = 0;
while (true) {
script_backend.with_lock_held (() => {
result = thread_suspend (thread_id);
interceptor.with_lock_held (() => {
Gum.Cloak.with_lock_held (() => {
result = thread_suspend (thread_id);
});
});
});

if (result != 0 || !script_backend.is_locked ())
if (result != 0 || (!script_backend.is_locked () && !Gum.Cloak.is_locked () && !interceptor.is_locked ()))
break;

if (thread_resume (thread_id) != 0)
Expand Down

0 comments on commit 05df3f7

Please sign in to comment.