[newlib-cygwin/cygwin-3_3-branch] Cygwin: ACLs: ignore *_INHERIT flags in file ACLs

Corinna Vinschen corinna@sourceware.org
Wed Jan 12 09:11:51 GMT 2022


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

commit 2537b3134b3239f5e7ebb45b15a684255e2c8e49
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Tue Jan 11 22:20:47 2022 +0100

    Cygwin: ACLs: ignore *_INHERIT flags in file ACLs
    
    get_posix_access() creates DEF_*_OBJ aclent_t entries from Windows ACEs
    with INHERIT flags set, independent of the file type.  These flags only
    make sense on directory objects, but certain Windows functions don't
    check the file type and allow INHERIT ACE flags even on non-directories.
    
    As a fix, make sure to ignore the INHERIT flags on non-directory ACLs
    and don't propagate the matching DEF_*_OBJ aclent_t entries to callers.
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/release/3.3.4 | 3 +++
 winsup/cygwin/sec_acl.cc    | 9 ++++++---
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/winsup/cygwin/release/3.3.4 b/winsup/cygwin/release/3.3.4
index 048426942..1982df0cf 100644
--- a/winsup/cygwin/release/3.3.4
+++ b/winsup/cygwin/release/3.3.4
@@ -17,3 +17,6 @@ Bug Fixes
 
 - Avoid a crash when NtQueryInformationProcess returns invalid handle data.
   Addresses: https://cygwin.com/pipermail/cygwin-patches/2021q4/011611.html
+
+- Ignore INHERIT ACEs when reading the DACL of non-directory files.
+  Addresses: https://cygwin.com/pipermail/cygwin/2022-January/250363.html
diff --git a/winsup/cygwin/sec_acl.cc b/winsup/cygwin/sec_acl.cc
index 90969b639..98d2391b1 100644
--- a/winsup/cygwin/sec_acl.cc
+++ b/winsup/cygwin/sec_acl.cc
@@ -811,7 +811,8 @@ get_posix_access (PSECURITY_DESCRIPTOR psd,
 			  class_perm = lacl[pos].a_perm;
 			}
 		    }
-		  if (ace->Header.AceFlags & SUB_CONTAINERS_AND_OBJECTS_INHERIT)
+		  if (S_ISDIR (attr)
+		      && (ace->Header.AceFlags & SUB_CONTAINERS_AND_OBJECTS_INHERIT) != 0)
 		    {
 		      if ((pos = searchace (lacl, MAX_ACL_ENTRIES,
 					    DEF_CLASS_OBJ)) >= 0)
@@ -952,7 +953,8 @@ get_posix_access (PSECURITY_DESCRIPTOR psd,
 		standard_ACEs_only = false;
 	    }
 	}
-      if ((ace->Header.AceFlags & SUB_CONTAINERS_AND_OBJECTS_INHERIT))
+      if (S_ISDIR (attr)
+	  && (ace->Header.AceFlags & SUB_CONTAINERS_AND_OBJECTS_INHERIT) != 0)
 	{
 	  if (type == USER_OBJ)
 	    {
@@ -1197,10 +1199,11 @@ int
 getacl (HANDLE handle, path_conv &pc, int nentries, aclent_t *aclbufp)
 {
   security_descriptor sd;
+  mode_t attr = pc.isdir () ? S_IFDIR : 0;
 
   if (get_file_sd (handle, pc, sd, false))
     return -1;
-  int pos = get_posix_access (sd, NULL, NULL, NULL, aclbufp, nentries);
+  int pos = get_posix_access (sd, &attr, NULL, NULL, aclbufp, nentries);
   syscall_printf ("%R = getacl(%S)", pos, pc.get_nt_native_path ());
   return pos;
 }


More information about the Cygwin-cvs mailing list