Pause containers while copying into them

Should fix CVE-2018-15664 for Podman.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
This commit is contained in:
Matthew Heon
2019-05-28 13:11:55 -04:00
parent 7b7d54242c
commit 49dc18552a
2 changed files with 16 additions and 3 deletions

View File

@ -24,4 +24,5 @@ type BuildValues struct {
type CpValues struct { type CpValues struct {
PodmanCommand PodmanCommand
Extract bool Extract bool
Pause bool
} }

View File

@ -50,6 +50,7 @@ func init() {
cpCommand.Command = _cpCommand cpCommand.Command = _cpCommand
flags := cpCommand.Flags() flags := cpCommand.Flags()
flags.BoolVar(&cpCommand.Extract, "extract", false, "Extract the tar file into the destination directory.") flags.BoolVar(&cpCommand.Extract, "extract", false, "Extract the tar file into the destination directory.")
flags.BoolVar(&cpCommand.Pause, "pause", true, "Pause the container while copying")
cpCommand.SetHelpTemplate(HelpTemplate()) cpCommand.SetHelpTemplate(HelpTemplate())
cpCommand.SetUsageTemplate(UsageTemplate()) cpCommand.SetUsageTemplate(UsageTemplate())
rootCmd.AddCommand(cpCommand.Command) rootCmd.AddCommand(cpCommand.Command)
@ -67,11 +68,10 @@ func cpCmd(c *cliconfig.CpValues) error {
} }
defer runtime.Shutdown(false) defer runtime.Shutdown(false)
extract := c.Flag("extract").Changed return copyBetweenHostAndContainer(runtime, args[0], args[1], c.Extract, c.Pause)
return copyBetweenHostAndContainer(runtime, args[0], args[1], extract)
} }
func copyBetweenHostAndContainer(runtime *libpod.Runtime, src string, dest string, extract bool) error { func copyBetweenHostAndContainer(runtime *libpod.Runtime, src string, dest string, extract bool, pause bool) error {
srcCtr, srcPath := parsePath(runtime, src) srcCtr, srcPath := parsePath(runtime, src)
destCtr, destPath := parsePath(runtime, dest) destCtr, destPath := parsePath(runtime, dest)
@ -94,6 +94,18 @@ func copyBetweenHostAndContainer(runtime *libpod.Runtime, src string, dest strin
return err return err
} }
defer ctr.Unmount(false) defer ctr.Unmount(false)
if pause {
if err := ctr.Pause(); err != nil {
return err
}
defer func() {
if err := ctr.Unpause(); err != nil {
logrus.Errorf("Error unpausing container after copying: %v", err)
}
}()
}
user, err := getUser(mountPoint, ctr.User()) user, err := getUser(mountPoint, ctr.User())
if err != nil { if err != nil {
return err return err