Skip to content

fix: don't wedge deployment finalization on SELinux policy refresh - #3649

Open
HuntedRaven7 wants to merge 6 commits into
ostreedev:mainfrom
HuntedRaven7:main
Open

HuntedRaven7 wants to merge 6 commits into
ostreedev:mainfrom
HuntedRaven7:main

Conversation

@HuntedRaven7

Copy link
Copy Markdown

The /etc merge can carry stale or incomplete libsemanage state into new deployments (e.g. leftover tmp/ transaction directories from an interrupted image build, or orphaned policy modules), after which every semodule run fails and ostree-finalize-staged permanently wedges all updates until the module store is repaired manually.

Prune stale tmp/ transaction state under each policy store before running semodule, and treat refresh failures as non-fatal: log loudly to the journal and stderr, then finalize the deployment with the previously built binary policy carried over via /etc.

Closes #3563

…ilures

The /etc merge can carry stale or incomplete libsemanage state into new
deployments (e.g. leftover tmp/ transaction directories from an interrupted
image build, or orphaned policy modules), after which every semodule run
fails and ostree-finalize-staged permanently wedges all updates until the
module store is repaired manually.

Prune stale tmp/ transaction state under each policy store before running
semodule, and treat refresh failures as non-fatal: log loudly to the
journal and stderr, then finalize the deployment with the previously built
binary policy carried over via /etc.

Closes ostreedev#3563
@HuntedRaven7

Copy link
Copy Markdown
Author

strange the clang stuff fails but the files I changed pass.

@alexvarming

alexvarming commented Oct 21, 2026 •

Copy link
Copy Markdown

Another case this fixes: an image with only a compiled SELinux policy and no libsemanage module store. It's common on embedded builds (Yocto refpolicy here), where local policy modules are never wanted. /etc/selinux/config exists and semodule has --refresh, so OSTree runs semodule -N --refresh in the new deployment, which fails without a store, and the deployment can't be finalized.

For now we carry a small patch in sysroot_finalize_selinux_policy(): it reads SELINUXTYPE from the deployment's /etc/selinux/config, and skips the refresh when /etc/selinux/<SELINUXTYPE>/active doesn't exist. A store under /var/lib/selinux isn't reachable from the deployment sandbox anyway.

One thing for the dry-run-at-stage idea in #3563: without a store, a dry run fails as well, so those images would refuse every update. Whichever way this goes, skipping the refresh when there's no store keeps them working. Happy to send that check as its own PR if it's wanted.

- Use glnx_file_get_contents_utf8_at() correctly (it returns the
  contents and takes out_len as its third argument).
- Replace g_auto(GString)/G_STRING_INIT with g_autoptr(GString) and
  g_string_new(), which is available with the project's minimum GLib.
- Drop the unused new_upstream_exists variable, and handle files that
  are gone from the new policy store so the cleanup actually works.
- Reformat the clang-format-only changes with clang-format 18, the
  version used by CI.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

/etc merge during deployment finalization creating invalid SELinux policy

2 participants