d96d33
From 840e7dad513b86f454573ad415701c0199f78d30 Mon Sep 17 00:00:00 2001
d96d33
From: TomSweeneyRedHat <tsweeney@redhat.com>
d96d33
Date: Tue, 24 Mar 2020 20:10:22 -0400
d96d33
Subject: [PATCH] Fix potential CVE in tarfile w/ symlink
d96d33
d96d33
Stealing @nalind 's workaround to avoid refetching
d96d33
content after a file read failure.  Under the right
d96d33
circumstances that could be a symlink to a file meant
d96d33
to overwrite a good file with bad data.
d96d33
d96d33
Testing:
d96d33
```
d96d33
goodstuff
d96d33
d96d33
[1] 14901
d96d33
d96d33
127.0.0.1 - - [24/Mar/2020 20:15:50] "GET / HTTP/1.1" 200 -
d96d33
127.0.0.1 - - [24/Mar/2020 20:15:50] "GET / HTTP/1.1" 200 -
d96d33
no FROM statement found
d96d33
d96d33
goodstuff
d96d33
```
d96d33
d96d33
Signed-off-by: TomSweeneyRedHat <tsweeney@redhat.com>
d96d33
---
d96d33
 imagebuildah/util.go | 5 +++--
d96d33
 1 file changed, 3 insertions(+), 2 deletions(-)
d96d33
d96d33
diff --git a/imagebuildah/util.go b/imagebuildah/util.go
d96d33
index 29ea60970..5f14c9883 100644
d96d33
--- a/vendor/github.com/containers/buildah/imagebuildah/util.go
d96d33
+++ b/vendor/github.com/containers/buildah/imagebuildah/util.go
d96d33
@@ -14,6 +14,7 @@ import (
d96d33
 
d96d33
 	"github.com/containers/buildah"
d96d33
 	"github.com/containers/storage/pkg/chrootarchive"
d96d33
+	"github.com/containers/storage/pkg/ioutils"
d96d33
 	"github.com/opencontainers/runtime-spec/specs-go"
d96d33
 	"github.com/pkg/errors"
d96d33
 	"github.com/sirupsen/logrus"
d96d33
@@ -57,7 +58,7 @@ func downloadToDirectory(url, dir string) error {
d96d33
 		}
d96d33
 		dockerfile := filepath.Join(dir, "Dockerfile")
d96d33
 		// Assume this is a Dockerfile
d96d33
-		if err := ioutil.WriteFile(dockerfile, body, 0600); err != nil {
d96d33
+		if err := ioutils.AtomicWriteFile(dockerfile, body, 0600); err != nil {
d96d33
 			return errors.Wrapf(err, "Failed to write %q to %q", url, dockerfile)
d96d33
 		}
d96d33
 	}
d96d33
@@ -75,7 +76,7 @@ func stdinToDirectory(dir string) error {
d96d33
 	if err := chrootarchive.Untar(reader, dir, nil); err != nil {
d96d33
 		dockerfile := filepath.Join(dir, "Dockerfile")
d96d33
 		// Assume this is a Dockerfile
d96d33
-		if err := ioutil.WriteFile(dockerfile, b, 0600); err != nil {
d96d33
+		if err := ioutils.AtomicWriteFile(dockerfile, b, 0600); err != nil {
d96d33
 			return errors.Wrapf(err, "Failed to write bytes to %q", dockerfile)
d96d33
 		}
d96d33
 	}