Register Windows desktop uninstall ownership before sandbox setup (#45224)

## Why

Desktop uninstall cleanup needs an installation owner even when the user has not signed in or configured the Windows sandbox. Recording ownership only during provisioning leaves those installations unregistered.

## What changed

- Add an authenticated installation registration request and attempt it during Windows desktop stdio initialization, with a five-second timeout before the initialization response.
- Persist ownership independently of provisioning, preserve existing desktop ownership, and prevent another user or home from replacing the registered owner.
- Validate write authority and retain directory handles and guards to protect the registered home against junction conversion through privileged cleanup.
- Preserve existing CLI homes during desktop uninstall while removing their `CodexSandboxUsers` ACL entries. Report ACL revocation errors and avoid propagating unchanged ACLs.
- Grant the owner `WRITE_DAC` on `.sandbox-bin` and allow elevated-helper fallback when older permissions need repair or the service cannot establish an uninstall watcher.

## Testing

Add tests for installation registration without sandbox settings and for preserving a child's null DACL when revoking an absent SID from its parent.

GitOrigin-RevId: fb48923e9d76758d1bf5b50c7305aa60f91629db
This commit is contained in:
chess authored and copyberry committed 2026-09-13 13:06:40 +00:00
1 parent 1715e55076
commit 36f0dbe796
20 files changed
+446 -146

No files matched your search

+29 -8
View File
@@ -899,7 +899,11 @@ pub unsafe fn add_deny_read_ace(path: &Path, psid: *mut c_void) -> Result<bool>
#[path = "acl_tests.rs"]
mod tests;
pub unsafe fn revoke_ace(path: &Path, psid: *mut c_void) {
/// Removes explicit ACEs for one SID and propagates the updated inherited ACL.
///
/// # Safety
/// Caller must pass a valid SID pointer and have authority to edit the target DACL.
pub unsafe fn revoke_ace(path: &Path, psid: *mut c_void) -> Result<()> {
let mut p_sd: *mut c_void = std::ptr::null_mut();
let mut p_dacl: *mut ACL = std::ptr::null_mut();
let code = GetNamedSecurityInfoW(
@@ -916,7 +920,14 @@ pub unsafe fn revoke_ace(path: &Path, psid: *mut c_void) {
if !p_sd.is_null() {
LocalFree(p_sd as HLOCAL);
}
return;
return acl_api_result(path, "GetNamedSecurityInfoW", code);
}
if p_dacl.is_null() {
// A null DACL has no ACE to revoke; replacing it with an empty ACL would deny access.
if !p_sd.is_null() {
LocalFree(p_sd as HLOCAL);
}
return Ok(());
}
let trustee = TRUSTEE_W {
pMultipleTrustee: std::ptr::null_mut(),
@@ -931,9 +942,17 @@ pub unsafe fn revoke_ace(path: &Path, psid: *mut c_void) {
explicit.grfInheritance = CONTAINER_INHERIT_ACE | OBJECT_INHERIT_ACE;
explicit.Trustee = trustee;
let mut p_new_dacl: *mut ACL = std::ptr::null_mut();
let code2 = SetEntriesInAclW(1, &explicit, p_dacl, &mut p_new_dacl);
if code2 == ERROR_SUCCESS {
let _ = SetNamedSecurityInfoW(
let result = acl_api_result(
path,
"SetEntriesInAclW",
SetEntriesInAclW(1, &explicit, p_dacl, &mut p_new_dacl),
)
.and_then(|()| {
// REVOKE_ACCESS only removes ACEs. An unchanged ACL must not propagate inheritance.
if (*p_new_dacl).AceCount == (*p_dacl).AceCount {
return Ok(());
}
let code = SetNamedSecurityInfoW(
to_wide(path).as_ptr() as *mut u16,
1,
DACL_SECURITY_INFORMATION,
@@ -942,13 +961,15 @@ pub unsafe fn revoke_ace(path: &Path, psid: *mut c_void) {
p_new_dacl,
std::ptr::null_mut(),
);
if !p_new_dacl.is_null() {
LocalFree(p_new_dacl as HLOCAL);
}
acl_api_result(path, "SetNamedSecurityInfoW", code)
});
if !p_new_dacl.is_null() {
LocalFree(p_new_dacl as HLOCAL);
}
if !p_sd.is_null() {
LocalFree(p_sd as HLOCAL);
}
result
}
/// Grants RX to the null device for the given SID to support stdout/stderr redirection.