@@ -40,7 +40,8 @@ func needsSetupDev(config *configs.Config) bool {
4040// prepareRootfs sets up the devices, mount points, and filesystems for use
4141// inside a new mount namespace. It doesn't set anything as ro. You must call
4242// finalizeRootfs after this function to finish setting up the rootfs.
43- func prepareRootfs (pipe io.ReadWriter , config * configs.Config ) (err error ) {
43+ func prepareRootfs (pipe io.ReadWriter , iConfig * initConfig ) (err error ) {
44+ config := iConfig .Config
4445 if err := prepareRoot (config ); err != nil {
4546 return newSystemErrorWithCause (err , "preparing rootfs" )
4647 }
@@ -80,6 +81,7 @@ func prepareRootfs(pipe io.ReadWriter, config *configs.Config) (err error) {
8081 // The hooks are run after the mounts are setup, but before we switch to the new
8182 // root, so that the old root is still available in the hooks for any mount
8283 // manipulations.
84+ // Note that iConfig.Cwd is not guaranteed to exist here.
8385 if err := syncParentHooks (pipe ); err != nil {
8486 return err
8587 }
@@ -111,6 +113,14 @@ func prepareRootfs(pipe io.ReadWriter, config *configs.Config) (err error) {
111113 }
112114 }
113115
116+ if cwd := iConfig .Cwd ; cwd != "" {
117+ // Note that spec.Process.Cwd can contain unclean value like "../../../../foo/bar...".
118+ // However, we are safe to call MkDirAll directly because we are in the jail here.
119+ if err := os .MkdirAll (cwd , 0755 ); err != nil {
120+ return err
121+ }
122+ }
123+
114124 return nil
115125}
116126
0 commit comments