Skip to content

Review draft: ostreedev/ostree#3649: fix: don't wedge deployment finalization on SELinux policy refresh #862

Open

Description

@cgwalters-bot

This text was generated by an LLM (how cgwalters uses LLMs). cgwalters has not reviewed it yet.

PR: ostreedev/ostree#3649

pr = "ostreedev/ostree#3649"
head = "a0207f11818b46729249315399c87fe99d5e3f21"
event = "REQUEST_CHANGES"

Review

AI: Thanks for picking this up, and for the clear reproduction in #3563. Unfortunately I don't think this approach can go in as written, for a few reasons.

First, the PR doesn't build. The new code calls glnx_file_get_contents_utf8_at() with the wrong arguments and uses g_auto(GString) / G_STRING_INIT, which don't exist, so every SELinux-enabled build job fails. The clang-format job also fails, because the branch reformats unrelated code in ot-main.c, ostree-sysroot-upgrader.h and ostree-repo-finder-mount.c, apparently with a different clang-format version than the one CI uses. Please drop those hunks.

Second, I don't think the tmp/ pruning addresses the reported failure. libsemanage's semanage_make_sandbox() already deletes any existing <store>/tmp and re-copies active/ into it at the start of every transaction. So the tmp/modules/200/.../lang_ext path in the error is a fresh copy of an active/modules tree that is already incomplete. My best guess is that the real cause is the per-file 3-way /etc merge running over the module store. If one file in a module directory was modified locally and the others weren't, the merge can delete some files and keep others, which leaves a half-removed module in active/. Nothing in this PR touches active/.

Third, making the refresh failure non-fatal is the part I'm most worried about. The "previously built binary policy carried over via /etc" is whatever the merge kept in /etc/selinux/<type>/policy/. On any system where policy was ever rebuilt locally (a module install, or setsebool -P), that file is the user's modified copy built from the old image's policy. The new deployment would then boot with the old policy and none of the new image's policy changes. That's a silently stale or mismatched policy in enforcing mode. The only notice is a warning printed by ostree-finalize-staged during shutdown, where nobody will see it. Trading a visible "can't update" for a possibly unbootable or mislabeled system isn't a good trade. I'd rather keep this fatal and move detection earlier, as discussed in the issue: try a dry-run policy build when staging and refuse to stage if it fails, so the error reaches the user while they're watching. The longer-term fix is the /usr vs /etc split for image-provided modules.

A separate, smaller change that does seem worth taking is the one alexvarming described: skip the refresh when the deployment has no active module store for the configured SELINUXTYPE. Images with only a compiled policy can't usefully run semodule --refresh anyway. That should be its own PR, with a test.

There are no tests here. Any version of this needs at least a kola test that reproduces the broken-store case, e.g. by deleting one file from an active/modules/<prio>/<name> directory in /etc before staging. Please also rebase to drop the merge commits and squash the fixups into one logically described commit.

Comments

src/libostree/ostree-sysroot-deploy.c:3415

This stats and removes tmp relative to the /etc/selinux dirfd, so it's checking /etc/selinux/tmp, not /etc/selinux/<store>/tmp. Even with the path fixed, libsemanage removes and recreates the sandbox from active/ at the start of every transaction (semanage_make_sandbox()), so a leftover tmp/ can't cause the failure in #3563. I'd drop this function.

src/libostree/ostree-sysroot-deploy.c:3521

Execution only reaches this point when exists_in_new is false, i.e. new_upstream_file doesn't exist, so this read always fails with ENOENT. The whole cleanup pass then aborts and gets logged as a warning. Separately, rewriting files under /etc by deleting any line that appears in the old /usr/etc copy is risky: it can silently drop user configuration. It also only looks at top-level regular files in /etc/selinux/<store>/, while the module store lives under active/modules/<prio>/<name>/. I don't think this function should be kept in any form.

src/libostree/ostree-sysroot-deploy.c:3458

(low) new_upstream_exists is never used, and new_upstream_dir/old_upstream_dir build the same string. Moot if the function goes away.

src/libostree/ostree-sysroot-deploy.c:3641

This also makes it non-fatal when semodule --help itself fails to spawn. That covers bwrap failing in the new deployment, which is a real problem we want to surface, not something to skip quietly.

src/libostree/ostree-sysroot-deploy.c:3668

Important: This is the core concern: on failure we finalize with whatever policy.NN the /etc merge kept. On a system with any local policy change, that's a binary built from the previous image's policy, so the new deployment runs with stale policy. Please keep this an error, and catch it at stage time (dry run) rather than downgrading it at shutdown.

  • Send the newest draft as cgwalters-bot

Activity

  1. added
    review-draft
    on Oct 22, 2026
  2. cgwalters-bot commented on Nov 7, 2026

    @cgwalters-bot
    CollaboratorAuthor

    ✅ dispatch ended well. Result: #862 (comment)

  3. cgwalters-bot commented on Nov 7, 2026

    @cgwalters-bot
    CollaboratorAuthor

    Valid and still actionable; not done or obsolete. PR #3649 is open at the draft’s exact head, a0207f1, with no submitted reviews. The build defects are independently confirmed by the existing Fedora CI log: wrong glnx_file_get_contents_utf8_at arguments and invalid GString initialization. That is CI reproduction, not a fresh local build. The deployment failure has reported reproduction and recovery steps; I did not reproduce it in a VM.

    The code supports the main objections: pruning uses the parent SELinux dirfd rather than the store dirfd; cleanup reads new_upstream_file only after establishing it is absent; refresh/spawn failures become success. Fixing compilation alone would not make that safe. One draft nit should be corrected before sending: identical old/new path strings are intentional because they are resolved against different deployment dirfds, not themselves a defect. The precise merge-to-incomplete-store mechanism and stale-policy boot consequences remain hypotheses needing integration tests.

    Accept a bounded OSTree implementation follow-up, following cgwalters’s stage-time validation direction, rather than accepting fail-open finalization. Account separately for the compiled-policy-only report. This is not a tracker code defect, nor authorization to send this review; sending remains the explicit review-send action.

    {
      "schema": "agent-board/job-plan/v1",
      "repo": "ostreedev/ostree",
      "item": 3563,
      "kind": "implement",
      "runner": "hosted",
      "brief": "Implement a bounded stage-time SELinux policy validation follow-up to #3563, using current OSTree main rather than rewriting another author's #3649 branch. Reproduce an incomplete active module store in an integration fixture; validate the prospective merged policy before committing staged state and surface failure to the staging caller. Keep finalization refresh errors fatal, since /etc can change after staging; do not delete user policy or adopt the fail-open cleanup in #3649. Cover successful refresh, broken-store refusal without committing staged state, unchanged live policy, and compiled-policy-only deployments without a usable module store. Determine the supported no-store/config semantics from existing code before adding any skip, and keep that change separately testable. Run SELinux-enabled build/style/unit checks and the relevant deployment integration tests, reporting any unavailable VM coverage. Propose one draft PR scoped as Part of #3563, not a claim to solve the broader /usr-/etc module-store split. Do not submit the review from tracker#862 or alter credentials, bounds or upstream-publication policy."
    }
    

    Generated-by: https://github.com/cgwalters/#llms

    Generated by dispatch · ◷

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

Metadata

Metadata

Assignees

Labels

review-draft

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions