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