|
88 | 88 | } |
89 | 89 | ) |
90 | 90 |
|
| 91 | +var makeFlags uintptr = uintptr(unix.MS_UNBINDABLE | unix.MS_PRIVATE | unix.MS_SLAVE | unix.MS_SHARED | unix.MS_REC) |
| 92 | + |
91 | 93 | func mountFlagNames(flags uintptr) []string { |
92 | 94 | var names []string |
93 | 95 | for flag, name := range mountFlagMap { |
@@ -385,7 +387,7 @@ func makeReadOnly(mntpoint string, flags uintptr) error { |
385 | 387 | if fs.Flags&unix.ST_RDONLY == 0 { |
386 | 388 | // All callers currently pass MS_RDONLY in "flags", but in case they stop doing |
387 | 389 | // that at some point in the future... |
388 | | - if err := unix.Mount(mntpoint, mntpoint, "bind", flags|unix.MS_RDONLY|unix.MS_REMOUNT|unix.MS_BIND, ""); err != nil { |
| 390 | + if err := unix.Mount(mntpoint, mntpoint, "bind", (flags|unix.MS_RDONLY|unix.MS_REMOUNT|unix.MS_BIND)&^makeFlags, ""); err != nil { |
389 | 391 | return fmt.Errorf("remounting %s in mount namespace read-only: %w", mntpoint, err) |
390 | 392 | } |
391 | 393 | } |
@@ -440,7 +442,7 @@ func setupChrootBindMounts(spec *specs.Spec, bundlePath string) (undoBinds func( |
440 | 442 | return undoBinds, fmt.Errorf("checking if directory %q was bound read-only: %w", subDev, err) |
441 | 443 | } |
442 | 444 | if fs.Flags&unix.ST_RDONLY == 0 { |
443 | | - if err := unix.Mount(subDev, subDev, "bind", devFlags|unix.MS_REMOUNT|unix.MS_BIND, ""); err != nil { |
| 445 | + if err := unix.Mount(subDev, subDev, "bind", (devFlags|unix.MS_REMOUNT|unix.MS_BIND)&^makeFlags, ""); err != nil { |
444 | 446 | return undoBinds, fmt.Errorf("remounting /dev in mount namespace read-only: %w", err) |
445 | 447 | } |
446 | 448 | } |
@@ -642,7 +644,7 @@ func setupChrootBindMounts(spec *specs.Spec, bundlePath string) (undoBinds func( |
642 | 644 | if effectiveImportantFlags != expectedImportantFlags { |
643 | 645 | // Do a remount to try to get the desired flags to stick. |
644 | 646 | effectiveUnimportantFlags := uintptr(fs.Flags) & ^possibleImportantFlags |
645 | | - remountFlags := unix.MS_REMOUNT | bindFlags | requestFlags | mountFlagsForFSFlags(effectiveUnimportantFlags) |
| 647 | + remountFlags := (unix.MS_REMOUNT | bindFlags | requestFlags | mountFlagsForFSFlags(effectiveUnimportantFlags)) &^ makeFlags |
646 | 648 | // If we are requesting a read-only mount, add any possibleImportantFlags present in fs.Flags to remountFlags. |
647 | 649 | if requestFlags&unix.ST_RDONLY == unix.ST_RDONLY { |
648 | 650 | remountFlags |= uintptr(fs.Flags) & possibleImportantFlags |
@@ -701,7 +703,7 @@ func setupChrootBindMounts(spec *specs.Spec, bundlePath string) (undoBinds func( |
701 | 703 | return undoBinds, fmt.Errorf("checking if directory %q was bound read-only: %w", target, err) |
702 | 704 | } |
703 | 705 | if fs.Flags&unix.ST_RDONLY == 0 { |
704 | | - if err := unix.Mount(target, target, "", unix.MS_REMOUNT|unix.MS_RDONLY|bindFlags|mountFlagsForFSFlags(uintptr(fs.Flags)), ""); err != nil { |
| 706 | + if err := unix.Mount(target, target, "", (unix.MS_REMOUNT|unix.MS_RDONLY|bindFlags|mountFlagsForFSFlags(uintptr(fs.Flags)))&^makeFlags, ""); err != nil { |
705 | 707 | return undoBinds, fmt.Errorf("remounting %q in mount namespace read-only: %w", target, err) |
706 | 708 | } |
707 | 709 | } |
@@ -814,7 +816,7 @@ func setupChrootBindMounts(spec *specs.Spec, bundlePath string) (undoBinds func( |
814 | 816 | return undoBinds, fmt.Errorf("checking if masked directory %q was mounted read-only in mount namespace: %w", target, err) |
815 | 817 | } |
816 | 818 | if fs.Flags&unix.ST_RDONLY == 0 { |
817 | | - if err = unix.Mount(target, target, "", syscall.MS_REMOUNT|roFlags|mountFlagsForFSFlags(uintptr(fs.Flags)), ""); err != nil { |
| 819 | + if err = unix.Mount(target, target, "", (syscall.MS_REMOUNT|roFlags|mountFlagsForFSFlags(uintptr(fs.Flags)))&^makeFlags, ""); err != nil { |
818 | 820 | return undoBinds, fmt.Errorf("making sure masked directory %q in mount namespace is read only: %w", target, err) |
819 | 821 | } |
820 | 822 | } |
|
0 commit comments