Skip to content

Permission-class semantics disagree: owner-only in three places, no-world in the one that runs #559

Open

Description

@David-Noble-at-work

Four sites decide which permission classes a mode must exclude, and they do not agree:

Site Mask Means
pkg/op/provider/encryption/provider.go:225 (secret floor) & 0o077 owner-only
pkg/op/provider/file/owneronly_unix_test.go (OwnerOnly) & 0o077 owner-only
pkg/fsroot/applymode_windows.go:23 (documentation) & 0o077 owner-only
pkg/fsroot/fsroot.go isPrivateMode & 0o007 no-world

The outlier is the line that actually runs. isPrivateMode is the gate deciding whether applyMode enforces at
all, and the doc comment sitting directly above that enforcement claims the other rule.

It already diverges the platforms

Take 0o640:

  • Unix — group can read. The mode says so and the kernel obeys.
  • Windows — isPrivateMode(0o640) is true, so applyMode fires and writes a protected DACL granting owner,
    SYSTEM and Administrators. There is no group entry. The group's read is silently dropped.

So the same call means owner + group on one platform and owner only on the other. Not a security hole —
Windows lands stricter — but a caller who asked for a group grant does not get one, and is not told.

The ruling

Which rule does enforcement mean?

  1. No world access (0o007, today's code) — group grants are honored on Unix and cannot be honored on
    Windows, so any mode with group bits stays divergent.
  2. Owner-only (0o077, today's doc and everything else) — 0o640 falls outside the enforced set entirely
    and inherits its parent DACL on Windows, so the enforced set becomes exactly the set both platforms can
    honor identically.

2 looks right: it makes enforcement mean the same thing everywhere, and it costs only the enforcement of modes
that were never faithfully enforced anyway.

Why the literals caused this

Go supplies no symbol for the permission classes — fs.ModePerm is all nine bits, and syscall's S_IRWXU /
S_IRWXG / S_IRWXO are unix-only and unusable in cross-platform code. As octal, 0o007 and 0o077 differ by
one character and read as a typo of each other.

fsroot.PermOwner, PermGroup and PermOther landed alongside #435 to remove that. Migrating the four call
sites onto them is this issue's work
, and doing so forces the ruling: the constant cannot be written without
saying which classes are excluded.

Blocks sops being able to set owner-only on decrypted plaintext, which needs the word to mean one thing.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions