public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
From: Takashi Yano <tyan0@sourceware.org>
To: cygwin-cvs@sourceware.org
Subject: [newlib-cygwin/cygwin-3_4-branch] Cygwin: shared: Fix access permissions setting in open_shared().
Date: Wed, 16 Aug 2023 13:12:47 +0000 (GMT)	[thread overview]
Message-ID: <20230816131247.4C4D1385DC18@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=c3eab1e295c2716b9c670213d7de21c968ebc161

commit c3eab1e295c2716b9c670213d7de21c968ebc161
Author: Takashi Yano <takashi.yano@nifty.ne.jp>
Date:   Wed Aug 16 08:00:27 2023 +0900

    Cygwin: shared: Fix access permissions setting in open_shared().
    
    After the commit 62f11a5a5704, the access permissions argument passed
    to open_shared() is ignored and always replaced with (FILE_MAP_READ |
    FILE_MAP_WRITE). This causes the weird behaviour that sshd service
    process loses its cygwin PID. This triggers the failure in pty that
    transfer_input() does not work properly.
    
    This patch resumes the access permission settings to fix that.
    
    Fixes: 62f11a5a5704 ("Cygwin: open_shared: don't reuse shared_locations parameter as output")
    Fixes: fb16f490bf6e ("Cygwin: open_shared: try harder allocating a shared region")
    Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
    Signedd-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>

Diff:
---
 winsup/cygwin/mm/shared.cc  | 9 +++------
 winsup/cygwin/release/3.4.8 | 3 +++
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/winsup/cygwin/mm/shared.cc b/winsup/cygwin/mm/shared.cc
index 2ea3a4336..20b57ff4d 100644
--- a/winsup/cygwin/mm/shared.cc
+++ b/winsup/cygwin/mm/shared.cc
@@ -148,8 +148,7 @@ open_shared (const WCHAR *name, int n, HANDLE& shared_h, DWORD size,
       if (name)
 	mapname = shared_name (map_buf, name, n);
       if (m == SH_JUSTOPEN)
-	shared_h = OpenFileMappingW (FILE_MAP_READ | FILE_MAP_WRITE, FALSE,
-				     mapname);
+	shared_h = OpenFileMappingW (access, FALSE, mapname);
       else
 	{
 	  created = true;
@@ -175,8 +174,7 @@ open_shared (const WCHAR *name, int n, HANDLE& shared_h, DWORD size,
 	 Note that we don't actually *need* fixed addresses.  The only
 	 advantage is reproducibility to help /proc/<PID>/maps along. */
       addr = (void *) region_address[m];
-      shared = MapViewOfFileEx (shared_h, FILE_MAP_READ | FILE_MAP_WRITE,
-				0, 0, 0, addr);
+      shared = MapViewOfFileEx (shared_h, access, 0, 0, 0, addr);
     }
   /* Also catch the unlikely case that a fixed region can't be mapped at the
      fixed address. */
@@ -190,8 +188,7 @@ open_shared (const WCHAR *name, int n, HANDLE& shared_h, DWORD size,
       do
 	{
 	  addr = (void *) next_address;
-	  shared = MapViewOfFileEx (shared_h, FILE_MAP_READ | FILE_MAP_WRITE,
-				    0, 0, 0, addr);
+	  shared = MapViewOfFileEx (shared_h, access, 0, 0, 0, addr);
 	  next_address += wincap.allocation_granularity ();
 	  if (next_address >= SHARED_REGIONS_ADDRESS_HIGH)
 	    {
diff --git a/winsup/cygwin/release/3.4.8 b/winsup/cygwin/release/3.4.8
index 448831c65..8cd3eb14b 100644
--- a/winsup/cygwin/release/3.4.8
+++ b/winsup/cygwin/release/3.4.8
@@ -17,3 +17,6 @@ Bug Fixes
 
 - Fix memory leak in printf() regarding gdtoa-based _ldtoa_r().
   Addresses: https://cygwin.com/pipermail/cygwin/2023-July/254054.html
+
+- Fix a bug introduced in cygwin 3.4.5 that open_shared() does not set
+  access permissions as requested by its argument.

                 reply	other threads:[~2023-08-16 13:12 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230816131247.4C4D1385DC18@sourceware.org \
    --to=tyan0@sourceware.org \
    --cc=cygwin-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).