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

rootfs: handle nested procfs mounts for MS_MOVE #2647

Merged
merged 1 commit into from
Oct 19, 2020
Merged

rootfs: handle nested procfs mounts for MS_MOVE #2647

merged 1 commit into from
Oct 19, 2020

Conversation

cyphar
Copy link
Member

@cyphar cyphar commented Oct 13, 2020

In a case where the host /proc mount has already been overmounted, the
MS_MOVE handling would get ENOENT when trying to hide (for instance)
"/proc/bus" because it had already hidden away "/proc". This revealed
two issues in the previous implementation of this hardening feaure:

  1. No checks were done to make sure the mount was a "full" mount (it is
    a mount of the root of the filesystem), but the kernel doesn't permit
    a non-full mount to be converted to a full mount (for reference, see
    mnt_already_visible). This just removes extra busy-work during setup.

  2. ENOENT was treated as a critical error, even though it actually
    indicates the mount doesn't exist and thus isn't a problem. A more
    theoretically pure solution would be to store the set of mountpoints
    to be hidden and only ignore the error if an ancestor directory of
    the current mountpoint was already hidden, but that would just add
    complexity with little justification.

In addition, better document the reasoning behind this logic so that
folks aren't confused when looking at it.

Fixes #2639
Fixes: 28a697c ("rootfs: umount all procfs and sysfs with --no-pivot")
Signed-off-by: Aleksa Sarai [email protected]

@cyphar
Copy link
Member Author

cyphar commented Oct 13, 2020

/cc @giuseppe Does this change make sense to you?

giuseppe
giuseppe previously approved these changes Oct 13, 2020
Copy link
Member

@giuseppe giuseppe left a comment

Choose a reason for hiding this comment

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

just a nit, otherwise the change makes sense to me. Thanks!

libcontainer/rootfs_linux.go Outdated Show resolved Hide resolved
@kolyshkin
Copy link
Contributor

LGTM except for a single nit.

In a case where the host /proc mount has already been overmounted, the
MS_MOVE handling would get ENOENT when trying to hide (for instance)
"/proc/bus" because it had already hidden away "/proc". This revealed
two issues in the previous implementation of this hardening feaure:

1. No checks were done to make sure the mount was a "full" mount (it is
   a mount of the root of the filesystem), but the kernel doesn't permit
   a non-full mount to be converted to a full mount (for reference, see
   mnt_already_visible). This just removes extra busy-work during setup.

2. ENOENT was treated as a critical error, even though it actually
   indicates the mount doesn't exist and thus isn't a problem. A more
   theoretically pure solution would be to store the set of mountpoints
   to be hidden and only ignore the error if an ancestor directory of
   the current mountpoint was already hidden, but that would just add
   complexity with little justification.

In addition, better document the reasoning behind this logic so that
folks aren't confused when looking at it.

Fixes: 28a697c ("rootfs: umount all procfs and sysfs with --no-pivot")
Signed-off-by: Aleksa Sarai <[email protected]>
Copy link
Contributor

@kolyshkin kolyshkin left a comment

Choose a reason for hiding this comment

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

LGTM

@kolyshkin
Copy link
Contributor

@AkihiroSuda PTAL

@mrunalp mrunalp merged commit 7ba005b into opencontainers:master Oct 19, 2020
@cyphar cyphar deleted the procfs-masking-nested branch October 20, 2020 00:43
AkihiroSuda added a commit that referenced this pull request Oct 20, 2020
This reverts commit b8bf572.

Revert #2647
Reopen #2339

Signed-off-by: Akihiro Suda <[email protected]>
cyphar added a commit to cyphar/moby-sys that referenced this pull request Oct 20, 2020
Previously, the filter would be run before all of the fields were parsed
(this behaviour also was not documented) -- this resulted in users of
the function accidentally assuming that fields like fsinfo.Root would
actually be filled correctly. It seems that the performance overhead of
parsing a few extra fields is not exorbitant, and optimising this just
leads to incorrect user code.

For a concrete example, this optimisation actually made this runc
change[1] regress a security hardening feature because it relied on
fsinfo.Root being filled correctly.

[1]: opencontainers/runc#2647

Signed-off-by: Aleksa Sarai <[email protected]>
AkihiroSuda added a commit that referenced this pull request Oct 20, 2020
For preventing regression like #2647

Signed-off-by: Akihiro Suda <[email protected]>
cyphar added a commit to cyphar/moby-sys that referenced this pull request Oct 21, 2020
Previously, the filter would be run before all of the fields were parsed
(this behaviour also was not documented) -- this resulted in users of
the function accidentally assuming that fields like fsinfo.Root would
actually be filled correctly. It seems that the performance overhead of
parsing a few extra fields is not exorbitant, and optimising this just
leads to incorrect user code.

For a concrete example, this optimisation actually made this runc
change[1] regress a security hardening feature because it relied on
fsinfo.Root being filled correctly.

[1]: opencontainers/runc#2647

Signed-off-by: Aleksa Sarai <[email protected]>
kolyshkin pushed a commit to kolyshkin/runc that referenced this pull request Oct 22, 2020
For preventing regression like opencontainers#2647

Signed-off-by: Akihiro Suda <[email protected]>
Signed-off-by: Aleksa Sarai <[email protected]>
kolyshkin pushed a commit to kolyshkin/runc that referenced this pull request Oct 22, 2020
For preventing regression like opencontainers#2647

Signed-off-by: Akihiro Suda <[email protected]>
Signed-off-by: Aleksa Sarai <[email protected]>
Signed-off-by: Kir Kolyshkin <[email protected]>
kolyshkin pushed a commit to kolyshkin/runc that referenced this pull request Oct 22, 2020
For preventing regression like opencontainers#2647

Signed-off-by: Akihiro Suda <[email protected]>
Signed-off-by: Aleksa Sarai <[email protected]>
Signed-off-by: Kir Kolyshkin <[email protected]>
dqminh pushed a commit to dqminh/runc that referenced this pull request Feb 3, 2021
For preventing regression like opencontainers#2647

Signed-off-by: Akihiro Suda <[email protected]>
Signed-off-by: Aleksa Sarai <[email protected]>
Signed-off-by: Kir Kolyshkin <[email protected]>
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.

process_linux.go:297: applying cgroup configuration for process: read-only file system
4 participants