Skip to content

DRAFT: tmpfiles: only chmod/chown directories that differ from the rule - #506

Closed
sbrkopac wants to merge 1 commit into
finit-project:masterfrom
sbrkopac:tmpfiles-skip-matching
Closed

sbrkopac wants to merge 1 commit into
finit-project:masterfrom
sbrkopac:tmpfiles-skip-matching

Conversation

@sbrkopac

Copy link
Copy Markdown
Contributor

on finix /var/empty is immutable, so every boot logs

tmpfiles: Failed chown(/var/empty, 0, 0): Operation not permitted

d rules chown the directory unconditionally, even when nothing needs to
change. this stats it first and skips chmod/chown when mode and owner
already match, the same direction mksubsysd() went in 6b03a1e.

heads up that the old errno == EEXIST chmod branch was dead, since
makedir() already swallows EEXIST. so existing directories with the wrong
mode will now actually get fixed, which i think was the intent.

tested with a finix vm test that runs a matching d rule on a chattr +i
directory. it fails on 4.17 and passes with this.

makedir() returns 0 when the directory already exists, so the EEXIST
branch never ran and existing directories never had their mode fixed.
chown() on the other hand ran every time, which fails with EPERM on an
immutable directory even when the owner is already correct:

    tmpfiles: Failed chown(/var/empty, 0, 0): Operation not permitted

Stat the directory and only change the mode or owner if it differs.
@sbrkopac sbrkopac changed the title tmpfiles: only chmod/chown directories that differ from the rule DRAFT: tmpfiles: only chmod/chown directories that differ from the rule Sep 22, 2026
@Bqrry4

Bqrry4 commented Sep 22, 2026

Copy link
Copy Markdown

Worth noting, previously this portion of the code was using just a call to mksubsys. In the meantime it got updated to do exactly the same, but the code didn't got replaced.
Should the check be moved under the mksubsys instead and this use a call to it?

@sbrkopac
sbrkopac marked this pull request as draft September 22, 2026 20:13

@troglobit troglobit left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have to flip it or we'll get a TOCTOU error instead that Covertly will flag. Ie, on error check why before logging.

@troglobit

Copy link
Copy Markdown
Collaborator

Fixed on master as of 88a9e65 and 4.x as 75739fb for the upcoming 4.18 patch release.

@troglobit troglobit closed this Sep 27, 2026
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.

3 participants