Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[20.10 backport] Remove local fork of archive/tar package #46695

Merged
merged 3 commits into from
Oct 23, 2023

Conversation

corhere
Copy link
Contributor

@corhere corhere commented Oct 20, 2023

The hack of forking archive/tar is incompatible with the version of the package in Go 1.20.

vendor/archive/tar/common.go:16:2: use of internal package internal/godebug not allowed

Backport the proper fix rather than hacking on the hack.

- What I did

- How I did it

- How to verify it

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

@corhere corhere added this to the 20.10.27 milestone Oct 20, 2023
@corhere corhere requested a review from tianon as a code owner October 20, 2023 22:17
@thaJeztah
Copy link
Member

Linter is complaining; you probably need to cherry-pick 65e1adc (part of #43765)

[2023-10-20T22:21:07.807Z] pkg/archive/archive.go:469:3: SA1019: hdr.Xattrs has been deprecated since Go 1.10: Use PAXRecords instead. (staticcheck)
[2023-10-20T22:21:07.807Z] 		hdr.Xattrs = make(map[string]string)
[2023-10-20T22:21:07.807Z] 		^
[2023-10-20T22:21:07.807Z] pkg/archive/archive.go:470:3: SA1019: hdr.Xattrs has been deprecated since Go 1.10: Use PAXRecords instead. (staticcheck)
[2023-10-20T22:21:07.807Z] 		hdr.Xattrs["security.capability"] = string(capability[:length])
[2023-10-20T22:21:07.807Z] 		^
[2023-10-20T22:21:07.807Z] pkg/archive/archive.go:724:26: SA1019: hdr.Xattrs has been deprecated since Go 1.10: Use PAXRecords instead. (staticcheck)
[2023-10-20T22:21:07.807Z] 	for key, value := range hdr.Xattrs {
[2023-10-20T22:21:07.807Z] 	                        ^
[2023-10-20T22:21:07.807Z] pkg/archive/archive_linux.go:45:7: SA1019: hdr.Xattrs has been deprecated since Go 1.10: Use PAXRecords instead. (staticcheck)
[2023-10-20T22:21:07.807Z] 			if hdr.Xattrs != nil {
[2023-10-20T22:21:07.807Z] 			   ^
[2023-10-20T22:21:07.807Z] pkg/archive/archive_linux.go:46:12: SA1019: hdr.Xattrs has been deprecated since Go 1.10: Use PAXRecords instead. (staticcheck)
[2023-10-20T22:21:07.807Z] 				delete(hdr.Xattrs, "trusted.overlay.opaque")
[2023-10-20T22:21:07.807Z] 				       ^
[2023-10-20T22:21:07.807Z] pkg/tarsum/versioning.go:122:34: SA1019: h.Xattrs has been deprecated since Go 1.10: Use PAXRecords instead. (staticcheck)
[2023-10-20T22:21:07.807Z] 	xAttrKeys := make([]string, len(h.Xattrs))
[2023-10-20T22:21:07.807Z] 	                                ^
[2023-10-20T22:21:07.807Z] pkg/tarsum/versioning.go:123:17: SA1019: h.Xattrs has been deprecated since Go 1.10: Use PAXRecords instead. (staticcheck)
[2023-10-20T22:21:07.807Z] 	for k := range h.Xattrs {
[2023-10-20T22:21:07.807Z] 	               ^
[2023-10-20T22:21:07.807Z] pkg/tarsum/versioning.go:139:56: SA1019: h.Xattrs has been deprecated since Go 1.10: Use PAXRecords instead. (staticcheck)
[2023-10-20T22:21:07.807Z] 		orderedHeaders = append(orderedHeaders, [2]string{k, h.Xattrs[k]})
[2023-10-20T22:21:07.807Z] 		                                                     ^

@thaJeztah thaJeztah added status/2-code-review status/failing-ci Indicates that the PR in its current state fails the test suite labels Oct 21, 2023
@corhere corhere removed the status/failing-ci Indicates that the PR in its current state fails the test suite label Oct 23, 2023
@corhere
Copy link
Contributor Author

corhere commented Oct 23, 2023

The only CI failures are the usual Windows Server hcsshim timeouts. PTAL @thaJeztah

hack/vendor.sh Outdated
@@ -1,28 +0,0 @@
#!/usr/bin/env bash
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you removed a bit too much here; the hack/vendor.sh script itself should probably still be there (or Jenkins to be updated);

[2023-10-23T17:06:17.709Z] + docker run --rm -t --privileged -v /home/ubuntu/workspace/moby_PR-46695/.git:/go/src/github.com/docker/docker/.git --name docker-pr2 -e DOCKER_EXPERIMENTAL -e DOCKER_GITCOMMIT=d6cbc6b37d407d5bc8573bcfbbcf803b8fcb91e4 -e DOCKER_GRAPHDRIVER -e TEST_FORCE_VALIDATE -e VALIDATE_REPO=https://github.com/moby/moby.git -e VALIDATE_BRANCH=20.10 docker:d6cbc6b37d407d5bc8573bcfbbcf803b8fcb91e4 hack/validate/vendor
[2023-10-23T17:06:17.969Z] hack/validate/vendor: line 14: ./hack/vendor.sh: No such file or directory
script returned exit code 127

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, missed that one. Those pesky horizontal scroll bars...

A copy of Go's archive/tar packge was vendored with a patch applied to
mitigate CVE-2019-14271. Vendoring standard library packages is not
supported by Go in module-aware mode, which is getting in the way of
maintenance. A different approach to mitigate the vulnerability is
needed which does not involve vendoring parts of the standard library.

glibc implements name service lookups such as users, groups and DNS
using a scheme known as Name Service Switch. The services are
implemented as modules, shared libraries which glibc dynamically links
into the process the first time a function requiring the module is
called. This is the crux of the vulnerability: if a process linked
against glibc chroots, then calls one of the functions implemented with
NSS for the first time, glibc may load NSS modules out of the chrooted
filesystem.

The API underlying the `docker cp` command is implemented by forking a
new process which chroots into the container's rootfs and writes a tar
stream of files from the container over standard output. It utilizes the
Go standard library's archive/tar package to write the tar stream. It
makes use of the tar.FileInfoHeader function to construct a tar.Header
value from an fs.FileInfo value. In modern versions of Go on *nix
platforms, FileInfoHeader will attempt to resolve the file's UID and GID
to their respective user and group names by calling the os/user
functions LookupId and LookupGroupId. The cgo implementation of os/user
on *nix performs lookups by calling the corresponding libc functions. So
when linked against glibc, calls to tar.FileInfoHeader after the
process has chrooted into the container's rootfs can have the side
effect of loading NSS modules from the container! Without any
mitigations, a malicious container image author can trivially get
arbitrary code execution by leveraging this vulnerability and escape the
chroot (which is not a sandbox) into the host.

Mitigate the vulnerability without patching or forking archive/tar by
hiding the OS-dependent file info from tar.FileInfoHeader which it needs
to perform the lookups. Without that information available it falls back
to populating the tar.Header with only the information obtainable
directly from the FileInfo value without making any calls into os/user.

Fixes moby#42402

Signed-off-by: Cory Snider <csnider@mirantis.com>
(cherry picked from commit e9bbc41)
Signed-off-by: Cory Snider <csnider@mirantis.com>
The recently-upgraded gosec linter has a rule for archive extraction
code which may be vulnerable to directory traversal attacks, a.k.a. Zip
Slip. Gosec's detection is unfortunately prone to false positives,
however: it flags any filepath.Join call with an argument derived from a
tar.Header value, irrespective of whether the resultant path is used for
filesystem operations or if directory traversal attacks are guarded
against.

All of the lint errors reported by gosec appear to be false positives.

Signed-off-by: Cory Snider <csnider@mirantis.com>
(cherry picked from commit 833139f)
Signed-off-by: Cory Snider <csnider@mirantis.com>
Finish cherry-picking the remaining part of
65e1adc which was not included in
commit 432fbc8.

Signed-off-by: Cory Snider <csnider@mirantis.com>
@corhere corhere force-pushed the backport-20.10/safer-fileinfo branch from 6c3e402 to 6c523aa Compare October 23, 2023 18:46
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@corhere corhere merged commit ea4eb73 into moby:20.10 Oct 23, 2023
1 of 2 checks passed
@corhere corhere deleted the backport-20.10/safer-fileinfo branch October 23, 2023 19:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants