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