Skip to content

learn: follow-ups from the #209 review - #220

Merged
congwang-mk merged 3 commits into
mainfrom
learn-proc-self-fixups
Sep 10, 2026
Merged

learn: follow-ups from the #209 review#220
congwang-mk merged 3 commits into
mainfrom
learn-proc-self-fixups

Conversation

@congwang-mk

Copy link
Copy Markdown
Contributor

Follow-ups to #209 that were left out of that PR as minor.

  • canonicalize_or_keep rewrote /proc/self to /proc/<pid> but only mapped results back when they carried a trailing /<pid>/ prefix, so an open of /proc/self itself came out as a numeric-pid path and was dropped as junk. Both sides now use Path::strip_prefix, so the bare directory and its entries round-trip the same way, and unrelated names that merely start with /proc/self no longer match.
  • canonicalize_parent_or_keep still resolved against the supervisor's own /proc/self; it now goes through the same pid-aware helper, so rename and unlink targets under /proc/self/cwd land on the workload's process.
  • The /proc/self/exe test only asserted that the alias was absent, which a dropped read would also satisfy. It now requires the resolved interpreter path.
  • The three / guards in learn shared one rule spelled two ways; they now call a single is_fs_root helper. This only affects sandlock learn output, not run enforcement.
  • docs/learn.md said a warning is printed for direct writes to Protected or Guarded paths; the code prints a NOTE and still records the path.

Tests: cargo test -p sandlock-cli --test learn_test -- --test-threads=4 passes (40/40), including a new test_proc_self_bare_preserved that fails on main.

canonicalize_or_keep rewrote "/proc/self" to "/proc/<pid>" but only
mapped results back when they carried a trailing "/<pid>/" prefix, so an
open of /proc/self itself came out as a numeric-pid path and was dropped
as junk. Use Path::strip_prefix on both sides so the bare directory and
its entries round-trip the same way, and stop matching unrelated names
that merely start with "/proc/self".

canonicalize_parent_or_keep still resolved against the supervisor's own
/proc/self, so rename or unlink targets under /proc/self/cwd landed on
the wrong process. Route it through the same pid-aware helper.

The exe test only asserted that /proc/self/exe was absent, which a
dropped read would also satisfy; it now checks the resolved interpreter
path is present.

Signed-off-by: Cong Wang <cwang@multikernel.io>
The direct-write, ancestor-walk, and read filters each spelled the "/"
guard differently (byte compare vs Path compare), which hides that they
are the same rule.

Signed-off-by: Cong Wang <cwang@multikernel.io>
The paragraph said a warning is printed for direct writes to Protected
or Guarded paths, but collapse_write_paths prints a NOTE and still
records the path. Also drop the trailing whitespace.

Signed-off-by: Cong Wang <cwang@multikernel.io>
@ghazariann

ghazariann commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Lgtm

@congwang-mk
congwang-mk merged commit fd8426f into main Sep 10, 2026
17 checks passed
@congwang-mk
congwang-mk deleted the learn-proc-self-fixups branch September 10, 2026 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants