mq_notify: rework to fix use-after-close/double-close bugs
authorRich Felker <dalias@aerifal.cx>
Fri, 10 Feb 2023 16:22:45 +0000 (11:22 -0500)
committerRich Felker <dalias@aerifal.cx>
Sun, 12 Feb 2023 20:05:38 +0000 (15:05 -0500)
commit8c0c9c69a12acc0a82590d4fd64cf633ff1dedd2
treef149f332cd257e79275d1df8d975807a1ae03f75
parentfde6891e59c315e4a0ec7e69182e1d6314e3795e
mq_notify: rework to fix use-after-close/double-close bugs

in the error path where the mq_notify syscall fails, the initiating
thread may have closed the socket before the worker thread calls recv
on it. even in the absence of such a race, if the recv call failed,
e.g. due to seccomp policy blocking it, the worker thread could
proceed to close, producing a double-close condition.

this can all be simplified by moving the mq_notify syscall into the
new thread, so that the error case does not require pthread_cancel.
now, the initiating thread only needs to read back the error status
after waiting for the worker thread to consume its arguments.
src/mq/mq_notify.c