mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 21:36:40 -10:00
devvm agent import and save checked each path they wrote in the store by path (storeGuard), then wrote by path (os.MkdirAll, state.WriteFileMode), so a link swapped into the store between the check and the write could lead the write elsewhere. They still check every path first, so a link fails the command, naming it, before the store changes; they now write only through the agent's folder in the store opened from devvm's config folder as a root (makeStoreDir, which makes it and the folders on its way through the config folder as a root, then openStoreDir), with state.WriteFileIn, a whole-file write through an os.Root. An import copied whatever an agent's folder held, one file at most 128 MiB, so a VM whose project folder is inside an agent's folder could fill the store that every VM with the agent mounts. Each agent's folder now gets agent save's bounds in all, 20,000 files and folders and 128 MiB: the walk stops at 20,000 (errFolderTooMany), the sizes as listed are counted (hostAgent.tooMuch), and a folder over either fails the import before anything is written, naming the folder and what to do (agent_import_too_much); the files' reads share the 128 MiB (h.read), so files that grew since the listing fail too. Before it reads anything, the import warns of each VM whose project folder is inside an agent's folder or holds it (agent_import_project_inside). A project folder that holds an agent's folder, such as ~/.pi for pi's ~/.pi/agent, let its VM put a link in the agent folder's place, which the import followed, copying whatever it led to, such as the home folder's files, into the store: the import now resolves the folder's path one link at a time (linkHops), leaves it out with agent_import_link_via_vm when a link in a VM's project folder leads it out of that folder (throughVM, shared with the link follower), its login with it (pi's auth.json), and reads the folder where the path led. Every agent's login file but Claude Code's ~/.claude.json, which was already a capped, regular-file read, was os.ReadFile by path, so a VM whose project folder held it could swap in a link to another file, a FIFO or an endless file between the check and the read: its path is now resolved once (linkHops), left out when a link in a VM's project folder leads it out of that folder (throughVM), and read where it led, through its folder opened with no link and never resolved again (openPhysical), opened without following one, a regular file of at most 128 MiB (claudeHostLogin), so a folder swapped for a link since fails the read. Tests: TestWriteFileIn, TestAgentImportTooMuch, TestAgentImportReadBudget, TestAgentImportProjectInside, TestAgentImportProjectHolds (a folder and a login led elsewhere), TestAgentImportLoginNoFollow, TestStoreOpsRefuseLinks (makeStoreDir). Co-Authored-By: Claude Opus 5.5 <[email protected]>