volumes_linux.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. package daemon
  2. import (
  3. "strings"
  4. "github.com/docker/docker/api/types/mount"
  5. "github.com/docker/docker/errdefs"
  6. "github.com/pkg/errors"
  7. )
  8. // validateBindDaemonRoot ensures that if a given mountpoint's source is within
  9. // the daemon root path, that the propagation is setup to prevent a container
  10. // from holding private references to a mount within the daemon root, which
  11. // can cause issues when the daemon attempts to remove the mountpoint.
  12. func (daemon *Daemon) validateBindDaemonRoot(m mount.Mount) (bool, error) {
  13. if m.Type != mount.TypeBind {
  14. return false, nil
  15. }
  16. // check if the source is within the daemon root, or if the daemon root is within the source
  17. if !strings.HasPrefix(m.Source, daemon.root) && !strings.HasPrefix(daemon.root, m.Source) {
  18. return false, nil
  19. }
  20. if m.BindOptions == nil {
  21. return true, nil
  22. }
  23. switch m.BindOptions.Propagation {
  24. case mount.PropagationRSlave, mount.PropagationRShared, "":
  25. return m.BindOptions.Propagation == "", nil
  26. default:
  27. }
  28. 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))
  29. }