Repository navigation
Keep build resources in stable, self-reclaiming directories - #1304
Merged
Merged
Conversation
Lets consumers name and verify extracted copies without hashing at run time.
Build resources are shared per build and user under a stable name, verified before reuse, and session directories are locked so that whatever a dead process left behind can be reclaimed by the next one.
The out-of-process helper now gets the blob through an unlinked shared memory object, so local sessions no longer write frida-agent.dylib to disk.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Every Frida session on macOS leaves a
frida-<random>directory with an extracted agent and helper (about 68 MB) in the cache directory whenever its process is killed, calls_exit, or exits without shutting Frida down, and nothing ever reclaims them. A machine running tests in a loop accumulated 142 GB that way in a day. Helpers andidundinstances whose client died keep their directories in use on top of that.This makes build resources live in one directory per build and user, and lets the next process clean up after a dead one.
Design
<base>/frida-<version>-<id>, where the id is a SHA-256 over the user id plus the names and digests of the resources that may go in that directory. The digests are computed at build time by the resource compiler, so nothing is hashed when a session starts..lock, whose mtime records the last use. Session directories (user blobs and the like) keep their random names, hold an exclusive lock for their owner's lifetime, and are now emptied completely on destroy.frida-<32 hex>directory, which has no lock, after three days./tmpget the same checks, and a failed check falls back to a random session directory. Shared bases that are not sticky never get stable names.always_use ()now names a checked root that holds resource and session directories, instead of one flat directory wiped at start.idundand injected agents do not take the lock; removing their files under them is harmless on Unix, and refused on Windows.The last commit is separable: it implements the missing half of
DarwinHelperProcess.try_mmap (), which has returnednullsince in-memory injection was added. The client hands the blob to the helper as an unlinked shared memory object over the descriptor passing the helper already supports, and the helper maps it the way frida-server does. A local macOS session then writes nofrida-agent.dylibat all; onlyfrida-helperandidundremain on disk. The system session still writes the agent, since it loads it in-process through dyld.Tested (macOS, arm64)
_exitand a quarter killed with SIGKILL at a random point: exactly one resource directory per set, no temporaries left, contents matching the build digests, no helper left running. 200 sessions of 17.27.5 left 85 directories, 4.4 GB./Systemincluding the two new tests,/Injectorand/HostSession(Local, Service, Darwin with ChildGating, ExitMonitor and UnwindSitter): 39 ok.Not verified
LockFileExlocking), FreeBSD, QNX and Prospero (session directory locking and reclamation): built by CI on this pull request, never run./System/ResourceDirectorytests pass in CI on Linux x86_64 and on Windows x86 and x86_64, which exercises the Windows locking; reclamation has not been exercised on either..lockmay fail, in which case nothing would be reclaimed there.Where to look first
ResourceDirectory.claim (): the retry loop that checks the.lockinode after waiting for the lock, which is the race with the reclaimer.maybe_reclaim (): it touches only the four name patterns and only entries owned by the user, and renames before deleting.root_directoryandis_trusted_root ().MAP_SHAREDin the helper (macOS refusesMAP_PRIVATEfor shared memory).