Skip to content

Commit 29874ce

Browse files
zulinx86Manciukic
authored andcommitted
jailer: Better error message for failure of moving to cgroup
If no --cgroup parameters are specified and --cgroup-version=2 is passed, the jailer moves the process to the cgroup specified with --parent-cgroup rather than creating a cgroup under it, contrary to its name. This move fails if the destination cgroup has domain controllers (e.g. memory) enabled in cgroup.subtree_control, which is called "no internal process constraint [1]. [1]: https://docs.kernel.org/admin-guide/cgroup-v2.html#no-internal-process-constraint Signed-off-by: Takahiro Itazuri <[email protected]>
1 parent 87a2255 commit 29874ce

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/jailer/src/env.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ impl Env {
218218
let cg_parent_procs = cg_parent.join("cgroup.procs");
219219
if cg_parent.exists() {
220220
fs::write(cg_parent_procs, std::process::id().to_string())
221-
.map_err(|_| JailerError::CgroupWrite(io::Error::last_os_error()))?;
221+
.map_err(|_| JailerError::CgroupMove(cg_parent, io::Error::last_os_error()))?;
222222
}
223223
}
224224

src/jailer/src/main.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,11 @@ pub enum JailerError {
4343
CgroupInvalidVersion(String),
4444
#[error("Parent cgroup path is invalid. Path should not be absolute or contain '..' or '.'")]
4545
CgroupInvalidParentPath(),
46-
#[error("Failed to write to cgroups file: {0}")]
47-
CgroupWrite(io::Error),
46+
#[error(
47+
"Failed to move process to cgroup ({0}): {1}.\nHint: If you intended to create a child \
48+
cgroup under {0}, pass any --cgroup parameters."
49+
)]
50+
CgroupMove(PathBuf, io::Error),
4851
#[error("Failed to change owner for {0}: {1}")]
4952
ChangeFileOwner(PathBuf, io::Error),
5053
#[error("Failed to chdir into chroot directory: {0}")]

0 commit comments

Comments
 (0)