Ignore inherited ACEs when refreshing Windows write roots (#34392)

## Why

An inherited `FILE_DELETE_CHILD` grant can make a write root look stale, but
`SET_ACCESS` cannot replace an ACE inherited from an ancestor. Treating that
grant as explicit causes unnecessary ACL refresh attempts that cannot converge.

## What changed

- Add explicit-ACE filtering to the Windows DACL permission checks.
- Refresh a write root only when `FILE_DELETE_CHILD` is present in an explicit
  allow ACE, while retaining effective-permission checks for required rights.
- Ignore inherited stale rights when deciding whether `SET_ACCESS` must repair
  an allow ACE.

## Testing

Add a Windows regression test covering a write root that inherits
`FILE_DELETE_CHILD`, verifying that repeated refresh checks leave its explicit
write ACE unchanged.

GitOrigin-RevId: d0df9429efcf299da3ff3c1bce92942684803293
This commit is contained in:
Felipe Coury authored and copyberry committed 2026-07-20 18:28:02 +00:00
1 parent 45ac251e17
commit bd92b056dd
3 files changed
+116 -8

No files matched your search

+62 -2
View File
@@ -49,6 +49,7 @@ use windows_sys::Win32::Storage::FileSystem::OPEN_EXISTING;
use windows_sys::Win32::Storage::FileSystem::READ_CONTROL;
const SE_KERNEL_OBJECT: u32 = 6;
const INHERIT_ONLY_ACE: u8 = 0x08;
const INHERITED_ACE: u8 = 0x10;
const ACCESS_ALLOWED_ACE_TYPE: u8 = 0;
const ACCESS_DENIED_ACE_TYPE: u8 = 1;
const GENERIC_READ_MASK: u32 = 0x8000_0000;
@@ -103,6 +104,28 @@ pub unsafe fn dacl_mask_allows(
psids: &[*mut c_void],
desired_mask: u32,
require_all_bits: bool,
) -> bool {
dacl_mask_allows_with_scope(
p_dacl,
psids,
desired_mask,
require_all_bits,
AceScope::Effective,
)
}
#[derive(Clone, Copy)]
enum AceScope {
Effective,
Explicit,
}
unsafe fn dacl_mask_allows_with_scope(
p_dacl: *mut ACL,
psids: &[*mut c_void],
desired_mask: u32,
require_all_bits: bool,
scope: AceScope,
) -> bool {
if p_dacl.is_null() {
return false;
@@ -135,6 +158,11 @@ pub unsafe fn dacl_mask_allows(
if (hdr.AceFlags & INHERIT_ONLY_ACE) != 0 {
continue;
}
// SET_ACCESS cannot replace an ACE inherited from an ancestor, so it cannot make
// an explicit-only repair converge when that inherited ACE contains stale rights.
if matches!(scope, AceScope::Explicit) && (hdr.AceFlags & INHERITED_ACE) != 0 {
continue;
}
let base = p_ace as usize;
let sid_ptr =
(base + std::mem::size_of::<ACE_HEADER>() + std::mem::size_of::<u32>()) as *mut c_void;
@@ -166,10 +194,41 @@ pub fn path_mask_allows(
psids: &[*mut c_void],
desired_mask: u32,
require_all_bits: bool,
) -> Result<bool> {
path_mask_allows_with_scope(
path,
psids,
desired_mask,
require_all_bits,
AceScope::Effective,
)
}
/// Returns whether an explicit allow ACE for one of the provided SIDs grants any bit in `desired_mask`.
pub fn path_mask_has_explicit_allow_ace(
path: &Path,
psids: &[*mut c_void],
desired_mask: u32,
) -> Result<bool> {
path_mask_allows_with_scope(
path,
psids,
desired_mask,
/*require_all_bits*/ false,
AceScope::Explicit,
)
}
fn path_mask_allows_with_scope(
path: &Path,
psids: &[*mut c_void],
desired_mask: u32,
require_all_bits: bool,
scope: AceScope,
) -> Result<bool> {
unsafe {
let (p_dacl, sd) = fetch_dacl_handle(path)?;
let has = dacl_mask_allows(p_dacl, psids, desired_mask, require_all_bits);
let has = dacl_mask_allows_with_scope(p_dacl, psids, desired_mask, require_all_bits, scope);
if !sd.is_null() {
LocalFree(sd as HLOCAL);
}
@@ -318,11 +377,12 @@ unsafe fn ensure_allow_mask_aces_with_inheritance_impl(
let mut entries: Vec<EXPLICIT_ACCESS_W> = Vec::new();
for sid in sids {
if dacl_mask_allows(p_dacl, &[*sid], allow_mask, /*require_all_bits*/ true)
&& !dacl_mask_allows(
&& !dacl_mask_allows_with_scope(
p_dacl,
&[*sid],
disallow_mask,
/*require_all_bits*/ false,
AceScope::Explicit,
)
{
continue;