Skip to content

[BUG] rm -r of a symlink that points at a direct-bind root deletes the bound host directory #385

Open

Description

@strandly-the-agent

Checks

  • I have updated to the latest minor and patch version of Strands Shell (built from main dbb6189)
  • I have checked the documentation and this is not expected behavior
  • I have searched issues and there are no duplicates of my issue

Binding

Rust

Strands Shell Version

main @ dbb6189 (Cargo version 0.0.0)

Language Runtime Version

Rust 1.100.0

Operating System

Debian GNU/Linux 12 (aarch64)

Installation Method

built from source

Steps to Reproduce

mkdir -p /tmp/ia/d && echo keep > /tmp/ia/d/keep && echo top > /tmp/ia/top
printf '[[bind]]\nmode = "direct"\nsource = "/tmp/ia"\ndestination = "/b"\n' > /tmp/ia.toml
strands-shell --config /tmp/ia.toml -c 'ln -s /b /tmp/lb; test -L /tmp/lb; echo $?; rm -r /tmp/lb; echo $?; readlink /tmp/lb'
ls /tmp/ia

File-bind variant (source = "/tmp/ib/hf", destination = "/hf"): ln -s /hf /tmp/lhf; rm /tmp/lhf.

Expected Behavior

As in bash: test -L is 0, rm -r /tmp/lb removes only the link, and /tmp/ia on the host is untouched.

Actual Behavior

test -L prints 1. rm -r /tmp/lb exits 0, the link /tmp/lb is still there (readlink prints /b), and the host directory /tmp/ia is gone with everything in it (ls: cannot access '/tmp/ia').

In the file-bind variant rm /tmp/lhf exits 0, deletes the host file /tmp/ib/hf, and leaves the link.

Everything deleted is inside the bind, so this is not a containment escape, but it is silent loss of the bound host data from a command that should only remove a link.

Additional Context

The exact-match branch of VfsKernel::resolve_host (src/vfs_kernel.rs:55) calls vfs.resolve(abs_path, true), which follows an in-memory symlink to the HostDir/HostFile inode. lstat, remove_file and remove_dir all go through it, so they see and act on the bind root rather than the link. A link to a path below the bind root (ln -s /b/d /tmp/x; rm -r /tmp/x) is fine.

Found while reviewing #377. That PR fixes host symlinks inside a bind; this case (an in-memory link pointing at the bind) behaves the same with and without it, except that with #377 the removal no longer stops at host links inside the tree.

Possible Solution

In lstat, remove_file and remove_dir, resolve the in-memory path without following the last component first (vfs.resolve(&abs, false)), and only take the host path when that inode is itself the HostDir/HostFile, not a symlink to it.

Related Issues

#254, #377

Activity

  1. added
    bug
    on Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    Fields

    Language

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions