Skip to content

Fix for host mount ns containers#3996

Merged
lifubang merged 2 commits intoopencontainers:mainfrom
kolyshkin:double-hooks
Aug 29, 2023
Merged

Fix for host mount ns containers#3996
lifubang merged 2 commits intoopencontainers:mainfrom
kolyshkin:double-hooks

Conversation

@kolyshkin
Copy link
Copy Markdown
Contributor

@kolyshkin kolyshkin commented Aug 26, 2023

If the container does not have own mount namespace configured (i.e. it shares the mount namespace with the host), its "prestart" (obsoleted) and "createRuntime" hooks are called twice, and its cgroups and Intel RDT settings are also applied twice.

The code being removed was originally added by commit 2f27649 ("Move pre-start hooks after container mounts", Feb 17 2016). At that time, the syncParentHooks() was called from setupRootfs(), which was only used when the container config has mount namespace (NEWNS) enabled.

Later, commit 244c9fc ("*: console rewrite", Jun 4 2016) spli the relevant part of setupRootfs() into prepareRootfs(). It was still called conditionally (only if mount namespace was enabled).

Finally, commit 91ca331 ("chroot when no mount namespaces is provided", Jan 25 2018) removed the above condition, meaning prepareRootfs(), and thus syncParentHooks(), is now called for any container.

Meaning, the special case for when mount namespace is not enabled is no longer needed.

Remove it.

Add a test case.

@kolyshkin

This comment was marked as outdated.

@kolyshkin
Copy link
Copy Markdown
Contributor Author

OK I think I have a test case now. Let's see if it works in CI.

@kolyshkin kolyshkin marked this pull request as draft August 26, 2023 03:07
@kolyshkin kolyshkin force-pushed the double-hooks branch 2 times, most recently from d96e8f9 to c7bab9e Compare August 28, 2023 19:30
@kolyshkin kolyshkin marked this pull request as ready for review August 28, 2023 19:41
If the container does not have own mount namespace configured (i.e. it
shares the mount namespace with the host), its "prestart" (obsoleted)
and "createRuntime" hooks are called twice, and its cgroups and Intel
RDT settings are also applied twice.

The code being removed was originally added by commit 2f27649 ("Move
pre-start hooks after container mounts", Feb 17 2016). At that time,
the syncParentHooks() was called from setupRootfs(), which was only
used when the container config has mount namespace (NEWNS) enabled.

Later, commit 244c9fc ("*: console rewrite", Jun 4 2016) spli
the relevant part of setupRootfs() into prepareRootfs(). It was still
called conditionally (only if mount namespace was enabled).

Finally, commit 91ca331 ("chroot when no mount namespaces is
provided", Jan 25 2018) removed the above condition, meaning
prepareRootfs(), and thus syncParentHooks(), is now called for any
container.

Meaning, the special case for when mount namespace is not enabled is no
longer needed.

Remove it.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Copy link
Copy Markdown
Member

@lifubang lifubang left a comment

Choose a reason for hiding this comment

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

👍

@lifubang lifubang merged commit 24ae5c2 into opencontainers:main Aug 29, 2023
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.

3 participants