Skip to content

fix: copy relative symlinks correctly between stages (release-4.1) #3031

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

Merged
merged 1 commit into from
Jun 20, 2024

Conversation

cstangeyanez
Copy link
Contributor

@cstangeyanez cstangeyanez commented Jun 20, 2024

cherry pick #2924

In a build stage, a valid relative symlink can be created that points to a location in the rootfs that is above the location of the symlink. E.g.:

/usr/mydir/mysubdir/true -> ../../../bin/true

This symlink is valid in the rootfs. It resolves to /bin/true.

If we attempt to copy /usr/mydir into a new build stage, then prior to this PR the symlink would cause the copy to fail.

We have been using CopyFromTar to copy from src <stage1>/usr/mydir, to <stage2>/usr/mydir. The CopyFromTar routines enforce that the target of a hard link or symlink must be under dst, or a fatal error is raised to avoid a breakout attack.

When copying between stages our boundary is not dst, but the top level of the destination stage's rootfs. We must allow links to be created that are above dst, but within the stage rootfs.

To resolve the issue, bring over enough code from
docker/docker/pkg/archive that we can implement a CopyFromTarWithRoot, that performs the same as CopyFromTar, except that we can specify a destination root directory. Any hard links and symlink targets under this destination root directory are valid.

Fixes #2607

@cstangeyanez cstangeyanez added this to the Singularity CE 4.1.4 milestone Jun 20, 2024
@cstangeyanez cstangeyanez requested a review from dtrudg June 20, 2024 13:55
@cstangeyanez cstangeyanez mentioned this pull request Jun 20, 2024
4 tasks
@cstangeyanez
Copy link
Contributor Author

Failure due to ubuntu keyserver timeout

Copy link
Member

@dtrudg dtrudg left a comment

Choose a reason for hiding this comment

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

LGTM - Needs to be rebased for CHANGELOG.md.

cherry pick sylabs#2924

In a build stage, a valid relative symlink can be created that points to a
location in the rootfs that is above the location of the symlink. E.g.:

  /usr/mydir/mysubdir/true -> ../../../bin/true

This symlink is valid in the rootfs. It resolves to `/bin/true`.

If we attempt to copy `/usr/mydir` into a new build stage, then prior to
this PR the symlink would cause the copy to fail.

We have been using `CopyFromTar` to copy from src `<stage1>/usr/mydir`,
to `<stage2>/usr/mydir`. The `CopyFromTar` routines enforce that the
target of a hard link or symlink must be under dst, or a fatal error is
raised to avoid a breakout attack.

When copying between stages our boundary is not dst, but the top level
of the destination stage's rootfs. We must allow links to be created
that are above dst, but within the stage rootfs.

To resolve the issue, bring over enough code from
`docker/docker/pkg/archive` that we can implement a
`CopyFromTarWithRoot`, that performs the same as `CopyFromTar`, except
that we can specify a destination root directory. Any hard links and
symlink targets under this destination root directory are valid.

Fixes sylabs#2607
@dtrudg dtrudg merged commit bd4b302 into sylabs:release-4.1 Jun 20, 2024
1 check failed
@cstangeyanez cstangeyanez deleted the pick2924 branch June 28, 2024 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants