install: finalize ownership before mode, and skip the mode if chown fails - #13629
Open
sylvestre wants to merge 1 commit into
Open
install: finalize ownership before mode, and skip the mode if chown fails#13629sylvestre wants to merge 1 commit into
sylvestre wants to merge 1 commit into
Conversation
sylvestre
force-pushed
the
install-chown-before-chmod
branch
from
July 29, 2026 08:09
f799e90 to
24a02f8
Compare
…ails set_ownership_and_permissions applied the mode -- including setuid/setgid -- and only then attempted the chown, with no rollback on failure. A failed ownership change therefore left the destination as a setuid file owned by the installing user. install -d had the same ordering. Reproducible unprivileged, no race needed: $ install -m 4755 -o root src dst GNU 9.10 : cannot change ownership of 'dst' -> dst is 600, no setuid uutils : chown failed -> dst is 4755, setuid Swap the order, matching GNU: chown first, and skip the chmod when it fails. This also fixes a second, quieter bug -- chown(2) clears setuid/setgid, so chmod-then-chown silently dropped those bits from successfully installed files. The mode is still applied in full when no ownership change is requested.
sylvestre
force-pushed
the
install-chown-before-chmod
branch
from
July 29, 2026 08:42
24a02f8 to
e0ed8e3
Compare
|
GNU testsuite comparison: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
set_ownership_and_permissions applied the mode -- including setuid/setgid -- and only then attempted the chown, with no rollback on failure. A failed ownership change therefore left the destination as a setuid file owned by the installing user. install -d had the same ordering.