From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 470483858C41; Tue, 31 Oct 2023 10:27:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 470483858C41 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1698748027; bh=SbO8ZCD97j44Pj2mwJsjQpc4At2v+/VqzWp+mDYgH2c=; h=From:To:Subject:Date:From; b=TatjQMuxDYxkhsCWfzAFnzQzViPfdnh7SyqEkAmR8EgmwD09pWErsPIyKSXhPMtZ+ kp0B0DFwtrFGhAumxlLC4LglS7AiPDXdQFfGNkqwGleL2I8B82ovTNAE05U97mygA/ jbLHW+FPVqhGf5iqWaERbsfhjv6R7PMG95PkK/FM= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin/cygwin-3_4-branch] Cygwin: cwd: avoid releasing the cwdstuff SRW Lock twice X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/cygwin-3_4-branch X-Git-Oldrev: 386e762aa140a18c4bc3fd5963c4bbc6e2663c76 X-Git-Newrev: f0c90d3a8aa4409608abe76e035eab5919133a61 Message-Id: <20231031102707.470483858C41@sourceware.org> Date: Tue, 31 Oct 2023 10:27:07 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3Df0c90d3a8aa= 4409608abe76e035eab5919133a61 commit f0c90d3a8aa4409608abe76e035eab5919133a61 Author: Corinna Vinschen AuthorDate: Mon Oct 30 19:40:31 2023 +0100 Commit: Corinna Vinschen CommitDate: Tue Oct 31 10:52:02 2023 +0100 Cygwin: cwd: avoid releasing the cwdstuff SRW Lock twice =20 cwdstuff::set has a code snippet handling the case where a process can't create a handle to a directory, e. g., due to permissions. =20 Commit 88443b0a22589 ("cwdstuff: Don't leave from setting the CWD prematurely on init") introduced a special case to handle this situation at process initialization. It also introduces an early mutex release, which is not required, but ok, because we're in the init phase. Releasing the mutex twice is no problem since the mutexes are recursive. =20 Fast forward to commit 0819679a7a210 ("Cygwin: cwd: use SRWLOCK instead of muto"). The mechanical change from a recursive mutex to a non-recursive SRWLOCK failed to notice that this very specific situation will release the SRWLOCK twice. =20 Remove the superfluous release action. While at it, don't set dir to NULL, but h, since dir will get the value of h anyway later on. Setting h to NULL may not be necessary, but better safe than sorry. =20 Reported-by: tryandbuy >tryandbuy@proton.me> Fixes: 88443b0a22589 ("cwdstuff: Don't leave from setting the CWD prema= turely on init") Fixes: 0819679a7a210 ("Cygwin: cwd: use SRWLOCK instead of muto") Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/path.cc | 3 +-- winsup/cygwin/release/3.4.10 | 3 +++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc index e788c7d60e03..5ad9e201f74e 100644 --- a/winsup/cygwin/path.cc +++ b/winsup/cygwin/path.cc @@ -4942,10 +4942,9 @@ cwdstuff::set (path_conv *nat_cwd, const char *posix= _cwd) peb.ProcessParameters->CurrentDirectoryHandle, GetCurrentProcess (), &h, 0, TRUE, 0)) { - release_write (); if (peb.ProcessParameters->CurrentDirectoryHandle) debug_printf ("...and DuplicateHandle failed with %E."); - dir =3D NULL; + h =3D NULL; } } } diff --git a/winsup/cygwin/release/3.4.10 b/winsup/cygwin/release/3.4.10 index f34b131b32ae..c75283991461 100644 --- a/winsup/cygwin/release/3.4.10 +++ b/winsup/cygwin/release/3.4.10 @@ -3,3 +3,6 @@ Bug Fixes =20 - Fix missing term in __cpuset_zero_s() prototoype in sys/cpuset.h. Addresses: https://cygwin.com/pipermail/cygwin/2023-September/254423.html + +- Fix hang in process initialization if cwd is unreadable. + Addresses: https://cygwin.com/pipermail/cygwin/2023-October/254604.html