summaryrefslogtreecommitdiff
path: root/daemon/volumes_linux.go
diff options
context:
space:
mode:
authorBrian Goff <cpuguy83@gmail.com>2018-01-18 16:55:27 -0500
committerBrian Goff <cpuguy83@gmail.com>2018-02-07 14:27:09 -0500
commit589a0afa8cbe39b6512662fd1705873e2d236dd0 (patch)
treeeafecc5c6d1524e4e8d94fb6b556ce382b2e7928 /daemon/volumes_linux.go
parent2e8ccbb49e21b8696ad4c39185036a8b7e50402f (diff)
downloaddocker-589a0afa8cbe39b6512662fd1705873e2d236dd0.tar.gz
Use rslave propagation for mounts from daemon root
By default, if a user requests a bind mount it uses private propagation. When the source path is a path within the daemon root this, along with some other propagation values that the user can use, causes issues when the daemon tries to remove a mountpoint because a container will then have a private reference to that mount which prevents removal. Unmouting with MNT_DETATCH can help this scenario on newer kernels, but ultimately this is just covering up the problem and doesn't actually free up the underlying resources until all references are destroyed. This change does essentially 2 things: 1. Change the default propagation when unspecified to `rslave` when the source path is within the daemon root path or a parent of the daemon root (because everything is using rbinds). 2. Creates a validation error on create when the user tries to specify an unacceptable propagation mode for these paths... basically the only two acceptable modes are `rslave` and `rshared`. In cases where we have used the new default propagation but the underlying filesystem is not setup to handle it (fs must hvae at least rshared propagation) instead of erroring out like we normally would, this falls back to the old default mode of `private`, which preserves backwards compatibility. Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Diffstat (limited to 'daemon/volumes_linux.go')
-rw-r--r--daemon/volumes_linux.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/daemon/volumes_linux.go b/daemon/volumes_linux.go
new file mode 100644
index 0000000000..cf3d9ed159
--- /dev/null
+++ b/daemon/volumes_linux.go
@@ -0,0 +1,36 @@
+package daemon
+
+import (
+ "strings"
+
+ "github.com/docker/docker/api/types/mount"
+ "github.com/docker/docker/errdefs"
+ "github.com/pkg/errors"
+)
+
+// validateBindDaemonRoot ensures that if a given mountpoint's source is within
+// the daemon root path, that the propagation is setup to prevent a container
+// from holding private refereneces to a mount within the daemon root, which
+// can cause issues when the daemon attempts to remove the mountpoint.
+func (daemon *Daemon) validateBindDaemonRoot(m mount.Mount) (bool, error) {
+ if m.Type != mount.TypeBind {
+ return false, nil
+ }
+
+ // check if the source is within the daemon root, or if the daemon root is within the source
+ if !strings.HasPrefix(m.Source, daemon.root) && !strings.HasPrefix(daemon.root, m.Source) {
+ return false, nil
+ }
+
+ if m.BindOptions == nil {
+ return true, nil
+ }
+
+ switch m.BindOptions.Propagation {
+ case mount.PropagationRSlave, mount.PropagationRShared, "":
+ return m.BindOptions.Propagation == "", nil
+ default:
+ }
+
+ return false, errdefs.InvalidParameter(errors.Errorf(`invalid mount config: must use either propagation mode "rslave" or "rshared" when mount source is within the daemon root, daemon root: %q, bind mount source: %q, propagation: %q`, daemon.root, m.Source, m.BindOptions.Propagation))
+}