Repository navigation
fix(libcontainer): check proc-safety on the resolved mountpoint - #3846
Conversation
Signed-off-by: Yusuke Sakurai <yusuke.sakurai@3-shake.com>
There was a problem hiding this comment.
🟡 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_containerand 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
There was a problem hiding this comment.
🔵 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
| } | ||
|
|
||
| self.check_proc_mount(options.root, mount)?; | ||
| self.check_proc_mount(options.root, &dest_path, mount, None)?; |
| root: &Root, | ||
| container_dest: &Path, | ||
| typ: Option<&str>, | ||
| dest_fd: BorrowedFd, |
There was a problem hiding this comment.
It is sufficiently expressed by the type.
| dest_fd: BorrowedFd, | |
| dest: BorrowedFd, |
utam0k
left a comment
There was a problem hiding this comment.
I'd like to know the performance impact. Do you have any data on this, or could you run some tests?
|
@utam0k |
|
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. |
|
@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... |
|
!github easy-benchmark |
|
/benchmark |
⏱️ Execution time benchmark
Two builds of the same code differ by up to 3% here, so treat a smaller change as noise. |
NP 💯 |
|
/lgtm with nits |
Signed-off-by: Yusuke Sakurai <yusuke.sakurai@3-shake.com>
|
@utam0k |


Description
Previously,
check_proc_mount, which ensures that mounts targeting/procare performed safely, was only called forprocandsysfsmounts.This change applies
check_proc_mountto all mounts handled bymount_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_mountpath 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
Testing
Related Issues
Fixes #
Additional Context