Skip to content

rootfs: handle nested procfs mounts for MS_MOVE#2647

Merged
mrunalp merged 1 commit intoopencontainers:masterfrom
cyphar:procfs-masking-nested
Oct 19, 2020
Merged

rootfs: handle nested procfs mounts for MS_MOVE#2647
mrunalp merged 1 commit intoopencontainers:masterfrom
cyphar:procfs-masking-nested

Conversation

@cyphar
Copy link
Copy Markdown
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 cyphar@cyphar.com

@cyphar
Copy link
Copy Markdown
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
Copy Markdown
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!

@kolyshkin
Copy link
Copy Markdown
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 <cyphar@cyphar.com>
Copy link
Copy Markdown
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
Copy Markdown
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 <akihiro.suda.cz@hco.ntt.co.jp>
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 <cyphar@cyphar.com>
AkihiroSuda added a commit that referenced this pull request Oct 20, 2020
For preventing regression like #2647

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
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 <cyphar@cyphar.com>
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 <akihiro.suda.cz@hco.ntt.co.jp>
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
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 <akihiro.suda.cz@hco.ntt.co.jp>
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
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 <akihiro.suda.cz@hco.ntt.co.jp>
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
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 <akihiro.suda.cz@hco.ntt.co.jp>
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
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