Skip to content

fix(libcontainer): check proc-safety on the resolved mountpoint - #3846

Merged
utam0k merged 2 commits into
youki-dev:mainfrom
saku3:harden-rootfs
Nov 29, 2026
Merged

utam0k merged 2 commits into
youki-dev:mainfrom
saku3:harden-rootfs

Conversation

@saku3

@saku3 saku3 commented Oct 25, 2026

Copy link
Copy Markdown
Member

Description

Previously, check_proc_mount, which ensures that mounts targeting /proc are performed safely, was only called for proc and sysfs mounts.
This change applies check_proc_mount to all mounts handled by mount_into_container, using the resolved mount destination to detect mounts targeting /proc, including those redirected through symlinks.

The implementation is based on the following code in runc.

https://github.com/opencontainers/runc/blob/7f0569a822242e25ba8d4980da865d4dfd0301b7/libcontainer/rootfs_linux.go#L580

The fallback legacy_mount path has also been updated to mount using the already-validated file descriptor for mount(2), rather than resolving the mount destination again.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test updates
  • CI/CD related changes
  • Other (please describe):

Testing

  • Added new unit tests
  • Added new integration tests
  • Ran existing test suite
  • Tested manually (please provide steps)

Related Issues

Fixes #

Additional Context

Signed-off-by: Yusuke Sakurai <yusuke.sakurai@3-shake.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Bind-source validation can inspect a different object from the pinned descriptor used for mounting, leaving a security bypass.

1 open issue
What changed in this PR

This PR hardens libcontainer mount handling by checking resolved destinations for /proc safety, including mounts redirected through symlinks.

Changes:

  • Applies proc-safety checks to all mounts handled by mount_into_container and rejects destinations outside or at the rootfs.
  • Reuses the validated destination descriptor for legacy mount(2).
  • Adds unit and integration tests for symlink-directed mounts.
File Description
tests/​contest/​contest/​src/​tests/​prohibit_symlink/​prohibit_symlink_test.rs Adds rejection tests for bind mounts redirected to /proc, beneath it, or to the rootfs.
crates/​libcontainer/​src/​rootfs/​mount.rs Validates resolved mount destinations, reuses the destination descriptor, and adds regression tests.

Review effort: Balanced

Comment thread crates/libcontainer/src/rootfs/mount.rs Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Security-sensitive mount validation needs human review and privileged integration testing, and a procfs bind-mount compatibility regression remains unresolved.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment thread crates/libcontainer/src/rootfs/mount.rs Outdated
}

self.check_proc_mount(options.root, mount)?;
self.check_proc_mount(options.root, &dest_path, mount, None)?;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I've removed it.

Comment thread crates/libcontainer/src/rootfs/mount.rs Outdated
root: &Root,
container_dest: &Path,
typ: Option<&str>,
dest_fd: BorrowedFd,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It is sufficiently expressed by the type.

Suggested change
dest_fd: BorrowedFd,
dest: BorrowedFd,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The same applies to src_fd.

@utam0k utam0k left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd like to know the performance impact. Do you have any data on this, or could you run some tests?

@saku3

saku3 commented Nov 28, 2026

Copy link
Copy Markdown
Member Author

@utam0k
Since this change is intended to address a security concern, are you primarily looking to identify potential optimization opportunities, or would a performance regression be a reason not to merge this change?

@saku3

saku3 commented Nov 28, 2026

Copy link
Copy Markdown
Member Author

Rather than requesting performance benchmarks on individual PRs, I think we should consider introducing automated performance regression testing in CI. This would allow us to consistently evaluate the performance impact of changes without requiring manual benchmarking each time.

@utam0k

utam0k commented Nov 28, 2026

Copy link
Copy Markdown
Member

@saku3 I'll make a decision based on the results. Isn't it already included in the CI? It hasn't been used in so long that I'm not even sure if it still works...

@utam0k

utam0k commented Nov 28, 2026

Copy link
Copy Markdown
Member

!github easy-benchmark

@utam0k

utam0k commented Nov 29, 2026

Copy link
Copy Markdown
Member

/benchmark

@github-actions

Copy link
Copy Markdown
Contributor

⏱️ Execution time benchmark

  • base: c450878e37c658e677a891db58c9e4f11122b602 (merge base)
  • pr: 76b8bc224c81014b3cc4e3c6f646c02f2fec942d
Command Mean Wall Time [ms] Change Factor
base 23.3 ± 2.9
pr 23.3 ± 2.0 +0.1%

Two builds of the same code differ by up to 3% here, so treat a smaller change as noise.

Workflow run

@utam0k

utam0k commented Nov 29, 2026

Copy link
Copy Markdown
Member

⏱️ Execution time benchmark

  • base: c450878e37c658e677a891db58c9e4f11122b602 (merge base)
  • pr: 76b8bc224c81014b3cc4e3c6f646c02f2fec942d

Command Mean Wall Time [ms] Change Factor
base 23.3 ± 2.9
pr 23.3 ± 2.0 +0.1%
Two builds of the same code differ by up to 3% here, so treat a smaller change as noise.

Workflow run

NP 💯

@utam0k

utam0k commented Nov 29, 2026

Copy link
Copy Markdown
Member

/lgtm with nits

Signed-off-by: Yusuke Sakurai <yusuke.sakurai@3-shake.com>
@saku3

saku3 commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

@utam0k
Thanks for the review!
I've removed the _fd suffix from the variable names you pointed out.

@saku3
saku3 requested a review from utam0k November 29, 2026 03:44
@utam0k
utam0k merged commit cf29d47 into youki-dev:main Nov 29, 2026
34 checks passed
@youki-dev-bot youki-dev-bot Bot mentioned this pull request Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants