fix: include character device files in policy group resolution#218
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical bug in the Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
`add_fs_capability()` gated non-directory paths on `path.is_file()`. Rust's `Path::is_file()` returns false for character devices, so /dev/urandom, /dev/null, etc. were silently dropped from the capability set despite being listed in policy groups. Align with FsCapability::new_file(), which already accepts any non-directory path since always-further#138. Signed-off-by: Pierre Schmitz <[email protected]>
3342444 to
8dc16ff
Compare
There was a problem hiding this comment.
Code Review
This pull request effectively addresses the issue where character device files were not being correctly included in policy group resolution due to an incorrect is_file() check. The change to add_fs_capability to treat all non-directory paths as files, aligning with FsCapability::new_file(), is a precise and correct fix. The addition of dedicated tests for character device files significantly improves the robustness of the policy resolver. The changes are well-reasoned and thoroughly tested.
Summary
add_fs_capability()in the CLI policy resolver gated non-directory paths onpath.is_file(). Rust'sPath::is_file()returnsfalsefor character devices, so device files listed in policy groups (/dev/urandom,/dev/null,/dev/zero,/dev/random,/dev/full,/dev/tty,/dev/console) were silently dropped from the capability set.This is the CLI-side counterpart to #138, which fixed the same
is_file()check in the library'sFsCapability::new_file(). The library fix was necessary but insufficient — the CLI policy resolver dropped device paths before they ever reached the library.Reproduction
Bun (which Claude Code and opencode are built on) segfaults at
0xBBADBEEF:strace shows the cause —
/dev/urandomis blocked by Landlock, and Bun crashes immediately after:Bun uses
open("/dev/urandom")rather than thegetrandom(2)syscall, so Landlock enforcement on the device file path applies.Fix
Changed the
else if path.is_file()branch toelse, matching the library'sFsCapability::new_file()which rejects only directories. After the fix, the verbose capability list shows 31 system/group paths (was 24 — the 7 missing were all character devices).Test plan
test_resolve_character_device_files— verifies device files in a policy group are resolved into capabilitiestest_embedded_policy_includes_device_files— verifies the realsystem_read_linuxgroup includes/dev/urandom,/dev/null,/dev/zero,/dev/randomcargo clippy --workspace --all-targets --all-features -- -D warnings -D clippy::unwrap_usedpassescargo fmt --all -- --checkpassescargo test --workspacepasses (one pre-existing flaky failure intest_check_sensitive_pathunrelated to this change)nono run --profile claude-code --allow-cwd -- claude -vsucceedsFixes #154 (Bun segfault component — the
/$bunfsvirtual path issue is separate)