Bind SYSTEM bootstrap to exact runtime and original process exit
Rust development slice / linux (push) Failing after 7s

This commit is contained in:
2026-11-16 14:37:53 +01:00
parent 9e64ccabdb
commit 4394b1bd85
4 changed files with 377 additions and 9 deletions
+2 -2
View File
@@ -232,7 +232,7 @@ $targets=@{settings=(Join-Path $helperRoot 'helper.json');pin=(Join-Path $helper
function HashBytes([byte[]]$bytes){$sha=[Security.Cryptography.SHA256]::Create();try{return([BitConverter]::ToString($sha.ComputeHash($bytes))).Replace('-','').ToLowerInvariant()}finally{$sha.Dispose()}}
function HashFile([string]$path){return(Get-FileHash -LiteralPath $path -Algorithm SHA256).Hash.ToLowerInvariant()}
function CheckPath([string]$path,[bool]$directory){$item=Get-Item -LiteralPath $path;if($item.PSIsContainer-ne$directory-or($item.Attributes-band[IO.FileAttributes]::ReparsePoint)-ne0){throw 'Protected regular path'};$acl=Get-Acl -LiteralPath $path;$owner=$acl.GetOwner([Security.Principal.SecurityIdentifier]).Value;if($owner-cnotin@('S-1-5-18','S-1-5-32-544')){throw 'Privileged owner required'};foreach($rule in $acl.GetAccessRules($true,$true,[Security.Principal.SecurityIdentifier])){$sid=$rule.IdentityReference.Value;if($rule.AccessControlType-ne[Security.AccessControl.AccessControlType]::Allow){throw 'Unexpected deny ACL'};if($sid-cin@('S-1-5-18','S-1-5-32-544')){continue};if($sid-cnotin@($agentSid,$helperSid)-or([int64]$rule.FileSystemRights-band(-bnot 0x1200a9))-ne0){throw 'Foreign or writable public access'}};return $acl}
function CheckStopped{if($null-eq$p.expected_service_processes-or@($p.expected_service_processes).Count-ne2){throw 'Two actual original process witnesses required'};foreach($old in @($p.expected_service_processes)){if([int]$old.pid-le0-or![string]$old.creation_filetime){throw 'Original kernel creation witness'};$live=Get-Process -Id ([int]$old.pid) -ErrorAction SilentlyContinue;if($null-ne$live){try{if($live.StartTime.ToUniversalTime().ToFileTimeUtc().ToString()-ceq$old.creation_filetime-and!$live.HasExited){throw 'Original service process still live'}}finally{$live.Dispose()}}};foreach($name in @('RmmDiscoveryWindows','RmmDiscoverySystemHelper')){$service=Get-CimInstance Win32_Service -Filter ("Name='"+$name+"'");if(!$service-or$service.State-cne'Stopped'-or[int]$service.ProcessId-ne0){throw 'Coordinated quiescent pair stop required'}}}
function CheckStopped{if($null-eq$p.expected_service_processes-or@($p.expected_service_processes).Count-ne2){throw 'Two actual original process witnesses required'};foreach($old in @($p.expected_service_processes)){if([int]$old.pid-le0-or![string]$old.creation_filetime){throw 'Original kernel creation witness'};$live=Get-Process -Id ([int]$old.pid) -ErrorAction SilentlyContinue;if($null-ne$live){try{if($live.StartTime.ToUniversalTime().ToFileTimeUtc().ToString()-ceq$old.creation_filetime-and!$live.HasExited){throw 'Original service process still live'}}finally{$live.Dispose()}}};foreach($name in @('RmmDiscoveryWindows','RmmDiscoverySystemHelper')){$service=Get-CimInstance Win32_Service -Filter ("Name='"+$name+"'");if(!$service-or$service.State-cne'Stopped'){throw 'Coordinated quiescent pair stop required'}}}
function PublicAcl{$acl=New-Object Security.AccessControl.FileSecurity;$acl.SetSecurityDescriptorSddlForm(('O:BAG:BAD:P(A;;FA;;;SY)(A;;FA;;;BA)(A;;0x1200a9;;;'+$agentSid+')(A;;0x1200a9;;;'+$helperSid+')'));return $acl}
function WritePublicOnce([string]$path,[byte[]]$bytes){
$rights=[Security.AccessControl.FileSystemRights]::ReadWrite
@@ -264,7 +264,7 @@ function ServiceDefinitions {
$rows=[ordered]@{}
foreach($name in @('RmmDiscoveryWindows','RmmDiscoverySystemHelper')){
$s=Get-CimInstance Win32_Service -Filter ("Name='"+$name+"'")
if(!$s-or$s.State-cne'Stopped'-or[int]$s.ProcessId-ne0-or$s.ServiceType-cne'Own Process'){throw 'Fixed stopped own-process services'}
if(!$s-or$s.State-cne'Stopped'-or$s.ServiceType-cne'Own Process'){throw 'Fixed stopped own-process services'}
$old=$p.expected_service_definitions.$name
if(!$old-or$s.PathName-cne$old.path-or$s.StartName-cne$old.configured_account){throw 'Original SCM command/account CAS'}
$rows[$name]=@{path=$s.PathName;configured_account=$s.StartName;start_mode=$s.StartMode}