Skip to content

Commit 6ca857f

Browse files
committed
volume,container: chroot to source before exporting content
* Utils must support higher level API to create Tar with chrooted into directory * Volume export: use TarwithChroot instead of Tar so we can make sure no symlink can be exported by tar if it exists outside of the source directory. * container export: use chroot and Tar instead of Tar so we can make sure no symlink can be exported by tar if it exists outside of the mointPoint. [NO NEW TESTS NEEDED] [NO TESTS NEEDED] Race needs combination of external/in-container mechanism which is hard to repro in CI. Closes: BZ:#2168256 CVE: https://access.redhat.com/security/cve/CVE-2023-0778 Signed-off-by: Aditya R <[email protected]>
1 parent e8a8433 commit 6ca857f

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

libpod/container_internal.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import (
3434
"github.com/containers/podman/v4/pkg/systemd/notifyproxy"
3535
"github.com/containers/podman/v4/pkg/util"
3636
"github.com/containers/storage"
37-
"github.com/containers/storage/pkg/archive"
37+
"github.com/containers/storage/pkg/chrootarchive"
3838
"github.com/containers/storage/pkg/idmap"
3939
"github.com/containers/storage/pkg/idtools"
4040
"github.com/containers/storage/pkg/lockfile"
@@ -761,7 +761,7 @@ func (c *Container) export(out io.Writer) error {
761761
}()
762762
}
763763

764-
input, err := archive.Tar(mountPoint, archive.Uncompressed)
764+
input, err := chrootarchive.Tar(mountPoint, nil, mountPoint)
765765
if err != nil {
766766
return fmt.Errorf("reading container directory %q: %w", c.ID(), err)
767767
}

utils/utils.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
"github.com/containers/common/pkg/cgroups"
1515
"github.com/containers/storage/pkg/archive"
16+
"github.com/containers/storage/pkg/chrootarchive"
1617
"github.com/godbus/dbus/v5"
1718
"github.com/sirupsen/logrus"
1819
)
@@ -63,7 +64,7 @@ func CreateTarFromSrc(source string, dest string) error {
6364
return fmt.Errorf("could not create tarball file '%s': %w", dest, err)
6465
}
6566
defer file.Close()
66-
return TarToFilesystem(source, file)
67+
return TarChrootToFilesystem(source, file)
6768
}
6869

6970
// TarToFilesystem creates a tarball from source and writes to an os.file
@@ -87,6 +88,28 @@ func Tar(source string) (io.ReadCloser, error) {
8788
return archive.Tar(source, archive.Uncompressed)
8889
}
8990

91+
// TarChrootToFilesystem creates a tarball from source and writes to an os.file
92+
// provided while chrooted to the source.
93+
func TarChrootToFilesystem(source string, tarball *os.File) error {
94+
tb, err := TarWithChroot(source)
95+
if err != nil {
96+
return err
97+
}
98+
_, err = io.Copy(tarball, tb)
99+
if err != nil {
100+
return err
101+
}
102+
logrus.Debugf("wrote tarball file %s", tarball.Name())
103+
return nil
104+
}
105+
106+
// TarWithChroot creates a tarball from source and returns a readcloser of it
107+
// while chrooted to the source.
108+
func TarWithChroot(source string) (io.ReadCloser, error) {
109+
logrus.Debugf("creating tarball of %s", source)
110+
return chrootarchive.Tar(source, nil, source)
111+
}
112+
90113
// RemoveScientificNotationFromFloat returns a float without any
91114
// scientific notation if the number has any.
92115
// golang does not handle conversion of float64s that have scientific

0 commit comments

Comments
 (0)