Skip to content

Commit d9efc31

Browse files
committed
layer: don't permit / type to be changed on extraction
If users can change the type of / to a symlink, they can cause umoci to overwrite host files. This is obviously bad, and is not caught by the rest of our directory escape detection code because the root itself has been changed to a different directory. Fixes: CVE-2021-29136 Reported-by: Robin Peraglie <robin@cure53.de> Tested-by: Daniel Dao <dqminh89@gmail.com> Reviewed-by: Tycho Andersen <tycho@tycho.pizza> Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
1 parent 07fa845 commit d9efc31

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

oci/layer/tar_extract.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,11 @@ func (te *TarExtractor) UnpackEntry(root string, hdr *tar.Header, r io.Reader) (
404404
if filepath.Join("/", hdr.Name) == "/" {
405405
// If we got an entry for the root, then unsafeDir is the full path.
406406
unsafeDir, file = hdr.Name, "."
407+
// If we're being asked to change the root type, bail because they may
408+
// change it to a symlink which we could inadvertently follow.
409+
if hdr.Typeflag != tar.TypeDir {
410+
return errors.New("malicious tar entry -- refusing to change type of root directory")
411+
}
407412
}
408413
dir, err := securejoin.SecureJoinVFS(root, unsafeDir, te.fsEval)
409414
if err != nil {

0 commit comments

Comments
 (0)