sandlock icon indicating copy to clipboard operation
sandlock copied to clipboard

run: write grants under /proc/self only cover the first process

Open congwang-mk opened this issue 2 months ago • 0 comments

Write-side counterpart of #218. A -w /proc/self/X entry becomes a Landlock rule bound to the first pid's inode, so forked children are denied.

sandlock run -r /usr -r /lib -r /lib64 -r /bin -r /etc -w /proc/self/comm -- \
  sh -c "sh -c 'echo x > /proc/self/comm'; true"
sh: 1: cannot create /proc/self/comm: Permission denied

The first process succeeds. Affects forked workers that write oom_score_adj or task/<tid>/comm (the GPU example in docs/cli.md grants -w /proc/self/task).

Proposed fix: serve policy-listed writes on behalf of the caller from procfs::handle_proc_open, opened inside /proc/<tgid> with openat2(RESOLVE_BENEATH | RESOLVE_NO_SYMLINKS). Unlike reads, keep writes policy-gated, and always refuse mem, attr/*, uid_map, gid_map, setgroups, projid_map: the injected fd carries the supervisor's credentials, and procfs checks some of these against the opener.

congwang-mk avatar Sep 19 '26 23:09 congwang-mk