From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7868) id 837DB3858D39; Fri, 1 Mar 2024 11:02:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 837DB3858D39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1709290928; bh=/u+IX087ULmWm0UDnX1eV7pTgXXMaA6ky0Bde7qz+mM=; h=From:To:Subject:Date:From; b=H8jfaPNwU4r/3kuQ/zejPHHMELJcrOpxrq83BWKWVltnLqAnPDrxFMXHSxRBAgsiV c/ehhHbLrBWMr3/Y1h06yzpWzBIuRDpfmxlSslZZxJt2qnabeebNNlqd42n3VWtnpr l7O8bTBCiXZ9ojnc3aDpLYgnJaYmjhxt1DxkSXCk= 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: 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/master X-Git-Oldrev: ee97ae1d5f4d42d47d828a1b4d9b05ec9cbfe042 X-Git-Newrev: c77a5689f7bd4520f6d87481fd08591747b5da0f Message-Id: <20240301110208.837DB3858D39@sourceware.org> Date: Fri, 1 Mar 2024 11:02:08 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3Dc77a5689f7b= d4520f6d87481fd08591747b5da0f commit c77a5689f7bd4520f6d87481fd08591747b5da0f 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