public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
From: Takashi Yano <tyan0@sourceware.org>
To: cygwin-cvs@sourceware.org
Subject: [newlib-cygwin] Cygwin: console: Do not unmap shared console memory belonging to ctty.
Date: Fri,  1 Mar 2024 11:02:08 +0000 (GMT)	[thread overview]
Message-ID: <20240301110208.837DB3858D39@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=c77a5689f7bd4520f6d87481fd08591747b5da0f

commit c77a5689f7bd4520f6d87481fd08591747b5da0f
Author: Takashi Yano <takashi.yano@nifty.ne.jp>
Date:   Fri Mar 1 19:05:36 2024 +0900

    Cygwin: console: Do not unmap shared console memory belonging to ctty.
    
    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>

Diff:
---
 winsup/cygwin/fhandler/console.cc | 8 +++++---
 winsup/cygwin/release/3.5.2       | 7 +++++++
 2 files changed, 12 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;
 }
diff --git a/winsup/cygwin/release/3.5.2 b/winsup/cygwin/release/3.5.2
new file mode 100644
index 000000000..7d8df9489
--- /dev/null
+++ b/winsup/cygwin/release/3.5.2
@@ -0,0 +1,7 @@
+Fixes:
+------
+
+- Fix the problem that console setup accesses shared memory which
+  is already unmapped due to race condition. To avoid this issue,
+  shared console memory will be kept mapped if it belongs to CTTY.
+  Addresses:  https://cygwin.com/pipermail/cygwin/2024-February/255561.html

                 reply	other threads:[~2024-03-01 11:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240301110208.837DB3858D39@sourceware.org \
    --to=tyan0@sourceware.org \
    --cc=cygwin-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).