fix: strip S_ISGID in chmod() for non-group-member users#363
Draft
toddr-bot wants to merge 1 commit intocpan-authors:mainfrom
Draft
fix: strip S_ISGID in chmod() for non-group-member users#363toddr-bot wants to merge 1 commit intocpan-authors:mainfrom
toddr-bot wants to merge 1 commit intocpan-authors:mainfrom
Conversation
POSIX chmod(2) silently clears the set-group-ID bit when the calling process is not privileged and is not a member of the file's group. MockFile was allowing S_ISGID unconditionally, which could mask permission bugs in code that relies on this kernel behavior. Also adds S_ISUID/S_ISGID constants and tests for the SGID stripping, SUID preservation, and non-owner EPERM enforcement. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
chmod(2)silently clears the set-group-ID bit when a non-root caller is not a member of the file's group — MockFile was not enforcing thisS_ISUIDandS_ISGIDconstants alongside existingS_IF*definitionsWhy
Same class of POSIX compliance gap as the recent chown/utime/glob permission fixes. Code relying on the kernel's SGID stripping behavior could pass tests under MockFile but fail on real filesystems.
How
After computing the new permission bits in
__chmod, checks whether the mock user is non-root and not in the file's group — if so, masks outS_ISGIDbefore applying.Testing
prove -l t/chmod.t— 3 new subtests (9 assertions) all passfh-ref-leak.tfailure (GH Spooky action-at-a-distance #179)🤖 Generated with Claude Code
Quality Report
Changes: 2 files changed, 119 insertions(+), 2 deletions(-)
Code scan: clean
Tests: failed (4 Failed, 94 test)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline