aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakashi Yano <takashi.yano@nifty.ne.jp>2024-03-01 19:05:36 +0900
committerTakashi Yano <takashi.yano@nifty.ne.jp>2024-03-01 20:01:28 +0900
commitcf121e088f928c68a8e3c799db97478c89b6dd96 (patch)
tree0acb8557e87bfa491697cc52d2ea8b040675d442
parentb65153e50e9b6f336f8709dfa6a28c1fa69a1c77 (diff)
downloadnewlib-cf121e088f928c68a8e3c799db97478c89b6dd96.zip
newlib-cf121e088f928c68a8e3c799db97478c89b6dd96.tar.gz
newlib-cf121e088f928c68a8e3c799db97478c89b6dd96.tar.bz2
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>
-rw-r--r--winsup/cygwin/fhandler/console.cc8
-rw-r--r--winsup/cygwin/release/3.5.27
2 files changed, 12 insertions, 3 deletions
diff --git a/winsup/cygwin/fhandler/console.cc b/winsup/cygwin/fhandler/console.cc
index c16ca39..67ea954 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 0000000..7d8df94
--- /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