Skip to content

--bind-try fails when the source is a bind mounted deleted file #811

Open

Description

@Hello71
touch a b
mount --bind a b
bwrap --bind-try b /x --ro-bind / / echo ok1
rm a
bwrap --bind-try b /x --ro-bind / / echo ok2

alternate example, without root:

touch a b; bwrap --bind / / --ro-bind $PWD/a $PWD/b sh -c 'bwrap --bind-try b /x --ro-bind / / echo ok1; rm a && bwrap --bind-try b /x --ro-bind / / echo ok2'

expected behavior: ok1, ok2
actual behavior: ok1, bwrap: Can't bind mount /tmp/x/b on /x: Unable to mount source on destination: No such file or directory

trimmed example strace output:

[pid 30523] openat(AT_FDCWD</>, "/oldroot", O_RDONLY|O_NOCTTY|O_CLOEXEC|O_PATH) = 4</oldroot>
[pid 30523] openat2(4</oldroot>, "/tmp/x/b", {flags=O_RDONLY|O_PATH, resolve=RESOLVE_NO_MAGICLINKS|RESOLVE_IN_ROOT}, 24) = 5</oldroot/tmp/x/b>(deleted)
[pid 30523] close(4</oldroot>)          = 0
[pid 30523] fstat(5</oldroot/tmp/x/b>(deleted), {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
[pid 30523] openat(AT_FDCWD</>, "/newroot", O_RDONLY|O_NOCTTY|O_CLOEXEC|O_PATH) = 4</newroot>
[pid 30523] openat2(4</newroot>, "/", {flags=O_RDONLY|O_DIRECTORY, resolve=RESOLVE_NO_MAGICLINKS|RESOLVE_IN_ROOT}, 24) = 6</newroot>
[pid 30523] close(4</newroot>)          = 0
[pid 30523] openat(6</newroot>, "x", O_WRONLY|O_CREAT|O_EXCL|O_NOCTTY|O_NOFOLLOW|O_CLOEXEC, 0444) = 4</newroot/x>
[pid 30523] close(4</newroot/x>)        = 0
[pid 30523] openat(6</newroot>, "x", O_RDONLY|O_NOFOLLOW|O_CLOEXEC|O_PATH) = 4</newroot/x>
[pid 30523] fstat(4</newroot/x>, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0
[pid 30523] readlink("/proc/self/fd/4", "/newroot/x", 99) = 10
[pid 30523] mount("/proc/self/fd/5", "/proc/self/fd/4", NULL, MS_BIND|MS_REC|MS_SILENT, NULL) = -1 ENOENT (No such file or directory)

basically, the file exists in the sense that it can be opened and I/O performed, but cannot be bind-mounted from. unfortunately, it doesn't seem to be possible to work around with new mount API. I'm not sure whether it makes more sense to argue the case to kernel maintainers, or silently ignore this error in bubblewrap.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions