Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakashi Yano <takashi.yano@nifty.ne.jp>2022-01-13 14:57:15 +0300
committerTakashi Yano <takashi.yano@nifty.ne.jp>2022-01-14 17:11:07 +0300
commitbff4594b089c10c41edcdd14c2682d19f36b3241 (patch)
treef0735eeaf87a177558122c2275f8f43d9aae6807
parent3af461092e7ee9b76f3a1c18a6d95ed6e226df81 (diff)
Cygwin: console: Fix potential deadlock regarding acuqiring mutex.
- Acquiring input_mutex and attach_mutex in console code has potential risk of deadlock. This patch fixes the issue.
-rw-r--r--winsup/cygwin/fhandler.h2
-rw-r--r--winsup/cygwin/select.cc7
2 files changed, 6 insertions, 3 deletions
diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h
index 0cea1b7f3..fb4747608 100644
--- a/winsup/cygwin/fhandler.h
+++ b/winsup/cygwin/fhandler.h
@@ -2208,9 +2208,11 @@ private:
void acquire_input_mutex_if_necessary (DWORD ms)
{
acquire_input_mutex (ms);
+ acquire_attach_mutex (ms);
}
void release_input_mutex_if_necessary (void)
{
+ release_attach_mutex ();
release_input_mutex ();
}
diff --git a/winsup/cygwin/select.cc b/winsup/cygwin/select.cc
index 5b8fc0f81..d01a319ef 100644
--- a/winsup/cygwin/select.cc
+++ b/winsup/cygwin/select.cc
@@ -1122,29 +1122,30 @@ peek_console (select_record *me, bool)
HANDLE h;
set_handle_or_return_if_not_open (h, me);
+ fh->acquire_input_mutex (mutex_timeout);
acquire_attach_mutex (mutex_timeout);
while (!fh->input_ready && !fh->get_cons_readahead_valid ())
{
if (fh->bg_check (SIGTTIN, true) <= bg_eof)
{
release_attach_mutex ();
+ fh->release_input_mutex ();
return me->read_ready = true;
}
else if (!PeekConsoleInputW (h, &irec, 1, &events_read) || !events_read)
break;
- fh->acquire_input_mutex (mutex_timeout);
if (fhandler_console::input_winch == fh->process_input_message ()
&& global_sigs[SIGWINCH].sa_handler != SIG_IGN
&& global_sigs[SIGWINCH].sa_handler != SIG_DFL)
{
set_sig_errno (EINTR);
- fh->release_input_mutex ();
release_attach_mutex ();
+ fh->release_input_mutex ();
return -1;
}
- fh->release_input_mutex ();
}
release_attach_mutex ();
+ fh->release_input_mutex ();
if (fh->input_ready || fh->get_cons_readahead_valid ())
return me->read_ready = true;