Skip to content

posix: the scan switches to a space's group without ever switching back, so its workers use an unpredictable group #912

Open

Description

@pbleser-oc

With use_space_groups, posix switches the fsgid of the current OS thread to the group of a space before working on it, through UnixMapper.ScopeUserByIds(-1, gid). That function locks the goroutine to its OS thread (runtime.LockOSThread), as the fsgid belongs to the thread, and returns a function that restores the previous fsgid and unlocks the thread again. Two places in pkg/storage/fs/posix/tree/assimilation.go discard that function:

  • Tree.findSpaceId (assimilation.go:414 on main), when assimilate finds a path without a space ID, i.e. a file or directory created outside OpenCloud: _, err = t.userMapper.ScopeUserByIds(-1, gid);
  • Tree.WarmupIDCache (assimilation.go:931), in scopeSpace, which it calls for every node with a space ID it walks through: _, err = t.userMapper.ScopeUserByIds(-1, gid). Despite its name, scopeSpace(path) switches to the group of that node, not of the space root.

So even when the switch succeeds, the goroutine stays locked to its thread with that group, and every further call nests the lock once more. Introduced with the debounced scans (c0ed917) and the shared warmup (41884c7), in 2024.

Who runs them

goroutine lifetime effect
the scan workers of workScanQueue (max_concurrency, default 5): assimilate → findSpaceId, and WarmupIDCache for items with RefreshParent or Recurse until the process stops the nested locks and the switched group accumulate, see below
the initial scan (tree.go:207), the warmup of a moved directory (tree.go:536, assimilation.go:553), the GPFS event handlers end after their job Go discards a thread whose goroutine ends while locked: no lasting effect
RestoreRecycleItem of a directory (decomposedfs.go:1490), on the request's goroutine the request the rest of the request runs with the group of the last node walked, instead of the space's group set by the scopeSpaceGroupHook middleware
opencloud posixfs scan the command the process exits

Without use_space_groups, scopeSpace returns early and findSpaceId doesn't switch, and the NullMapper doesn't lock: nothing happens.

Consequences

1. The process panics after 2³² nested locks

Go counts the nested LockOSThread calls of a thread in a uint32 (m.lockedExt) and panics with LockOSThread nesting overflow when it would wrap (runtime/proc.go, Go 1.26). The scan workers don't recover from panics, so the panic takes down the whole process: the storage-users service, or with the single binary, all of OpenCloud.

Confirmed with a minimal program that calls runtime.LockOSThread() in a loop without unlocking (go1.26.0, linux/amd64): it panics after 4294967296 calls, after 5 s.

How fast a scan worker gets there: every file created outside OpenCloud is queued with RefreshParent, so after assimilating it, a worker calls WarmupIDCache(parent, true, true). That walks the parent directory, which Scan just marked dirty, and calls scopeSpace for every file in it (and every dirty subdirectory): one more nested lock per file in that directory. The workers share the queue, so with the default 5 workers, the first one panics after about 5 × 2³² ≈ 21 billion node visits in total. For example:

files in the directory files created outside OpenCloud in it, until the panic
10,000 ~2 million
1,000 ~21 million

That is months to years on a busy posix storage shared through SMB or NFS, and never on most deployments. These numbers are estimated from the code, not measured on a server.

2. The scan workers keep a stale group (not verified)

After its first switch, a scan worker keeps the group of the last node it walked. For later items whose space ID is known, neither assimilate nor findSpaceId switches again, so the worker handles them with another space's group instead of the process's own:

  • files and directories it creates (metadata, lock files) get that group, unless the parent directory is setgid. They are created with mode 0600 or 0700, so the group doesn't grant anyone access to them.
  • access to files that are owned by another user and only accessible through their group depends on that fsgid and on the process's supplementary groups, so a worker may be denied access that it would otherwise have, or the other way round.

This was not observed on a server; it follows from the code.

3. One thread per scan worker stays locked

Harmless on its own: at most one thread per goroutine, and Go starts other threads for the other goroutines.

Possible fix

Restore the previous scope instead of discarding it:

  • findSpaceId shouldn't switch at all, it only looks up the space ID; assimilate can switch to the space's group for the duration of the assimilation of the item and restore it (defer unscope()), as the workers in tree.go:603 do.
  • WarmupIDCache should switch only when the walk enters another space, and restore the previous scope when it leaves it, or when it returns.
  • Optionally, scopeSpace should switch to the group of the space root rather than the group of each node, as its name and comment say.

#899 makes ScopeUserByIds unlock the thread when it fails; it doesn't change these two callers, which discard the function on success.

Activity

  1. pbleser-oc commented on Oct 24, 2026

    @pbleser-oc
    MemberAuthor

    A correction on the weight of the consequences above: the crash is the least likely of them, and I'd rather not have it read as the main issue. What matters more is that the scan workers do their work with an unpredictable group.

    The group a scan worker uses depends on what it did before. posix only switches to a space's group in findSpaceId, i.e. for a path without a space ID, a file created outside OpenCloud, and in WarmupIDCache. A worker starts with the process's own group; after its first such switch it keeps the group of the last node it handled, and it handles every later item with it, including files of other spaces:

    scan worker
      at start                          → the process's own group
      new file in space A               → switches to A's group, never back
      existing file changed in space B  → no switch: handled with A's group
    

    What that changes:

    • Access to files changed outside OpenCloud. Whether a worker can read a file that its owner (e.g. an SMB user) shares only with the space's group depends on the group that worker happens to have: the assimilation of such a file can fail or succeed depending on which files that worker handled before. Such failures look random and are hard to reproduce.
    • Group ownership of OpenCloud's internal files. Metadata and lock files that a worker creates get the group of whichever space it last switched to. They are created with mode 0600 (directories 0700), so the group doesn't grant anyone access to them; this is not a security issue, but it's confusing for admins, and it would charge them to the wrong group with filesystem group quotas.
    • Not related to the leak, but next to it: changes to existing files are never scoped to their space's group at all, only new files are (findSpaceId is only called without a space ID). A fix should scope every scanned item to the group of its space, and switch back afterwards, rather than only restore the previous group.

    Resources: nothing beyond one locked thread per scan worker (5 by default). The nested locks are a counter, they use no memory, and the leak creates no files.

    The crash stays as described: a confirmed mechanism, but it needs millions of files created outside OpenCloud in a long-running process, so it's very unlikely in practice.

    All of this is from reading the code; neither the access failures nor the group ownership were observed on a server.

  2. changed the title [-]posix: the assimilation switches to a space's group without ever switching back, and can crash the process after enough scans[/-] [+]posix: the scan switches to a space's group without ever switching back, so its workers use an unpredictable group[/+] on Oct 24, 2026
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

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions