public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
* [PATCH] Cygwin: console: Do not unmap shared console memory belonging to ctty.
@ 2024-03-01 10:53 Takashi Yano
  0 siblings, 0 replies; only message in thread
From: Takashi Yano @ 2024-03-01 10:53 UTC (permalink / raw)
  To: cygwin-patches; +Cc: Takashi Yano, Kate Deplaix

In the condition that console setup for CTTY and close run at the
sametime, accessing shared console memory which is already unmapped
may occur. With this patch, to avoid this race issue, shared console
memory which belongs to contorolling terminal (CTTY) is kept mapped
as before.
Addresses: https://cygwin.com/pipermail/cygwin/2024-February/255561.html

Fixes: 3721a756b0d8 ("Cygwin: console: Make the console accessible from other terminals.")
Reported-by: Kate Deplaix <kit-ty-kate@outlook.com>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
---
 winsup/cygwin/fhandler/console.cc | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/winsup/cygwin/fhandler/console.cc b/winsup/cygwin/fhandler/console.cc
index c16ca3962..67ea95466 100644
--- a/winsup/cygwin/fhandler/console.cc
+++ b/winsup/cygwin/fhandler/console.cc
@@ -1926,9 +1926,11 @@ fhandler_console::close ()
 	  || get_device () == (dev_t) myself->ctty))
     free_console ();
 
-  if (shared_console_info[unit])
-    UnmapViewOfFile ((void *) shared_console_info[unit]);
-  shared_console_info[unit] = NULL;
+  if (shared_console_info[unit] && myself->ctty != tc ()->ntty)
+    {
+      UnmapViewOfFile ((void *) shared_console_info[unit]);
+      shared_console_info[unit] = NULL;
+    }
 
   return 0;
 }
-- 
2.43.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-03-01 10:54 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-01 10:53 [PATCH] Cygwin: console: Do not unmap shared console memory belonging to ctty Takashi Yano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).