Repository navigation
Windows: every confined command dies with 0xC0000142 in workspace-write (default DACL names a capability SID the token does not carry) #8775
Replies: 1 comment
Source-level patch and verification (attaching here because PRs are closed)
Two candidate one-line fixes, both verified against the shipped runnerMethod: byte-patch a copy of
Why
|
Uh oh!
There was an error while loading. Please reload this page.
English
Summary
On Windows 11 (build 22635.5305), with file policy set to
workspace-write, everyconfined command fails immediately with exit code
3221225794(0xC0000142,STATUS_DLL_INIT_FAILED) and no stdout/stderr.read-onlyworks.danger-full-accessworks. The bundled
diagnose-windows-sandbox-aclskill does not apply: this is not afile-permission problem (see "ACLs are exonerated" below).
Affected package:
@deepseek-ai/dsh-sandbox-windows-acl@0.2.0-rc.2(DSH desktop profile).It is executable-independent:
cmd.exe,powershell.exe(5.1) and MSIXpwsh7.6.6 all die.Reproduction
Two independent ways, neither depending on the caller's own confinement:
app.asar):Result: exit
-1073741502(0xC0000142), no output.With
--mode read-only: exit0,helloprinted.AclSandbox(imported straight out ofapp.asar,run with
ELECTRON_RUN_AS_NODE=1), varying only the SID that enters the token:S-1-5-32-545BUILTIN\UsersS-1-5-11Authenticated UsersS-1-5-21-<machine>-1011(a local group)S-1-5-32-546BUILTIN\Guests0xC0000142S-1-5-21-1111111111-2222222222-3333333333-1500(nonexistent)0xC0000142S-1-4-…capability SID (the real workspace/temp write SID)0xC00001420xC0000142All rows use
manageDacls: false(zero DACL/label edits), no TMP/TEMP rewrite,unchanged cwd — so directory grants, integrity labels and the temp directory are
all out of scope. Rows 7/8 isolate the trigger to the token default DACL.
NT Kernel Logger, keyword0x7= process|thread|img,tracerpt→ CSV, filtered by child PID):cmd.exepowershell.exe5.1The child always dies exactly where the first CRT DLL of its dependency chain
(
ucrtbase.dll, resp.msvcrt.dll) would be initialized.Current behavior
workspace-write: exit3221225794/0xC0000142, empty output, for every executable.read-only: works (and correctly denies writes inside the workspace, so confinementitself is functional).
Expected behavior
workspace-writespawns the confined child, the command runs, writes outside theworkspace are denied.
Environment
ProductNamestill reportsWindows 10 Pro, the known legacy value). Note the source comment indsh-sandbox-windows-aclstates "verified on Win11 26200".desktop.pwsh: MSIX/Store build 7.6.6 (C:\Program Files\WindowsApps\Microsoft.PowerShell_7.6.6.0_x64__8wekyb3d8bbwe\pwsh.exe,reached through the app execution alias). Irrelevant to the failure —
cmd.exeand5.1 fail identically.
SeDebugPrivilegeenabled.Root cause
@deepseek-ai/dsh-sandbox-windows-acl/lib/types-Cl_DXjhk.js(shipped bundle):read-onlyresolves to?? worldSid— EVERYONE, an enabled group of the childtoken — and works.
workspace-writeresolves to the capability SID (S-1-4-…, created byworkspaceWriteSid()/tempWriteSid()), which the token does not carry as a group.Failure chain: the ACE is merged into
TokenDefaultDacl; every kernel object the childcreates without an explicit security descriptor inherits that DACL; the normal access
check (pass 1, evaluated against the token's own SIDs) can never be satisfied by a
capability SID, while the write-restricted pass 2 check only sees the restricting list.
With the two checks intersected, the child cannot write to objects it just created, so
the CRT's initialization fails, its
DllMainreturns FALSE, and the process dies withSTATUS_DLL_INIT_FAILED. The doc comment above the call explains the intent (lettingnewly created pipes pass the pass-2 check) — but that reasoning only covers pass 2 and
misses pass 1;
worldSidsatisfies both, which is exactly whyread-onlyhas alwaysbeen healthy.
Suggested fix
A/B verification of that one-line change
An
app.asarcopy was byte-patched with an equal-length replacement (entry offsetspreserved) and driven through the production runner in
workspace-write(including the real directory grants and the TMP/TEMP rewrite):
cmd.exepowershell.exe5.1pwsh7.6.60xC00001420xC00001420xC0000142Out of scope (already excluded)
manageDacls: falsescenario reproduces withzero ACL/label changes. Workspace ACLs were also confirmed writable/owned correctly.
pwshPath:cmd.exefails identically, sopwshPathconfig or anMSI PowerShell install changes nothing.
dsh-sandbox-local's Windows backend is thisrunner.
中文
概述
Windows 11(build 22635.5305)上,文件策略为
workspace-write时,每一条受限命令都立刻以退出码
3221225794(0xC0000142,STATUS_DLL_INIT_FAILED)失败,且没有任何stdout/stderr。
read-only正常,danger-full-access正常。自带的diagnose-windows-sandbox-acl技能不适用:这不是文件权限问题(见下文"已排除 ACL")。受影响包:
@deepseek-ai/dsh-sandbox-windows-acl@0.2.0-rc.2(DSH desktop profile)。与可执行文件无关:
cmd.exe、powershell.exe5.1、MSIXpwsh7.6.6 全部一样失败。复现
两种方式,都不依赖调用方自身的受限状态:
app.asar内):结果:退出码
-1073741502(0xC0000142),无输出。改成
--mode read-only:退出码0,正常打印hello。用
AclSandbox(直接从app.asarimport,ELECTRON_RUN_AS_NODE=1运行)做参数化二分,只改变进入令牌的那一个 SID:见上表 1–8。
全部场景使用
manageDacls: false(零 DACL/标签改动)、不重写 TMP/TEMP、cwd 不变,因此目录授权、完整性标签、临时目录都被排除。第 7/8 行把触发点定位到
令牌默认 DACL。
镜像加载跟踪(
NT Kernel Logger,关键字0x7,tracerpt转 CSV 后按子进程 PID 过滤):见上表。子进程总是恰好死在其依赖链里第一个 CRT DLL(
ucrtbase.dll或msvcrt.dll)初始化的位置。当前行为
workspace-write:退出码3221225794/0xC0000142,输出为空,任何可执行文件都一样。read-only:正常(并且正确拒绝了工作区内的写入,说明约束本身是可用的)。预期行为
workspace-write能正常启动受限子进程并执行命令,工作区之外的写入被拒绝。环境
ProductName仍为Windows 10 Pro,属已知遗留值)。注意dsh-sandbox-windows-acl源码注释声明"verified on Win11 26200"。
desktop。pwsh:Store/MSIX 版 7.6.6(经 App Execution Alias 命中)。与本次故障无关——cmd.exe与 5.1 表现完全相同。SeDebugPrivilege已启用。根因
@deepseek-ai/dsh-sandbox-windows-acl/lib/types-Cl_DXjhk.js(随包发布版本,约 1293 行,AclSandbox.init()内):read-only取到?? worldSid—— EVERYONE,是子令牌自身携带的启用组 —— 因此正常。workspace-write取到能力 SID(S-1-4-…,由workspaceWriteSid()/tempWriteSid()派生),而令牌并不把它作为组携带。失败链条:该 ACE 被并入
TokenDefaultDacl;子进程创建的、未显式指定安全描述符的内核对象都会继承这个默认 DACL;普通检查(pass 1,用令牌自身的 SID 判定)永远无法被能力 SID 满足,
而 write-restricted 的 pass 2 检查只看 restricting 列表。两次检查取交集后,子进程
无法写入自己刚创建的对象,于是 CRT 初始化失败、
DllMain返回 FALSE,进程以STATUS_DLL_INIT_FAILED死亡。该调用上方的注释说明了动机(让新建管道通过 pass-2 检查),但那份推理只覆盖了 pass 2,漏掉了 pass 1;
worldSid能同时满足两次检查——这正是read-only一直健康的原因。建议修复
该一行改动的 A/B 验证
把
app.asar复制一份并做等长字节替换(保持 asar 条目偏移不变),再用生产同款 runner 在
workspace-write下运行(含真实目录授权与 TMP/TEMP 重写):cmd.exepowershell.exe5.1pwsh7.6.60xC00001420xC00001420xC0000142已排除项
manageDacls: false场景在零 ACL/标签改动下即可复现;工作区 ACL 的所有权与可写性也已确认正常。
pwshPath的问题:cmd.exe表现完全相同,所以改pwshPath或装 MSI 版 PowerShell 都不起作用。dsh-sandbox-local的 Windows 后端就是这个 runner。All reactions