Skip to content

--bind can cause bwrap to fail during startup if it races with the mount table changing #650

@artli

Description

@artli

Try running this in one terminal to cause the mount table to change frequently:

$ mkdir from to
$ while true; do sudo mount --bind from to && sudo umount to; done

And run bwrap repeatedly in another terminal:

$ while true; do bwrap --bind / / -- /bin/true && echo -n .; done
...................................................................................................bwrap: Can't bind mount /oldroot/ on /newroot/: Unable to apply mount flags: remount "/newroot/<redacted>/to": Invalid argument
.....................................................................................................................................................................................................................................................................................................................................bwrap: Can't bind mount /oldroot/ on /newroot/: Unable to apply mount flags: remount "/newroot/<redacted>/to": Invalid argument
..............................................................................................................................................................................................................................................................................................................................................................................................................bwrap: Can't bind mount /oldroot/ on /newroot/: Unable to apply mount flags: remount "/newroot/<redacted>/to": Invalid argument
.....................................

This likely happens because the bind_mount function grabs the current mount table (

mount_tab = parse_mountinfo (proc_fd, kernel_case_combination);
) and then remounts its entries one by one to ensure --bind works recursively but fails if any of the sub-mounts fail (
mount ("none", mount_tab[i].mountpoint,
). The implicit assumption is that any mount that's already listed in the mount table is going to stay there and so we should be able to remount it, but mounts can definitely disappear in real-world scenarios (e.g. if the user unmounts something manually or if autofs is used with non-zero timeouts), so bwrap should be robust to that.

It already checks that errno != EACCES; perhaps this failure can be excluded in the same way.

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