CVE-2019-11246: Clean links handling in cp's tar code#76788
CVE-2019-11246: Clean links handling in cp's tar code#76788k8s-ci-robot merged 2 commits intokubernetes:masterfrom
Conversation
|
/sig cli |
pkg/kubectl/cmd/cp/cp.go
Outdated
There was a problem hiding this comment.
how come you removed this? (I'm not sure I disagree, just curious)
There was a problem hiding this comment.
The entire code was introduced in #46762 to deal with copying a file into a dir, which is now much simpler. I've wanted to clean this so with this significant changes it was a good time to do it.
pkg/kubectl/cmd/cp/cp.go
Outdated
There was a problem hiding this comment.
What happens here if the destination file is a directory? Can this get confused if the path ends in a /?
There was a problem hiding this comment.
Based on https://golang.org/pkg/path/filepath/#Split it should be solid.
There was a problem hiding this comment.
Looking at the implementation, it seems like the destination file would be included in the directory if the path end sin a slash, and the file would be "" I think.
I think it's fine, but might be worth adding a test case?
There was a problem hiding this comment.
I've added directory test, but that's actually handled a few lines earlier in
destFileName := path.Join(destDir, header.Name[len(prefix):])
destFileName will get cleaned (path.Join calls Clean internally) even if it ends with /.
9baef94 to
a93a18c
Compare
|
@tallclair added that one last test case and also fixed the verify failure, ptal |
|
/retest |
tallclair
left a comment
There was a problem hiding this comment.
lgtm, just fix the comment.
pkg/kubectl/cmd/cp/cp_test.go
Outdated
There was a problem hiding this comment.
| file{ // Absolute file | |
| file{ // Relative directory path with terminating / |
|
@tallclair updated, ptal |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: soltysh The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
Now with fixed e2e. |
|
Self-tagging based on previous approval. |
…8-upstream-release-1.14 Automated cherry pick of #76788: Test kubectl cp escape
…8-upstream-release-1.13 Automated cherry pick of #76788: Test kubectl cp escape
…8-upstream-release-1.12 Automated cherry pick of #76788: Test kubectl cp escape
| } | ||
| // For scrutiny we verify both the actual destination as well as we follow | ||
| // all the links that might lead outside of the destination directory. | ||
| if !isDestRelative(destDir, destFileName) || !isDestRelative(destDir, filepath.Join(evaledPath, file)) { |
There was a problem hiding this comment.
I haven't had enough time to go through everything to understand the intention here, but I think the symlink checking is probably more aggressive than it should be. Picking up this change breaks existing scripts that copy files to temp directories on Mac.
Please be aware that Mac's default readlink doesn't support canonicalizing a path, so it's not as easy to portably fix on the user's side as you might think (see: stackoverflow).
$ FILE=path/to/file
$ TMPD=$(mktemp -d)
$ kubectl cp --no-preserve "$NAMESPACE/$POD:$FILE" "$TMPD/$FILE" -c $CONTAINER
warning: link "/var/folders/h7/ydd9wql57gdf6883cj9779sm0zsnn7/T/tmp.3TVUBz8Mqe/path/to/file" is pointing to "" which is outside target destination, skipping
$ echo $TMPD
/var/folders/h7/ydd9wql57gdf6883cj9779sm0zsnn7/T/tmp.3TVUBz8Mqe
$ readlink -f $TMPD # using GNU readlink
/private/var/folders/h7/ydd9wql57gdf6883cj9779sm0zsnn7/T/tmp.3TVUBz8Mqe
kubectl cp potential directory traversal - CVE-2019-11246 kubectl cp potential directory traversal - CVE-2019-11246 kubernetes#75037 kubernetes#76788 See merge request !53
What type of PR is this?
/kind bug
What this PR does / why we need it:
This PR cleans up the tar code used in
kubectl cp.Special notes for your reviewer:
/assign @tallclair
Does this PR introduce a user-facing change?: