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