@@ -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+
155175func 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