File: volumes_linux.go

package info (click to toggle)
docker.io 20.10.24%2Bdfsg1-1%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bookworm-proposed-updates
  • size: 60,824 kB
  • sloc: sh: 5,621; makefile: 593; ansic: 179; python: 162; asm: 7
file content (36 lines) | stat: -rw-r--r-- 1,287 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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 references 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))
}