Skip to content

Commit

Permalink
Cygwin: console: Do not unmap shared console memory belonging to ctty.
Browse files Browse the repository at this point in the history
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: 3721a75 ("Cygwin: console: Make the console accessible from other terminals.")
Reported-by: Kate Deplaix <[email protected]>
Signed-off-by: Takashi Yano <[email protected]>
  • Loading branch information
tyan0 committed Mar 1, 2024
1 parent ee97ae1 commit c77a568
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 5 additions & 3 deletions winsup/cygwin/fhandler/console.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
7 changes: 7 additions & 0 deletions winsup/cygwin/release/3.5.2
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c77a568

Please sign in to comment.