Repository navigation
feat: engage the macOS helper sandbox before framework code runs - #55962
claude[bot] wants to merge 4 commits into
Conversation
Link the non-MAS helper apps against Chromium's libaperitif.dylib, which starts the seatbelt sandbox from its own static initializer, and remove the SeatbeltExecServer block from the helper's main(). libaperitif is linked before Electron Framework, so the sandbox is on before any code from the framework or from system libraries other than libSystem runs. - Link the framework's shared library (`+link_nested`) after libaperitif, since `-framework` entries are placed before all shared libraries by the Apple link rule. - Rewrite libaperitif's install name, which assumes Chrome's bundle layout, to the framework's Libraries directory, and bundle the dylib there. - Verify that each helper loads exactly libaperitif, Electron Framework and libSystem, in that order, as Chrome does. - Add libaperitif.dylib to the macOS dist zip manifests. MAS builds are unchanged. Refs #54663 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NayLZiGwUtmxxg3gkkqg5P
|
Release note looks good now. |
|
CI note on the What fails: one test, Why it isn't this PR:
All other macOS jobs are green. That covers Generated by Claude Code |
Address review feedback on the Apéritif helpers change: - Replace the C++ launcher with a plain C entry point (shell/app/electron_main_mac.c) for the main and helper executables. It checks that Apéritif initialized and calls a new framework export, ElectronExecutableMain(), which now holds the run-as-node and helper --type handling. - Build Electron's own libelectron_aperitif.dylib with an Electron install name instead of rewriting Chromium's libaperitif. Its static initializer registers PartitionAlloc's early malloc zone once, repairs stdio, and then engages the Seatbelt sandbox using Chromium's seatbelt code. Executables link it before Electron Framework via +link_nested. - MAS builds link the library too, for early malloc zone registration, but without Seatbelt. - Verify that the main and helper executables load exactly libelectron_aperitif, Electron Framework and libSystem, in that order, and that the library links only libSystem and libsandbox. - Add a spec that launches a sandboxed window with DYLD_PRINT_INITIALIZERS=1 and checks that only libSystem initializes before libelectron_aperitif in the browser and renderer processes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
CI failure on 64d33b0: The only failure (1 failed, 1841 passed): Line 2655 is the first Why I don't think this PR causes it:
No code change is needed for this PR. Re-running the shard should clear it. Generated by Claude Code |
|
CI triage for run 44778206912 (head 64d33b0): the two test failures look unrelated to this PR. windows-x64 / test (win, 1) (job): one failure out of 2588 passing tests. The tests just before it in the same block ran very slowly too: macos-arm64 / test (mas, 1) (job): Why I think they're unrelated:
The shards that exercise this PR's changes passed or are still running: macos-arm64 (darwin, 1) and macos-x64 (mas, 1) passed, and macos-arm64 (darwin, 2), macos-x64 (darwin, 1) and windows-arm64 (win, 2) were still running when I wrote this. A rerun of the two failed shards should be enough. Generated by Claude Code |
…licy GPU and network service helpers compile their Seatbelt policy in libelectron_aperitif's initializer, before PartitionAlloc is installed. The compiler's temporary buffers therefore come from the system malloc zone, which keeps the freed pages resident. Call malloc_zone_pressure_relief() after the sandbox is engaged to return them, which recovers about 0.3 MiB in each of those processes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Can this be changed to Fixes instead of |
Requested by John Kleinschmidt · Slack thread
Description of Change
Fixes #54663.
On macOS, helper processes (renderers, GPU, utility) used to engage the sandbox from
main(). By the timemain()runs, dyld has already loaded Electron Framework and every system library it links, and run all of their static initializers, unsandboxed. In a renderer, which handles untrusted web content, anything those initializers acquire (open files, Mach ports, connections to system services) stays available after the sandbox is on.This change adopts the layout Chromium moved to in crbug.com/40794783: the sandbox is now engaged before any code other than libSystem runs.
libelectron_aperitif.dylib. Bundled in the framework'sLibrariesdirectory. Its static initializer registers PartitionAlloc's early malloc zone, repairs closed stdio file descriptors, and then, in helpers launched with seatbelt arguments, engages the sandbox using Chromium's seatbelt code. Mac App Store builds use it only for the malloc zone and stdio steps.shell/app/electron_main_mac.c, which links onlylibelectron_aperitif, Electron Framework and libSystem, in that order, so the library initializes first. The run-as-node and helper--typehandling moved from the old C++ launcher into the framework (ElectronExecutableMain()).EarlyMallocZoneRegistration(), which PartitionAlloc expects to run before the framework's allocator initializes. It now runs once in every process, as it does in Chrome.libelectron_aperitiflinks only libSystem and libsandbox. A dependency added there later would run before the sandbox, so it fails the build.DYLD_PRINT_INITIALIZERS=1and checks thatlibelectron_aperitifinitializes before everything except libSystem in the browser and in a sandboxed renderer.Size and performance. The helper executables no longer carry their own copy of libc++ and the seatbelt code, so each shrinks from about 214 KB to about 27 KB, roughly 0.7 MB less per architecture after adding the new dylib. Chromium's startup and memory gains from this project came from loading its framework at launch instead of with
dlopen(); Electron's helpers already did that, and startup time and browser and renderer memory are unchanged. The GPU process and network service each use about 0.7 MiB more: they compile their sandbox policy before PartitionAlloc is installed, so the policy compiler's temporary buffers come from system malloc, which keeps one freed block resident. The library returns the rest of those pages after the sandbox is engaged.App developers who sign or package Electron themselves should make sure the new dylib in
Electron Framework.framework/Libraries/is signed along with the rest of the framework.Checklist
npm testpasses🤖 Generated with Claude Code
https://claude.ai/code/session_01NayLZiGwUtmxxg3gkkqg5P
Release Notes
Notes: Shrank macOS helper executables and sandboxed them before framework code runs.