Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use selinux.format_mount_label when formatting mount label #3034

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/libcontainer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ thiserror = "2.0.9"
tracing = { version = "0.1.41", features = ["attributes"] }
safe-path = "0.1.0"
nc = "0.9.5"
selinux = { path = "../../experiment/selinux" }

[dev-dependencies]
oci-spec = { version = "~0.7.1", features = ["proptests", "runtime"] }
Expand Down
3 changes: 2 additions & 1 deletion crates/libcontainer/src/process/container_init_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use oci_spec::runtime::{
IOPriorityClass, LinuxIOPriority, LinuxNamespaceType, LinuxSchedulerFlag, LinuxSchedulerPolicy,
Scheduler, Spec, User,
};
use selinux::selinux;

use super::args::{ContainerArgs, ContainerType};
use crate::error::MissingSpecError;
Expand Down Expand Up @@ -164,7 +165,7 @@ fn masked_path(path: &Path, mount_label: &Option<String>, syscall: &dyn Syscall)
}
SyscallError::Nix(nix::errno::Errno::ENOTDIR) => {
let label = match mount_label {
Some(l) => format!("context=\"{l}\""),
Some(l) => selinux::SELinux::format_mount_label("", l),
None => "".to_string(),
};
syscall
Expand Down
6 changes: 2 additions & 4 deletions crates/libcontainer/src/rootfs/mount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use nix::NixPath;
use oci_spec::runtime::{Mount as SpecMount, MountBuilder as SpecMountBuilder};
use procfs::process::{MountInfo, MountOptFields, Process};
use safe_path;
use selinux::selinux;

#[cfg(feature = "v1")]
use super::symlink::Symlink;
Expand Down Expand Up @@ -489,10 +490,7 @@ impl Mount {

if let Some(l) = label {
if typ != Some("proc") && typ != Some("sysfs") {
match mount_option_config.data.is_empty() {
true => d = format!("context=\"{l}\""),
false => d = format!("{},context=\"{}\"", mount_option_config.data, l),
}
d = selinux::SELinux::format_mount_label(&mount_option_config.data, l);
}
}

Expand Down
Loading