Repository navigation
fix(sandbox): deny path truncate on Landlock ABI below 3 - #143
Draft
cursor[bot] wants to merge 1 commit into
Draft
cursor[bot] wants to merge 1 commit into
cursor[bot] wants to merge 1 commit into
Conversation
JetPack 6.2 (kernel 5.15) is Landlock ABI 1, which cannot gate truncate(2). A sandboxed command could wipe a user-owned file outside the workspace even though open for write returned EACCES. Deny that path syscall with seccomp. ftruncate and open(O_TRUNC) stay available so workspace writes still work. Co-authored-by: esadrianno <esadrianno@gmail.com>
This branch has not been deployed
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
On Landlock ABI 1 and 2, a sandboxed shell can wipe a user-owned file outside the workspace.
openfor write is still denied (EACCES), buttruncate(2)succeeds and the file size becomes 0.ShellClaw's primary device is a Jetson Orin Nano on JetPack 6.2, which ships kernel 5.15 (Landlock ABI 1). A command with no
/in its text, such aspython3building the path withchr(47), passes the allowlist and reaches that syscall. The same shape was already shown to chmod host files. This one deletes the bytes.Root cause
LANDLOCK_ACCESS_FS_TRUNCATEexists only from ABI 3 (Linux 6.2).landlock_handled_fscorrectly omits that bit on older kernels, because setting it makescreate_rulesetfail. A right that is not inhandled_access_fsstays allowed.open(O_TRUNC)is still gated byWRITE_FILE. The path form oftruncate(2)is not.Fix
After
restrict_self, if the ABI is below 3, install a seccomp filter that returnsEPERMfortruncate(2)(andtruncate64where that syscall exists).ftruncate(2)stays allowed: it needs a writable descriptor, andWRITE_FILEalready rejects opening a host file. Shell redirection usesopen(O_TRUNC), so workspace writes keep working.On ABI 3 and newer the existing Landlock bit still applies, and the filter is not installed.
os.truncate(path)and thetruncateutility inside the workspace returnEPERMon JetPack. Creating or rewriting a file withopendoes not.Validation
A ruleset built with ABI 1 rights on this host (kernel Landlock ABI 6) reproduced the wipe:
open(O_WRONLY|O_TRUNC)returnedEACCESandtruncateleft the file at 0 bytes.make test_sandboxthen failed on the new case (WEXITSTATUS=5, size 22 to 0). After the filter, the same case passes:truncatereturnsEPERM, the host file keeps its size, a workspaceopen(O_TRUNC)succeeds, andftruncateon that descriptor succeeds. The rest oftest_sandboxpassed.