Skip to content

Commit 841d831

Browse files
committed
install: Always mount selinuxfs *before* install_t re-execution
My changes to ensure `install_t` actually re-broke the labeling on `/etc`, because we were mounting selinuxfs *after* the re-exec. Reorder and clean up things so that we always do the mount before the re-exec for install_t. Signed-off-by: Colin Walters <[email protected]>
1 parent e2dc1ca commit 841d831

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

lib/src/install.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,13 @@ pub(crate) async fn install(opts: InstallOpts) -> Result<()> {
657657
let host_selinux = crate::lsm::selinux_enabled()?;
658658
tracing::debug!("Target has SELinux, host={host_selinux}");
659659
if host_selinux {
660+
// /sys/fs/selinuxfs is not normally mounted, so we do that now.
661+
// Because SELinux enablement status is cached process-wide and was very likely
662+
// already queried by something else (e.g. glib's constructor), we would also need
663+
// to re-exec. But, selinux_ensure_install does that unconditionally right now too,
664+
// so let's just fall through to that.
665+
crate::lsm::container_setup_selinux()?;
666+
// This will re-execute the current process (once).
660667
crate::lsm::selinux_ensure_install()?;
661668
} else if opts.disable_selinux {
662669
override_disable_selinux = true;
@@ -670,13 +677,6 @@ pub(crate) async fn install(opts: InstallOpts) -> Result<()> {
670677
tracing::debug!("Target does not enable SELinux");
671678
}
672679

673-
// Because SELinux enablement status is cached process-wide and was very likely
674-
// already queried by something else (e.g. glib's constructor), we need to mount
675-
// selinuxfs now if needed, then re-exec *again*.
676-
if srcdata.selinux && !override_disable_selinux {
677-
crate::lsm::container_setup_selinux()?;
678-
}
679-
680680
// Create our global (read-only) state which gets wrapped in an Arc
681681
// so we can pass it to worker threads too. Right now this just
682682
// combines our command line options along with some bind mounts from the host.

lib/src/lsm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ pub(crate) fn container_setup_selinux() -> Result<()> {
6060
let path = Utf8Path::new(SELINUXFS);
6161
if !path.join("enforce").exists() {
6262
if !path.exists() {
63+
tracing::debug!("Creating {path}");
6364
std::fs::create_dir(path)?;
6465
}
6566
Task::new("Mounting selinuxfs", "mount")
6667
.args(["selinuxfs", "-t", "selinuxfs", path.as_str()])
6768
.run()?;
6869
}
69-
70-
selinux_ensure_install()
70+
Ok(())
7171
}
7272

7373
fn selinux_label_for_path(target: &str) -> Result<String> {

0 commit comments

Comments
 (0)