fix(file): reject dangling-symlink writes outside workspace - #90
Closed
cursor[bot] wants to merge 1 commit into
Closed
cursor[bot] wants to merge 1 commit into
cursor[bot] wants to merge 1 commit into
Conversation
write_file treated a dangling workspace symlink as "ancestor is in
bounds" and fopen("w") followed it onto the host. Camera capture used
the same ancestor walk. Open with O_NOFOLLOW and fail closed on
unresolvable links.
Co-authored-by: esadrianno <esadrianno@gmail.com>
2 tasks
4 tasks
Collaborator
|
Superseded by #94 (já em |
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.
Bug and impact
With
workspace_only(on by default),write_filewalked to the first existing ancestor whenrealpathfailed. A dangling symlink in the workspace therefore passed the prefix check, andfopen("w")followed it and created or truncated a host file outside the workspace.Camera capture used the same ancestor walk for caller-supplied JPEG paths.
Concrete trigger (main
d367477)/tmp/ws, sandbox/workspace_only on.python3 -c 'import os; os.symlink("/tmp/sc_pwned","leak")'(allowlist skips this; same first step as fix(sandbox): Landlock + relative-token block for workspace FS escapes #74).write_filepath=/tmp/ws/leakcontent=pwned./tmp/sc_pwnedis created on the host.read_fileof an existing outside symlink is already denied viarealpath.Same walk applies to
camera_capturepath=.Distinctness
cat leakof a relative symlink; Landlock in fix(sandbox): Landlock FS bound plus workspace_only defense-in-depth #89 does not bound the file tool, which runs in the agent process).auth_tokens.json).sandbox_execonly).Fix
write_fileopens withO_NOFOLLOWwhenworkspace_onlyis set so a TOCTOU swap cannot follow a link.path_inside_workspaceuses the same dangling-symlink deny.Test plan
CI=true make test_file—test_file_write_dangling_symlink_rejectedCI=true make test_hardware_camera—test_output_dangling_symlink_rejectedCI=true make test_shellDoes not re-open #66/#74/#76/#82 (still present on main; tracked by #89).