Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@vvoland
Copy link
Contributor

@vvoland vvoland commented Aug 18, 2023

- What I did
Use refcounted mounter introduced in #45698 when doing diff and export. This is to reuse already mounted rootfs of a container and avoid breaking overlay by mounting an workdir layer as a lowerdir of other mounts.

Also added an integration test to verify.

- How I did it
See individual commits.

- How to verify it

$ make DOCKER_GRAPHDRIVER=overlayfs TEST_INTEGRATION_USE_SNAPSHOTTER=1 TEST_FILTER='TestOverlayfs' test-integration
Test with #45698 reverted
INFO: Testing against a local daemon
=== RUN   TestOverlayfs
=== RUN   TestOverlayfs/diff
    overlayfs_test.go:80: diff caused overlayfs kernel warning: <4>[520803.140901] overlayfs: lowerdir is in-use as upperdir/workdir of another mount, accessing files from both mounts will result in undefined behavior.
=== RUN   TestOverlayfs/export
    overlayfs_test.go:80: export caused overlayfs kernel warning: <4>[520803.156318] overlayfs: upperdir is in-use as upperdir/workdir of another mount, accessing files from both mounts will result in undefined behavior.
    overlayfs_test.go:80: export caused overlayfs kernel warning: <4>[520803.156462] overlayfs: workdir is in-use as upperdir/workdir of another mount, accessing files from both mounts will result in undefined behavior.
=== RUN   TestOverlayfs/cp_to_container
    overlayfs_test.go:80: cp to container caused overlayfs kernel warning: <4>[520803.177945] overlayfs: upperdir is in-use as upperdir/workdir of another mount, accessing files from both mounts will result in undefined behavior.
    overlayfs_test.go:80: cp to container caused overlayfs kernel warning: <4>[520803.178382] overlayfs: workdir is in-use as upperdir/workdir of another mount, accessing files from both mounts will result in undefined behavior.
=== RUN   TestOverlayfs/cp_from_container
    overlayfs_test.go:80: cp from container caused overlayfs kernel warning: <4>[520803.193088] overlayfs: upperdir is in-use as upperdir/workdir of another mount, accessing files from both mounts will result in undefined behavior.
    overlayfs_test.go:80: cp from container caused overlayfs kernel warning: <4>[520803.193471] overlayfs: workdir is in-use as upperdir/workdir of another mount, accessing files from both mounts will result in undefined behavior.
--- FAIL: TestOverlayfs (1.07s)
    --- FAIL: TestOverlayfs/diff (0.02s)
    --- FAIL: TestOverlayfs/export (0.02s)
    --- FAIL: TestOverlayfs/cp_to_container (0.02s)
    --- FAIL: TestOverlayfs/cp_from_container (0.02s)
FAIL
Before this PR
INFO: Testing against a local daemon
=== RUN   TestOverlayfs
=== RUN   TestOverlayfs/diff
    overlayfs_test.go:80: diff caused overlayfs kernel warning: <4>[520341.301322] overlayfs: lowerdir is in-use as upperdir/workdir of another mount, accessing files from both mounts will result in undefined behavior.
=== RUN   TestOverlayfs/export
    overlayfs_test.go:80: export caused overlayfs kernel warning: <4>[520341.314918] overlayfs: upperdir is in-use as upperdir/workdir of another mount, accessing files from both mounts will result in undefined behavior.
    overlayfs_test.go:80: export caused overlayfs kernel warning: <4>[520341.315250] overlayfs: workdir is in-use as upperdir/workdir of another mount, accessing files from both mounts will result in undefined behavior.
=== RUN   TestOverlayfs/cp_to_container
=== RUN   TestOverlayfs/cp_from_container
--- FAIL: TestOverlayfs (1.02s)
    --- FAIL: TestOverlayfs/diff (0.02s)
    --- FAIL: TestOverlayfs/export (0.02s)
    --- PASS: TestOverlayfs/cp_to_container (0.01s)
    --- PASS: TestOverlayfs/cp_from_container (0.01s)
FAIL
After this PR
INFO: Testing against a local daemon
=== RUN   TestOverlayfs
=== RUN   TestOverlayfs/diff
=== RUN   TestOverlayfs/export
=== RUN   TestOverlayfs/cp_to_container
=== RUN   TestOverlayfs/cp_from_container
--- PASS: TestOverlayfs (1.07s)
    --- PASS: TestOverlayfs/diff (0.04s)
    --- PASS: TestOverlayfs/export (0.02s)
    --- PASS: TestOverlayfs/cp_to_container (0.01s)
    --- PASS: TestOverlayfs/cp_from_container (0.01s)
PASS

DONE 5 tests in 3.427s

- Description for the changelog

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

Check that operations that could potentially perform overlayfs mounts
that could cause undefined behaviors.

Signed-off-by: Paweł Gronowski <[email protected]>
(cherry picked from commit 303e2b1)
Signed-off-by: Paweł Gronowski <[email protected]>
To prevent mounting the container rootfs in a rw mode if it's already
mounted.  This can't use `mount.WithReadonlyTempMount` because the
archive code does a chroot with a pivot_root, which creates a new
directory in the rootfs.

Signed-off-by: Paweł Gronowski <[email protected]>
(cherry picked from commit 051d51b)
Signed-off-by: Paweł Gronowski <[email protected]>
The container rw layer may already be mounted, so it's not safe to use
it in another overlay mount. Use the ref counted mounter (which will
reuse the existing mount if it exists) to avoid that.

Also, mount the parent mounts (layers of the base image) in a read-only
mode.

Signed-off-by: Paweł Gronowski <[email protected]>
(cherry picked from commit 6da42ca)
Signed-off-by: Paweł Gronowski <[email protected]>
@vvoland vvoland added area/runtime Runtime kind/bugfix PR's that fix bugs labels Aug 18, 2023
@vvoland vvoland added this to the 24.0.6 milestone Aug 18, 2023
@thaJeztah thaJeztah added status/2-code-review containerd-integration Issues and PRs related to containerd integration labels Aug 18, 2023
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

@vvoland vvoland merged commit 2774296 into moby:24.0 Aug 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/runtime Runtime containerd-integration Issues and PRs related to containerd integration kind/bugfix PR's that fix bugs status/4-merge

Projects

Development

Successfully merging this pull request may close these issues.

3 participants