From fe6ddc15a35636ca7027c32e4c60ebb136fc9d7f Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Mon, 27 Jan 2025 20:56:01 +0100 Subject: [PATCH] Cygwin: message queues: avoid deadlocks in multi-threaded processes Deadlocks have been observed if the message queue functions are called from different threads in the same process. Remove incorrectly locking the descriptor table while accessing the message queue fhandler, potentially calling blocking functions. Fixes: 46f3b0ce85a9 ("Cygwin: POSIX msg queues: move all mq_* functionality into fhandler_mqueue") Reported-by: Christian Franke Signed-off-by: Corinna Vinschen --- winsup/cygwin/posix_ipc.cc | 10 +++++----- winsup/cygwin/release/3.5.7 | 4 ++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/winsup/cygwin/posix_ipc.cc b/winsup/cygwin/posix_ipc.cc index 2650c35ac..c188b0ce2 100644 --- a/winsup/cygwin/posix_ipc.cc +++ b/winsup/cygwin/posix_ipc.cc @@ -224,7 +224,7 @@ mq_getattr (mqd_t mqd, struct mq_attr *mqstat) { int ret = -1; - cygheap_fdget fd ((int) mqd, true); + cygheap_fdget fd ((int) mqd); if (fd >= 0) { fhandler_mqueue *fh = fd->is_mqueue (); @@ -241,7 +241,7 @@ mq_setattr (mqd_t mqd, const struct mq_attr *mqstat, struct mq_attr *omqstat) { int ret = -1; - cygheap_fdget fd ((int) mqd, true); + cygheap_fdget fd ((int) mqd); if (fd >= 0) { fhandler_mqueue *fh = fd->is_mqueue (); @@ -258,7 +258,7 @@ mq_notify (mqd_t mqd, const struct sigevent *notification) { int ret = -1; - cygheap_fdget fd ((int) mqd, true); + cygheap_fdget fd ((int) mqd); if (fd >= 0) { fhandler_mqueue *fh = fd->is_mqueue (); @@ -276,7 +276,7 @@ mq_timedsend (mqd_t mqd, const char *ptr, size_t len, unsigned int prio, { int ret = -1; - cygheap_fdget fd ((int) mqd, true); + cygheap_fdget fd ((int) mqd); if (fd >= 0) { fhandler_mqueue *fh = fd->is_mqueue (); @@ -300,7 +300,7 @@ mq_timedreceive (mqd_t mqd, char *ptr, size_t maxlen, unsigned int *priop, { int ret = -1; - cygheap_fdget fd ((int) mqd, true); + cygheap_fdget fd ((int) mqd); if (fd >= 0) { fhandler_mqueue *fh = fd->is_mqueue (); diff --git a/winsup/cygwin/release/3.5.7 b/winsup/cygwin/release/3.5.7 index 12180efd9..87baa3ada 100644 --- a/winsup/cygwin/release/3.5.7 +++ b/winsup/cygwin/release/3.5.7 @@ -3,3 +3,7 @@ Fixes: - Fix stat() on message queues. Addresses: https://cygwin.com/pipermail/cygwin/2025-January/257186.html + +- Avoid deadlocks when calling message queue functions from different threads + in the same process. + Addresses: https://cygwin.com/pipermail/cygwin/2025-January/257120.html