Skip to content

Commit 380b243

Browse files
committed
lsm: Add an API to set SELinux permissive
This is going to be needed for takeover installs. There's no point to trying to keep the LSM state running through the whole thing because we're going to replace the OS anyways. Signed-off-by: Colin Walters <[email protected]>
1 parent a63deaf commit 380b243

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

lib/src/lsm.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::fs::File;
2+
use std::io::Write;
13
use std::os::unix::process::CommandExt;
24
use std::path::Path;
35
use std::process::Command;
@@ -79,6 +81,20 @@ pub(crate) fn container_setup_selinux() -> Result<()> {
7981
Ok(())
8082
}
8183

84+
#[context("Setting SELinux permissive mode")]
85+
#[allow(dead_code)]
86+
#[cfg(feature = "install")]
87+
pub(crate) fn selinux_set_permissive() -> Result<()> {
88+
let enforce_path = &Utf8Path::new(SELINUXFS).join("enforce");
89+
if !enforce_path.exists() {
90+
return Ok(());
91+
}
92+
let mut f = File::open(enforce_path)?;
93+
f.write_all(b"0")?;
94+
tracing::debug!("Set SELinux permissive mode");
95+
Ok(())
96+
}
97+
8298
fn selinux_label_for_path(target: &str) -> Result<String> {
8399
// TODO: detect case where SELinux isn't enabled
84100
let o = Command::new("matchpathcon").args(["-n", target]).output()?;

0 commit comments

Comments
 (0)