synccall: add separate exit_sem to fix thread release logic bug
commit7f3a2925369c00abc33457400e33632e6dacb8ae
authorMarkus Wichmann <nullplan@gmx.net>
Tue, 31 Oct 2023 16:03:44 +0000 (31 17:03 +0100)
committerRich Felker <dalias@aerifal.cx>
Mon, 6 Nov 2023 18:05:24 +0000 (6 13:05 -0500)
tree03eefaabaefd100ef7e346f5f10326e8490a5638
parent5baf2d92d3ed82960c419cb6093fbcdd028dde11
synccall: add separate exit_sem to fix thread release logic bug

The code intends for the sem_post() in line 97 (now 98) to only unblock
target threads waiting on line 29. But after the first thread is
released, the next sem_post() might also unblock a thread waiting on
line 36. That would cause the thread to return to the execution of user
code before all threads are done, leading to user code being executed in
a mixed-credentials environment.

What's more, if this happens more than once, then the mass release on
line 110 (now line 111) will cause multiple threads to execute the
callback at the same time, and the callbacks are currently not written
to cope with that situation.

Adding another semaphore allows the caller to say explicitly which
threads it wants to release.
src/thread/synccall.c