Skip to content

Commit e8498d3

Browse files
authored
Merge pull request opencontainers#2672 from giuseppe/fix-remount-readonly
linux: fix remount readonly in a user namespace
2 parents 8591c33 + 41aa764 commit e8498d3

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

libcontainer/rootfs_linux.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,19 @@ func prepareRoot(config *configs.Config) error {
741741
}
742742

743743
func setReadonly() error {
744-
return unix.Mount("/", "/", "bind", unix.MS_BIND|unix.MS_REMOUNT|unix.MS_RDONLY|unix.MS_REC, "")
744+
flags := uintptr(unix.MS_BIND | unix.MS_REMOUNT | unix.MS_RDONLY)
745+
746+
err := unix.Mount("", "/", "", flags, "")
747+
if err == nil {
748+
return nil
749+
}
750+
var s unix.Statfs_t
751+
if err := unix.Statfs("/", &s); err != nil {
752+
return &os.PathError{Op: "statfs", Path: "/", Err: err}
753+
}
754+
flags |= uintptr(s.Flags)
755+
return unix.Mount("", "/", "", flags, "")
756+
745757
}
746758

747759
func setupPtmx(config *configs.Config) error {

0 commit comments

Comments
 (0)