From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7868) id E14D23858C53; Fri, 1 Mar 2024 11:01:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E14D23858C53 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1709290908; bh=2chDkPsQp+eXcUu/IiG2W4yG8GCW7oIHU1M+NRT4WXA=; h=From:To:Subject:Date:From; b=vcMFPomFoDKJz9aZdJnY/xSdWg/JmPZFFi7WECh2+66jzch+/TQbyxvmAsZegU5OY 6z3Yo9ePZCbfmF3pNyC5LwQdH9HzKckBPRczHdMyYokamVakMm0H1lfOQ3hfTT1Zx+ kM1vnotPtfjDbUYKuxxdv6bzq7RixjbqUziL4U3k= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Takashi Yano To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin/cygwin-3_5-branch] Cygwin: console: Do not unmap shared console memory belonging to ctty. X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/cygwin-3_5-branch X-Git-Oldrev: b65153e50e9b6f336f8709dfa6a28c1fa69a1c77 X-Git-Newrev: cf121e088f928c68a8e3c799db97478c89b6dd96 Message-Id: <20240301110148.E14D23858C53@sourceware.org> Date: Fri, 1 Mar 2024 11:01:47 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3Dcf121e088f9= 28c68a8e3c799db97478c89b6dd96 commit cf121e088f928c68a8e3c799db97478c89b6dd96 Author: Takashi Yano Date: Fri Mar 1 19:05:36 2024 +0900 Cygwin: console: Do not unmap shared console memory belonging to ctty. =20 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 =20 Fixes: 3721a756b0d8 ("Cygwin: console: Make the console accessible from= other terminals.") Reported-by: Kate Deplaix Signed-off-by: Takashi Yano 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/con= sole.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 () =3D=3D (dev_t) myself->ctty)) free_console (); =20 - if (shared_console_info[unit]) - UnmapViewOfFile ((void *) shared_console_info[unit]); - shared_console_info[unit] =3D NULL; + if (shared_console_info[unit] && myself->ctty !=3D tc ()->ntty) + { + UnmapViewOfFile ((void *) shared_console_info[unit]); + shared_console_info[unit] =3D NULL; + } =20 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