Skip to content

Commit

Permalink
Cygwin: message queues: avoid deadlocks in multi-threaded processes
Browse files Browse the repository at this point in the history
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: 46f3b0c ("Cygwin: POSIX msg queues: move all mq_* functionality into fhandler_mqueue")
Reported-by: Christian Franke <[email protected]>
Signed-off-by: Corinna Vinschen <[email protected]>
  • Loading branch information
github-cygwin committed Jan 27, 2025
1 parent b940faa commit fe6ddc1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 5 additions & 5 deletions winsup/cygwin/posix_ipc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
Expand All @@ -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 ();
Expand All @@ -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 ();
Expand All @@ -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 ();
Expand All @@ -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 ();
Expand Down
4 changes: 4 additions & 0 deletions winsup/cygwin/release/3.5.7
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit fe6ddc1

Please sign in to comment.