Skip to content

Commit 68dbdba

Browse files
committed
lsm: exit early if the process already has install_t
There's no need to perform any additional steps if the bootc process already has install_t. Signed-off-by: Ondřej Budai <[email protected]>
1 parent 0c47374 commit 68dbdba

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)