Skip to content

🐛 fix(strict): protect sentinel and claims - #985

Merged
gaborbernat merged 2 commits into
tox-dev:mainfrom
gaborbernat:fix/strict-record-mode
Nov 20, 2026
Merged

gaborbernat merged 2 commits into
tox-dev:mainfrom
gaborbernat:fix/strict-record-mode

Conversation

@gaborbernat

@gaborbernat gaborbernat commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

StrictSoftFileLock created its sentinel and claims with the requested mode. A shared group could therefore change the sentinel record, allowing a SoftFileLock contender to enter while the strict holder remained inside. Strict record creation now removes group and other write permission. This addresses draft advisory ANT-2026-IHP04UFY.

The sentinel must remain owned by its writer

The mode argument and umask determine a new file's permissions; a default ACL can also grant access within the mode's limit. Previously, a requested mode with group write could leave the sentinel writable by another account. A legacy soft contender trusts that sentinel's content to decide whether to wait. The new creation mode prevents another account from changing that decision through a newly created record.

sequenceDiagram
    participant S as strict holder
    participant M as sentinel
    participant P as peer account
    participant C as soft contender
    rect rgb(255, 214, 214)
        S->>+M: old: publish a group-writable sentinel
        P->>M: change its record
        C->>M: read changed record
        M-->>C: appears stale, contender enters
        deactivate M
    end
    rect rgb(216, 243, 220)
        S->>+M: new: publish sentinel without group or other write
        P->>M: write denied
        C->>M: read intact sentinel
        M-->>C: wait for strict holder
        deactivate M
    end
Loading

Claim probes after the mode change

A strict contender verifies a claim with a hard-link probe. Linux can refuse a hard link to another account's file once the claim is no longer group-writable. _claim_exists_on_server now counts that EPERM as an existing claim, so a contender waits instead of raising a protocol error. A missing claim still returns false on ENOENT or ESTALE.

Behavior changes

New strict sentinels and claims omit group and other write bits even when mode, umask, or a default ACL would permit them. Existing records keep their permissions; an owner can remove those bits with chmod go-w before reusing the path. On Linux with protected hard links, a cross-account strict contender can treat EPERM from the claim probe as contention. No caller-facing exception is added.

Reported by the filelock scanner: ANT-2026-IHP04UFY.

A group-writable strict sentinel let another account change its record,
so a soft contender could enter beside the strict holder. Remove group
and other write permission when creating strict records. Treat a refused
hard-link probe as an existing claim so cross-account contenders wait.
@gaborbernat gaborbernat added bug security Fixes a published or draft security advisory labels Nov 20, 2026
@gaborbernat
gaborbernat merged commit d746e45 into tox-dev:main Nov 20, 2026
47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug security Fixes a published or draft security advisory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant