Skip to content

Commit 0228707

Browse files
authored
Merge pull request opencontainers#1873 from rhatdan/ms_move
When doing a copyup, /tmp can not be a shared mount point
2 parents 459bfae + 62a4763 commit 0228707

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

libcontainer/rootfs_linux.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,26 @@ func finalizeRootfs(config *configs.Config) (err error) {
152152
return nil
153153
}
154154

155+
// /tmp has to be mounted as private to allow MS_MOVE to work in all situations
156+
func prepareTmp(topTmpDir string) (string, error) {
157+
tmpdir, err := ioutil.TempDir(topTmpDir, "runctop")
158+
if err != nil {
159+
return "", err
160+
}
161+
if err := unix.Mount(tmpdir, tmpdir, "bind", unix.MS_BIND, ""); err != nil {
162+
return "", err
163+
}
164+
if err := unix.Mount("", tmpdir, "", uintptr(unix.MS_PRIVATE), ""); err != nil {
165+
return "", err
166+
}
167+
return tmpdir, nil
168+
}
169+
170+
func cleanupTmp(tmpdir string) error {
171+
unix.Unmount(tmpdir, 0)
172+
return os.RemoveAll(tmpdir)
173+
}
174+
155175
func mountCmd(cmd configs.Command) error {
156176
command := exec.Command(cmd.Path, cmd.Args[:]...)
157177
command.Env = cmd.Env
@@ -199,7 +219,12 @@ func mountToRootfs(m *configs.Mount, rootfs, mountLabel string) error {
199219
}
200220
}
201221
if copyUp {
202-
tmpDir, err = ioutil.TempDir("/tmp", "runctmpdir")
222+
tmpdir, err := prepareTmp("/tmp")
223+
if err != nil {
224+
return newSystemErrorWithCause(err, "tmpcopyup: failed to setup tmpdir")
225+
}
226+
defer cleanupTmp(tmpdir)
227+
tmpDir, err = ioutil.TempDir(tmpdir, "runctmpdir")
203228
if err != nil {
204229
return newSystemErrorWithCause(err, "tmpcopyup: failed to create tmpdir")
205230
}

0 commit comments

Comments
 (0)