Skip to content

Commit e5b5970

Browse files
authored
Merge pull request #262 from ondrejbudai/selinux-shortcut
lsm: exit early if the process already has install_t
2 parents 0c47374 + 68dbdba commit e5b5970

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lib/src/lsm.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ impl Drop for SetEnforceGuard {
8484
#[context("Ensuring selinux install_t type")]
8585
#[cfg(feature = "install")]
8686
pub(crate) fn selinux_ensure_install_or_setenforce() -> Result<Option<SetEnforceGuard>> {
87+
// If the process already has install_t, exit early
88+
if self_has_install_t()? {
89+
return Ok(None);
90+
}
8791
selinux_ensure_install()?;
8892
let current = std::fs::read_to_string("/proc/self/attr/current")
8993
.context("Reading /proc/self/attr/current")?;
@@ -170,3 +174,10 @@ pub(crate) fn xattrs_have_selinux(xattrs: &ostree::glib::Variant) -> bool {
170174
}
171175
false
172176
}
177+
178+
fn self_has_install_t() -> Result<bool> {
179+
let current = std::fs::read_to_string("/proc/self/attr/current")
180+
.context("Reading /proc/self/attr/current")?;
181+
182+
Ok(current.contains("install_t"))
183+
}

0 commit comments

Comments
 (0)