mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 12:18:16 +00:00 
			
		
		
		
	Update dependency opencontainer/runc
This commit is contained in:
		
							
								
								
									
										130
									
								
								vendor/github.com/opencontainers/runc/libcontainer/rootfs_linux.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										130
									
								
								vendor/github.com/opencontainers/runc/libcontainer/rootfs_linux.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -46,6 +46,7 @@ func prepareRootfs(pipe io.ReadWriter, iConfig *initConfig) (err error) {
 | 
			
		||||
		return newSystemErrorWithCause(err, "preparing rootfs")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	hasCgroupns := config.Namespaces.Contains(configs.NEWCGROUP)
 | 
			
		||||
	setupDev := needsSetupDev(config)
 | 
			
		||||
	for _, m := range config.Mounts {
 | 
			
		||||
		for _, precmd := range m.PremountCmds {
 | 
			
		||||
@@ -53,8 +54,7 @@ func prepareRootfs(pipe io.ReadWriter, iConfig *initConfig) (err error) {
 | 
			
		||||
				return newSystemErrorWithCause(err, "running premount command")
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if err := mountToRootfs(m, config.Rootfs, config.MountLabel); err != nil {
 | 
			
		||||
		if err := mountToRootfs(m, config.Rootfs, config.MountLabel, hasCgroupns); err != nil {
 | 
			
		||||
			return newSystemErrorWithCausef(err, "mounting %q to rootfs %q at %q", m.Source, config.Rootfs, m.Destination)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
@@ -182,7 +182,34 @@ func mountCmd(cmd configs.Command) error {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func mountToRootfs(m *configs.Mount, rootfs, mountLabel string) error {
 | 
			
		||||
func prepareBindMount(m *configs.Mount, rootfs string) error {
 | 
			
		||||
	stat, err := os.Stat(m.Source)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		// error out if the source of a bind mount does not exist as we will be
 | 
			
		||||
		// unable to bind anything to it.
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	// ensure that the destination of the bind mount is resolved of symlinks at mount time because
 | 
			
		||||
	// any previous mounts can invalidate the next mount's destination.
 | 
			
		||||
	// this can happen when a user specifies mounts within other mounts to cause breakouts or other
 | 
			
		||||
	// evil stuff to try to escape the container's rootfs.
 | 
			
		||||
	var dest string
 | 
			
		||||
	if dest, err = securejoin.SecureJoin(rootfs, m.Destination); err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	if err := checkMountDestination(rootfs, dest); err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	// update the mount with the correct dest after symlinks are resolved.
 | 
			
		||||
	m.Destination = dest
 | 
			
		||||
	if err := createIfNotExists(dest, stat.IsDir()); err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func mountToRootfs(m *configs.Mount, rootfs, mountLabel string, enableCgroupns bool) error {
 | 
			
		||||
	var (
 | 
			
		||||
		dest = m.Destination
 | 
			
		||||
	)
 | 
			
		||||
@@ -257,25 +284,7 @@ func mountToRootfs(m *configs.Mount, rootfs, mountLabel string) error {
 | 
			
		||||
		}
 | 
			
		||||
		return nil
 | 
			
		||||
	case "bind":
 | 
			
		||||
		stat, err := os.Stat(m.Source)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			// error out if the source of a bind mount does not exist as we will be
 | 
			
		||||
			// unable to bind anything to it.
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
		// ensure that the destination of the bind mount is resolved of symlinks at mount time because
 | 
			
		||||
		// any previous mounts can invalidate the next mount's destination.
 | 
			
		||||
		// this can happen when a user specifies mounts within other mounts to cause breakouts or other
 | 
			
		||||
		// evil stuff to try to escape the container's rootfs.
 | 
			
		||||
		if dest, err = securejoin.SecureJoin(rootfs, m.Destination); err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
		if err := checkMountDestination(rootfs, dest); err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
		// update the mount with the correct dest after symlinks are resolved.
 | 
			
		||||
		m.Destination = dest
 | 
			
		||||
		if err := createIfNotExists(dest, stat.IsDir()); err != nil {
 | 
			
		||||
		if err := prepareBindMount(m, rootfs); err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
		if err := mountPropagate(m, rootfs, mountLabel); err != nil {
 | 
			
		||||
@@ -319,12 +328,33 @@ func mountToRootfs(m *configs.Mount, rootfs, mountLabel string) error {
 | 
			
		||||
			Data:             "mode=755",
 | 
			
		||||
			PropagationFlags: m.PropagationFlags,
 | 
			
		||||
		}
 | 
			
		||||
		if err := mountToRootfs(tmpfs, rootfs, mountLabel); err != nil {
 | 
			
		||||
		if err := mountToRootfs(tmpfs, rootfs, mountLabel, enableCgroupns); err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
		for _, b := range binds {
 | 
			
		||||
			if err := mountToRootfs(b, rootfs, mountLabel); err != nil {
 | 
			
		||||
				return err
 | 
			
		||||
			if enableCgroupns {
 | 
			
		||||
				subsystemPath := filepath.Join(rootfs, b.Destination)
 | 
			
		||||
				if err := os.MkdirAll(subsystemPath, 0755); err != nil {
 | 
			
		||||
					return err
 | 
			
		||||
				}
 | 
			
		||||
				flags := defaultMountFlags
 | 
			
		||||
				if m.Flags&unix.MS_RDONLY != 0 {
 | 
			
		||||
					flags = flags | unix.MS_RDONLY
 | 
			
		||||
				}
 | 
			
		||||
				cgroupmount := &configs.Mount{
 | 
			
		||||
					Source:      "cgroup",
 | 
			
		||||
					Device:      "cgroup",
 | 
			
		||||
					Destination: subsystemPath,
 | 
			
		||||
					Flags:       flags,
 | 
			
		||||
					Data:        filepath.Base(subsystemPath),
 | 
			
		||||
				}
 | 
			
		||||
				if err := mountNewCgroup(cgroupmount); err != nil {
 | 
			
		||||
					return err
 | 
			
		||||
				}
 | 
			
		||||
			} else {
 | 
			
		||||
				if err := mountToRootfs(b, rootfs, mountLabel, enableCgroupns); err != nil {
 | 
			
		||||
					return err
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		for _, mc := range merged {
 | 
			
		||||
@@ -727,6 +757,41 @@ func pivotRoot(rootfs string) error {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func msMoveRoot(rootfs string) error {
 | 
			
		||||
	mountinfos, err := mount.GetMounts()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	absRootfs, err := filepath.Abs(rootfs)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	for _, info := range mountinfos {
 | 
			
		||||
		p, err := filepath.Abs(info.Mountpoint)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
		// Umount every syfs and proc file systems, except those under the container rootfs
 | 
			
		||||
		if (info.Fstype != "proc" && info.Fstype != "sysfs") || filepath.HasPrefix(p, absRootfs) {
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
		// Be sure umount events are not propagated to the host.
 | 
			
		||||
		if err := unix.Mount("", p, "", unix.MS_SLAVE|unix.MS_REC, ""); err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
		if err := unix.Unmount(p, unix.MNT_DETACH); err != nil {
 | 
			
		||||
			if err != unix.EINVAL && err != unix.EPERM {
 | 
			
		||||
				return err
 | 
			
		||||
			} else {
 | 
			
		||||
				// If we have not privileges for umounting (e.g. rootless), then
 | 
			
		||||
				// cover the path.
 | 
			
		||||
				if err := unix.Mount("tmpfs", p, "tmpfs", 0, ""); err != nil {
 | 
			
		||||
					return err
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	if err := unix.Mount(rootfs, "/", "", unix.MS_MOVE, ""); err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
@@ -859,3 +924,18 @@ func mountPropagate(m *configs.Mount, rootfs string, mountLabel string) error {
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func mountNewCgroup(m *configs.Mount) error {
 | 
			
		||||
	var (
 | 
			
		||||
		data   = m.Data
 | 
			
		||||
		source = m.Source
 | 
			
		||||
	)
 | 
			
		||||
	if data == "systemd" {
 | 
			
		||||
		data = cgroups.CgroupNamePrefix + data
 | 
			
		||||
		source = "systemd"
 | 
			
		||||
	}
 | 
			
		||||
	if err := unix.Mount(source, m.Destination, m.Device, uintptr(m.Flags), data); err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user