smoke-aces.ps1 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. <#
  2. Additive-DENY-ACE lifecycle smoke (the A-row equivalents from
  3. the deleted smoke-acl.ps1, re-expressed for the separate-user
  4. model: trustee = `srt-sandbox`'s SID, mechanism = additive
  5. explicit DENY ACE, refcount = `ace_holders` table).
  6. Self-contained: provisions the `srt-sandbox` account + WFP
  7. filters under a fixed test-only sublayer GUID (distinct from
  8. smoke.ps1 / smoke-exec.ps1) and grants a scratch tree to the
  9. sandbox user so the child can read test files at all.
  10. #>
  11. param(
  12. [Parameter(Mandatory = $true, Position = 0)]
  13. [string] $Exe
  14. )
  15. $ErrorActionPreference = 'Stop'
  16. # Fixed test-only sublayer; distinct from smoke.ps1 and smoke-exec.ps1.
  17. # Referenced verbatim by the workflow's always()-cleanup step.
  18. $Sublayer = 'd3a85b1c-7e92-4f6a-b1d4-8e0c5f2a9b3e'
  19. $PortRange = '60080-60089'
  20. function Run { param([string[]] $argv)
  21. & $Exe @argv
  22. if ($LASTEXITCODE -ne 0) {
  23. throw "srt-win $($argv -join ' ') exited $LASTEXITCODE"
  24. }
  25. }
  26. function J { param([string[]] $argv) Run $argv | ConvertFrom-Json }
  27. function Stdin { param([string[]] $argv, [string] $json)
  28. $raw = $json | & $Exe @argv 2>&1 | Out-String
  29. Write-Host -NoNewline $raw
  30. if ($LASTEXITCODE -ne 0) {
  31. throw "srt-win $($argv -join ' ') exited ${LASTEXITCODE}: $raw"
  32. }
  33. }
  34. function RunCapture { param([string[]] $argv)
  35. $raw = & $Exe @argv 2>&1 | Out-String
  36. return [pscustomobject]@{ exit = $LASTEXITCODE; raw = $raw }
  37. }
  38. $cmd = Join-Path $env:SystemRoot 'System32\cmd.exe'
  39. $pwsh = Join-Path $env:SystemRoot 'System32\WindowsPowerShell\v1.0\powershell.exe'
  40. $env:SANDBOX_RUNTIME_WIN_DEBUG = '1'
  41. Write-Host "smoke-aces: sublayer=$Sublayer exe=$Exe"
  42. try { Start-Service seclogon -ea Stop } catch {
  43. Write-Host "smoke-aces: WARNING: Start-Service seclogon: $_"
  44. }
  45. Run @('install','--sublayer-guid',$Sublayer,'--proxy-port-range',$PortRange)
  46. $us = J @('user','status')
  47. if (-not $us.user.exists) { throw 'srt-sandbox not provisioned' }
  48. $sbSid = $us.marker_user_sid
  49. if (-not $sbSid) { throw 'setup marker missing user_sid' }
  50. Write-Host "smoke-aces: sandbox user sid=$sbSid"
  51. # Exec helper — same as smoke-exec.ps1's RExec.
  52. # Do NOT pass --quiet — A28's assertion depends on the
  53. # `per-exec deny.*holder_pid=\d+` diag line, which is `!quiet`-gated.
  54. function RExec {
  55. param([string[]] $tail)
  56. $argv = @('exec',
  57. '--env', "PATH=$($env:PATH)",
  58. '--env', "PATHEXT=$($env:PATHEXT)") + $tail
  59. $psi = [System.Diagnostics.ProcessStartInfo]::new()
  60. $psi.FileName = $Exe
  61. $psi.UseShellExecute = $false
  62. $psi.RedirectStandardOutput = $true
  63. $psi.RedirectStandardError = $true
  64. $psi.Environment['SANDBOX_RUNTIME_WIN_DEBUG'] = '1'
  65. foreach ($a in $argv) { $null = $psi.ArgumentList.Add($a) }
  66. $p = [System.Diagnostics.Process]::Start($psi)
  67. $so = $p.StandardOutput.ReadToEndAsync()
  68. $se = $p.StandardError.ReadToEndAsync()
  69. if (-not $p.WaitForExit(30000)) {
  70. try { $p.Kill($true) } catch { }
  71. $p.WaitForExit()
  72. throw ("RExec: TIMEOUT after 30s. argv: $($argv -join ' ')`n" +
  73. "stderr: $($se.Result)`nstdout: $($so.Result)")
  74. }
  75. $exit = $p.ExitCode
  76. $raw = $so.Result + $se.Result
  77. $lines = $raw -split "`r?`n"
  78. $child = ($lines | Where-Object { $_ -notmatch '^srt-win:' }) -join "`n"
  79. return [pscustomobject]@{ exit = $exit; raw = $raw; out = $child }
  80. }
  81. # `acl stamp` for a given holder PID. JSON body is positional so
  82. # call sites stay one-liners.
  83. function Stamp { param([hashtable] $body, [int] $HolderPid = $PID)
  84. $j = (ConvertTo-Json -Compress -Depth 4 $body)
  85. Stdin @('acl','stamp','--holder-pid',$HolderPid,
  86. '--sandbox-user-sid',$sbSid) $j
  87. }
  88. # `acl restore` for a given holder. Best-effort (does not throw).
  89. function Restore { param([int] $HolderPid)
  90. & $Exe acl restore --holder-pid $HolderPid `
  91. --sandbox-user-sid $sbSid 2>&1 | Out-String | Write-Host -NoNewline
  92. }
  93. # "Is there an explicit DENY ACE for the sandbox user on this path?"
  94. # — the additive-DENY-ACE equivalent of smoke-acl's Get-MarkerHash.
  95. # Filtered to explicit (non-inherited) Deny so the working-tree
  96. # GRANT on $Root that inherits into every test file doesn't count.
  97. $sbAcct = New-Object System.Security.Principal.SecurityIdentifier($sbSid)
  98. function Has-SbAce { param([string] $path)
  99. $hits = (Get-Acl $path).Access | Where-Object {
  100. -not $_.IsInherited -and
  101. $_.AccessControlType -eq 'Deny' -and
  102. $_.IdentityReference.Translate(
  103. [System.Security.Principal.SecurityIdentifier]) -eq $sbAcct
  104. }
  105. return [bool]$hits
  106. }
  107. # Scratch tree under the broker's TEMP. GetLongPathName: the GHA
  108. # runner's TEMP is an 8.3 short path; canonicalize so srt-win and
  109. # Get-Acl agree on the canonical form.
  110. $Root = New-Item -ItemType Directory `
  111. -Path (Join-Path $env:TEMP "srt-aces-$([guid]::NewGuid().ToString('N'))")
  112. $k32 = Add-Type -PassThru -Namespace WA -Name K -MemberDefinition `
  113. '[DllImport("kernel32.dll",CharSet=CharSet.Unicode)] public static extern uint GetLongPathName(string s,System.Text.StringBuilder l,uint n);'
  114. $lp = [System.Text.StringBuilder]::new(1024)
  115. if ($k32::GetLongPathName($Root.FullName, $lp, 1024) -gt 0) {
  116. $Root = $lp.ToString()
  117. } else {
  118. $Root = $Root.FullName
  119. }
  120. Write-Host "smoke-aces: scratch=$Root"
  121. try {
  122. # The sandbox user has no implicit access to the broker's
  123. # %TEMP%; grant the scratch root so reads/writes inside it
  124. # succeed BEFORE the per-row deny ACE is layered on.
  125. Stdin @('acl','grant','--holder-pid',$PID,
  126. '--sandbox-user-sid',$sbSid) `
  127. "{`"write`":[`"$($Root -replace '\\','\\')`"]}"
  128. # ── A2: denyWrite — child reads, cannot write; broker can ──────
  129. # f1 first (denyRead) under $PID; A2's stamp of f2 below is then
  130. # a SECOND batch under the same holder — A2(reg) re-checks f1.
  131. $f1 = Join-Path $Root 'a1.txt'
  132. 'A1' | Set-Content -Encoding ASCII $f1
  133. Stamp @{ denyRead = @($f1) }
  134. $f2 = Join-Path $Root 'a2.txt'
  135. 'A2-readable' | Set-Content -Encoding ASCII $f2
  136. Stamp @{ denyWrite = @($f2) }
  137. $r = RExec @('--', $cmd, '/c', "type `"$f2`"")
  138. if ($r.exit -ne 0 -or $r.out -notmatch 'A2-readable') {
  139. throw "A2: child read failed (denyWrite should leave read open). " +
  140. "exit=$($r.exit) raw: $($r.raw)"
  141. }
  142. $r = RExec @('--', $cmd, '/c', "echo nope> `"$f2`"")
  143. if ($r.exit -eq 0) {
  144. throw "A2: child WRITE succeeded (should be denied). raw: $($r.raw)"
  145. }
  146. 'A2-broker-wrote' | Set-Content -Encoding ASCII $f2
  147. if ((Get-Content -Raw $f2).Trim() -ne 'A2-broker-wrote') {
  148. throw 'A2: broker write did not stick'
  149. }
  150. Write-Host 'A2 ok: denyWrite — child reads, child denied write, broker writes'
  151. # ── A2(reg): re-stamp by same holder is UPSERT-not-REPLACE ──────
  152. # A2's stamp of f2 above was a SECOND `apply_aces` batch under
  153. # $PID after f1's. The earlier hold must survive — `ace_holders`
  154. # is (path, kind, pid)-keyed; a second batch must not CASCADE-
  155. # delete the prior batch's rows.
  156. $r = RExec @('--', $cmd, '/c', "type `"$f1`"")
  157. if ($r.exit -eq 0 -or $r.out -match '^A1$') {
  158. throw "A2(reg): earlier deny on f1 was DROPPED by a second " +
  159. "stamp under the same holder. raw: $($r.raw)"
  160. }
  161. Write-Host 'A2(reg) ok: second stamp by same holder kept earlier holds'
  162. # ── A4: refcount — two live holders, restore only on last ──────
  163. $f4 = Join-Path $Root 'a4.txt'
  164. 'A4' | Set-Content -Encoding ASCII $f4
  165. $holderB = Start-Process -FilePath $pwsh -PassThru -WindowStyle Hidden `
  166. -ArgumentList @('-NoProfile','-Command','Start-Sleep 120')
  167. try {
  168. Stamp @{ denyRead = @($f4) } $PID
  169. Stamp @{ denyRead = @($f4) } $holderB.Id
  170. Restore $PID
  171. if (-not (Has-SbAce $f4)) {
  172. throw 'A4: deny ACE removed after only one of two holders released'
  173. }
  174. $r = RExec @('--', $cmd, '/c', "type `"$f4`"")
  175. if ($r.exit -eq 0) {
  176. throw "A4: child read succeeded after one of two holders " +
  177. "released. raw: $($r.raw)"
  178. }
  179. Restore $holderB.Id
  180. if (Has-SbAce $f4) {
  181. throw 'A4: deny ACE still present after both holders released'
  182. }
  183. $r = RExec @('--', $cmd, '/c', "type `"$f4`"")
  184. if ($r.exit -ne 0 -or $r.out -notmatch 'A4') {
  185. throw "A4: child still denied after both holders released. " +
  186. "raw: $($r.raw)"
  187. }
  188. Write-Host 'A4 ok: ace_holders refcount — restore only on last release'
  189. } finally {
  190. Stop-Process -Id $holderB.Id -Force -ea SilentlyContinue
  191. }
  192. # ── A5: acl recover reaps dead-PID holds ────────────────────────
  193. $f5 = Join-Path $Root 'a5.txt'
  194. 'A5' | Set-Content -Encoding ASCII $f5
  195. $holderC = Start-Process -FilePath $pwsh -PassThru -WindowStyle Hidden `
  196. -ArgumentList @('-NoProfile','-Command','Start-Sleep 5')
  197. Stamp @{ denyRead = @($f5) } $holderC.Id
  198. $holderC.WaitForExit()
  199. $r = RExec @('--', $cmd, '/c', "type `"$f5`"")
  200. if ($r.exit -eq 0) { throw "A5: deny did not take effect. raw: $($r.raw)" }
  201. Run @('acl','recover')
  202. if (Has-SbAce $f5) {
  203. throw 'A5: deny ACE still present after recover (dead holder not reaped)'
  204. }
  205. $r = RExec @('--', $cmd, '/c', "type `"$f5`"")
  206. if ($r.exit -ne 0 -or $r.out -notmatch 'A5') {
  207. throw "A5: still denied after recover. raw: $($r.raw)"
  208. }
  209. Write-Host 'A5 ok: acl recover — orphan from dead holder restored'
  210. # ── A13: cross-holder mask widening (SbAce::max) ────────────────
  211. $f13 = Join-Path $Root 'a13.txt'
  212. 'A13' | Set-Content -Encoding ASCII $f13
  213. $hA = Start-Process -FilePath $cmd -PassThru -WindowStyle Hidden `
  214. -ArgumentList '/c','timeout','/t','120','/nobreak'
  215. $hB = Start-Process -FilePath $cmd -PassThru -WindowStyle Hidden `
  216. -ArgumentList '/c','timeout','/t','120','/nobreak'
  217. try {
  218. Stamp @{ denyWrite = @($f13) } $hA.Id
  219. $r = RExec @('--', $cmd, '/c', "type `"$f13`"")
  220. if ($r.exit -ne 0 -or $r.out -notmatch 'A13') {
  221. throw "A13 setup: child read under denyWrite-only failed. raw: $($r.raw)"
  222. }
  223. Stamp @{ denyRead = @($f13) } $hB.Id
  224. $r = RExec @('--', $cmd, '/c', "type `"$f13`"")
  225. if ($r.exit -eq 0) {
  226. throw "A13: stricter denyRead NOT applied (mask widening " +
  227. "ignored). raw: $($r.raw)"
  228. }
  229. Write-Host 'A13 ok: denyWrite then denyRead on same path → read denied'
  230. } finally {
  231. Stop-Process -Id $hA.Id -Force -ea SilentlyContinue
  232. Stop-Process -Id $hB.Id -Force -ea SilentlyContinue
  233. & $Exe acl recover 2>&1 | Out-Null
  234. }
  235. # ── A28: per-exec error after stamp → PerExecRestore Drop runs ──
  236. $f28 = Join-Path $Root 'a28.txt'
  237. 'A28-DATA' | Set-Content -Encoding ASCII $f28
  238. if (Has-SbAce $f28) { throw 'A28 pre: file already carries a sb-user ACE' }
  239. $r = RExec @('--deny-read', $f28, '--',
  240. 'C:\__srt_win_nonexistent__.exe')
  241. if ($r.exit -eq 0) {
  242. throw 'A28 setup: launch of a nonexistent exe SUCCEEDED?'
  243. }
  244. if ($r.raw -notmatch 'per-exec deny.*holder_pid=\d+') {
  245. throw "A28: per-exec deny diag missing — ACE did not commit " +
  246. "before the launch error. raw: $($r.raw)"
  247. }
  248. if (Has-SbAce $f28) {
  249. throw "A28: per-exec deny ACE LEAKED — sb-user ACE still " +
  250. "present after a post-stamp error. raw: $($r.raw)"
  251. }
  252. $rR = RExec @('--', $cmd, '/c', "type `"$f28`"")
  253. if ($rR.out -notmatch 'A28-DATA') {
  254. throw "A28: child without --deny-read still denied. raw: $($rR.raw)"
  255. }
  256. Write-Host 'A28 ok: per-exec error after stamp → Drop ran (no leaked ACE)'
  257. # ── A29: broker hard-killed mid-exec → recover reaps ────────────
  258. $f29 = Join-Path $Root 'a29.txt'
  259. 'A29-DATA' | Set-Content -Encoding ASCII $f29
  260. $exec29 = Start-Process -FilePath $Exe -PassThru -WindowStyle Hidden `
  261. -ArgumentList @('exec','--deny-read',$f29,'--',
  262. $cmd,'/c','ping -n 60 127.0.0.1 >nul')
  263. try {
  264. $deadline = [DateTime]::UtcNow.AddSeconds(15)
  265. while (-not (Has-SbAce $f29)) {
  266. if ([DateTime]::UtcNow -gt $deadline -or $exec29.HasExited) {
  267. throw "A29 setup: per-exec deny ACE never landed " +
  268. "(exec exited=$($exec29.HasExited))"
  269. }
  270. Start-Sleep -Milliseconds 100
  271. }
  272. Stop-Process -Id $exec29.Id -Force
  273. $exec29.WaitForExit()
  274. } finally {
  275. if (-not $exec29.HasExited) {
  276. Stop-Process -Id $exec29.Id -Force -ea SilentlyContinue
  277. }
  278. }
  279. if (-not (Has-SbAce $f29)) {
  280. throw 'A29 setup: ACE gone after kill — Drop ran (kill not hard enough)'
  281. }
  282. $rec29 = RunCapture @('acl','recover')
  283. if ($rec29.raw -notmatch 'pruned [1-9]\d* dead broker') {
  284. throw "A29: crash-recovery did not report the dead per-exec " +
  285. "holder. raw: $($rec29.raw)"
  286. }
  287. if (Has-SbAce $f29) {
  288. throw 'A29: per-exec deny ACE NOT reaped by recover after broker kill'
  289. }
  290. $rR = RExec @('--', $cmd, '/c', "type `"$f29`"")
  291. if ($rR.out -notmatch 'A29-DATA') {
  292. throw "A29: child still denied after reap. raw: $($rR.raw)"
  293. }
  294. Write-Host 'A29 ok: per-exec broker hard-killed → recover reaps + restores'
  295. # ── A30: hardlink guard — refuse any multi-link Deny target ─────
  296. # NTFS hardlinks share one security descriptor across distinct
  297. # canonical paths, but `ace_holders` is PATH-keyed. A Deny on
  298. # one alias is invisible to a holder of another — releasing it
  299. # would write the SHARED DACL back without the deny while the
  300. # other holder's child is still running. `ensure_ace` refuses
  301. # `links > 1` for ALL Deny callers (per-exec and session-level
  302. # `acl stamp` alike — no `refuse_escalation` distinction under
  303. # the additive-ACE model).
  304. $d30 = Join-Path $Root 'a30'
  305. New-Item -ItemType Directory -Path $d30 | Out-Null
  306. $f30 = Join-Path $d30 'orig.txt'
  307. $f30L = Join-Path $d30 'alias.txt'
  308. 'A30-DATA' | Set-Content -Encoding ASCII $f30
  309. New-Item -ItemType HardLink -Path $f30L -Target $f30 | Out-Null
  310. # (a) per-exec --deny-read on a hardlinked file → refused.
  311. $r = RExec @('--deny-read', $f30L, '--', $cmd, '/c', 'exit 0')
  312. if ($r.exit -eq 0) {
  313. throw ("A30(a): per-exec --deny-read on a hardlinked file " +
  314. "SUCCEEDED — links>1 gate did not fire. raw: $($r.raw)")
  315. }
  316. if ($r.raw -notmatch '(?i)deny refused.*has 2 hardlink') {
  317. throw "A30(a): expected hardlink refuse; got: $($r.raw)"
  318. }
  319. if (Has-SbAce $f30L) {
  320. throw 'A30(a): hardlinked file was stamped despite refuse'
  321. }
  322. # (b) session-level `acl stamp` on the original → ALSO refused.
  323. # (Same chokepoint; under the additive-ACE model session
  324. # stamps go through ensure_ace too.)
  325. $b30 = (ConvertTo-Json -Compress @{ denyWrite = @($f30) }) `
  326. | & $Exe acl stamp --holder-pid $PID `
  327. --sandbox-user-sid $sbSid 2>&1 | Out-String
  328. if ($LASTEXITCODE -eq 0) {
  329. throw ("A30(b): session acl stamp on a hardlinked file " +
  330. "SUCCEEDED — expected refuse. out: $b30")
  331. }
  332. if ($b30 -notmatch '(?i)deny refused.*has 2 hardlink') {
  333. throw "A30(b): expected hardlink refuse; got: $b30"
  334. }
  335. if (Has-SbAce $f30) {
  336. throw 'A30(b): original was stamped despite refuse'
  337. }
  338. # The grant on $Root inherits into $d30, so a child without a
  339. # deny can still read — confirms neither alias was stamped.
  340. $rR = RExec @('--', $cmd, '/c', "type `"$f30`"")
  341. if ($rR.out -notmatch 'A30-DATA') {
  342. throw "A30: child denied read — refuse leaked an ACE. raw: $($rR.raw)"
  343. }
  344. Write-Host ('A30 ok: hardlink guard — per-exec AND session ' +
  345. 'acl stamp refuse multi-link Deny targets')
  346. # ── A31: non-existent deny target → placeholder-create + stamp ──
  347. # `acl stamp` mkdirs each missing intermediate + creates an empty
  348. # leaf; leaf gets the full Deny mask, intermediates get an
  349. # object-only deny-DELETE (so rename/rmdir of an intermediate is
  350. # blocked too). Placeholders are PERMANENT (leave-in-place):
  351. # `acl restore` strips the ACEs but never deletes the file/dir.
  352. $leaf31 = Join-Path $Root 'a31\secrets\token'
  353. if (Test-Path (Join-Path $Root 'a31')) {
  354. throw 'A31 pre: a31 subtree already exists'
  355. }
  356. Stamp @{ denyRead = @($leaf31) }
  357. # (a) placeholder chain exists; leaf is an empty file with a
  358. # sb-user Deny ACE; child `type` denied.
  359. if (-not (Test-Path $leaf31 -PathType Leaf)) {
  360. throw 'A31(a): placeholder leaf not created'
  361. }
  362. if (-not (Has-SbAce $leaf31)) {
  363. throw 'A31(a): placeholder leaf has no sb-user Deny ACE'
  364. }
  365. $r = RExec @('--', $cmd, '/c', "type `"$leaf31`"")
  366. if ($r.exit -eq 0) {
  367. throw "A31(a): child read placeholder leaf. raw: $($r.raw)"
  368. }
  369. # (b) child cannot delete/rename the placeholder chain (full
  370. # Deny on leaf, deny-DELETE on intermediates, DenyFdc on
  371. # parents).
  372. $r = RExec @('--', $cmd, '/c', "del /f `"$leaf31`"")
  373. if (-not (Test-Path $leaf31)) {
  374. throw "A31(b): child deleted placeholder leaf. raw: $($r.raw)"
  375. }
  376. $mid31 = Join-Path $Root 'a31\secrets'
  377. $r = RExec @('--', $cmd, '/c',
  378. "ren `"$mid31`" secrets2 && mkdir `"$mid31`"")
  379. if (Test-Path (Join-Path $Root 'a31\secrets2')) {
  380. throw ("A31(b): child renamed placeholder intermediate. " +
  381. "raw: $($r.raw)")
  382. }
  383. # (c) restore strips the ACEs; placeholder chain LEFT IN PLACE
  384. # (leave-in-place — never delete what the user may have
  385. # written into).
  386. Restore $PID
  387. if ((Has-SbAce $leaf31) -or (Has-SbAce $mid31)) {
  388. throw 'A31(c): placeholder chain still has sb-user ACE after restore'
  389. }
  390. if (-not (Test-Path $leaf31 -PathType Leaf)) {
  391. throw ('A31(c): placeholder leaf gone after restore ' +
  392. '(should be left in place)')
  393. }
  394. Write-Host ('A31 ok: non-existent deny target → placeholder ' +
  395. 'chain created+stamped, delete/rename blocked, ' +
  396. 'ACEs stripped and chain left in place on restore')
  397. # (d) trailing `\` ⇒ leaf materialized as a DIRECTORY.
  398. $dir31 = Join-Path $Root 'a31d\hooks'
  399. Stamp @{ denyRead = @($dir31 + '\') }
  400. if (-not (Test-Path $dir31 -PathType Container)) {
  401. throw 'A31(d): trailing-\ deny target not created as directory'
  402. }
  403. if (-not (Has-SbAce $dir31)) {
  404. throw 'A31(d): dir placeholder leaf has no sb-user Deny ACE'
  405. }
  406. Restore $PID
  407. Write-Host 'A31(d) ok: trailing-\ ⇒ directory placeholder'
  408. # (e) broker-unwritable deny target soft-drops (exit 0) — the
  409. # sandbox cannot create there either. Constructed: deny the
  410. # REAL user create under $Root\a31e so `create_placeholder_
  411. # chain` hits PermissionDenied even on the elevated CI
  412. # runner. `Stamp` throws on nonzero exit, so reaching the
  413. # next line is the assertion.
  414. $unw = Join-Path $Root 'a31e'
  415. New-Item -ItemType Directory $unw | Out-Null
  416. $me = [System.Security.Principal.WindowsIdentity]::GetCurrent().User
  417. $rule = New-Object System.Security.AccessControl.FileSystemAccessRule(
  418. $me, 'CreateFiles,CreateDirectories', 'Deny')
  419. $a = Get-Acl $unw; $a.AddAccessRule($rule); Set-Acl $unw $a
  420. Stamp @{ denyRead = @((Join-Path $unw 'sub\token')) }
  421. if (Test-Path (Join-Path $unw 'sub')) {
  422. throw 'A31(e): placeholder created under broker-unwritable dir'
  423. }
  424. $a.RemoveAccessRule($rule) | Out-Null; Set-Acl $unw $a
  425. Write-Host 'A31(e) ok: broker-unwritable deny target soft-drops'
  426. }
  427. finally {
  428. & $Exe acl revoke --holder-pid $PID --sandbox-user-sid $sbSid 2>&1 | Out-Null
  429. & $Exe acl restore --holder-pid $PID --sandbox-user-sid $sbSid 2>&1 | Out-Null
  430. & $Exe acl recover 2>&1 | Out-Null
  431. if (Test-Path $Root) { Remove-Item -Recurse -Force $Root -ea SilentlyContinue }
  432. & $Exe uninstall --sublayer-guid $Sublayer 2>&1 | Out-Null
  433. }
  434. Write-Host 'smoke-aces: PASS (A2/A2(reg)/A4/A5/A13/A28/A29/A30/A31)'