GHSA-xj3h-wwxq-gfcj: Race Condition

Published Sep 22, 2026
·
Updated

Summary

Cloudreve v4 splits the storage-quota check (reading the user's used bytes and comparing them to MaxStorage) and the charge (incrementing users.storage) into two non-atomic steps in the PrepareUpload code path. This creates a Time-of-Check to Time-of-Use (TOCTOU) race condition. Any authenticated user — including an unprivileged account in the default User group — can concurrently issue several upload-session requests that all read the same stale used snapshot, each pass the check, and then each contribute their declared size to users.storage. The end result is that the total approved capacity exceeds the group's MaxStorage many times over.

The same primitive is trivially amplifiable into a storage-based denial of service. During PrepareUpload, Cloudreve reserves the declared size against users.storage before any bytes are written, so an attacker can push the reserved amount far beyond the host's physical disk (tested: a 1 GiB-quota account reserved 17 GiB in a single 20-way burst), and can then materialise the reservation by completing chunked uploads to actually write the excess bytes to disk. Amplification to the host's free space fills the disk and denies uploads for every user of the instance.

Exploitation requires only a valid session with Files.Write permission. No administrator configuration, no non-default storage policy, and no elevated privileges are needed. The default deployment (local storage policy, default User group) is affected.

Technical details

PrepareUpload in pkg/filemanager/fs/dbfs/upload.go splits quota enforcement across two stages:

Stage A — the check (snapshot compare, no lock) — pkg/filemanager/fs/dbfs/validator.go:

go func (f DBFS) validateUserCapacity(ctx context.Context, size int64, u ent.User) error { capacity, err := f.Capacity(ctx, u) // reads "used" if err != nil { return ... } return f.validateUserCapacityRaw(ctx, size, capacity) }

func (f DBFS) validateUserCapacityRaw(ctx context.Context, size int64, capacity fs.Capacity) error { if capacity.Used + size > capacity.Total { // snapshot compare only; no lock, no reservation return fs.ErrInsufficientCapacity } return nil }

capacity.Used comes from the in-memory ent.User that was hydrated once at the beginning of the request — pkg/filemanager/fs/dbfs/dbfs.go:

go func (f DBFS) Capacity(ctx context.Context, u ent.User) (fs.Capacity, error) { ... res.Used = f.user.Storage // captured at request start res.Total = requesterGroup.MaxStorage return res, nil }

No SELECT is issued at check time, no row lock is taken on the user row, and pending upload sessions are not counted.

Stage B — the charge (single unconditional UPDATE, outside the tx) — pkg/filemanager/fs/dbfs/upload.go → inventory/tx.go → inventory/user.go:

go // PrepareUpload: check (A) ... then, many statements later ... if err := f.validateUserCapacity(ctx, req.Props.Size, ancestor.Owner()); err != nil { return nil, err } ... if err := inventory.CommitWithStorageDiff(ctx, dbTx, f.l, f.userClient); err != nil { ... } // charge (B)

// inventory/user.go c.client.User.Update().Where(user.ID(uid)).AddStorage(diff).Exec(ctx) // SQL: storage = storage + diff

Between A and B the code performs storage-policy load-balancing, save-path generation, encryption-metadata generation, transaction start, placeholder-file/entity creation, and metadata upsert. This leaves a wide race window. N concurrent PrepareUpload requests each read the same stale Used snapshot at A, each pass their independent quota check, and then each add their own size to users.storage at B. The committed total is up to N × size above MaxStorage.

Three defensive controls that would each independently close the race are missing:

1. The check and the charge are not enclosed in the same transaction with a SELECT ... FOR UPDATE on the user row. 2. The charge is a plain storage = storage + :size UPDATE, not an atomic conditional update of the form UPDATE users SET storage = storage + :size WHERE id = :uid AND storage + :size <= :maxstorage. 3. Used is computed only from committed entities. Concurrent pending upload sessions (which have already been reserved by the accounting model) are not counted, so races among sessions that haven't yet completed are invisible to each other.

Affected Software

1 affected componentFixes available
go/github.com/cloudreve/Cloudreve/v4<4.0.0-20260715025621-7329602751c0
4.0.0-20260715025621-7329602751c0

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Upgrade

    Upgrade go/github.com/cloudreve/Cloudreve/v4 to a version that resolves this vulnerability.

    Fixed in 4.0.0-20260715025621-7329602751c0
  2. Compensating control

    Make quota enforcement atomic by enclosing the quota check and storage charge in the same transaction with a SELECT ... FOR UPDATE lock on the user row, or replace the separate check and charge with an atomic conditional update such as `UPDATE users SET storage = storage + :size WHERE id = :uid AND storage + :size <= :max_storage`.

  3. Compensating control

    Include concurrent pending upload-session reservations when calculating used storage so that sessions already reserved by the accounting model are counted against the quota.

Event History

Sep 22, 2026
Advisory Published
via GitHub·08:40 PM
Data Sourced
via GitHub·08:40 PM
DescriptionSeverityWeaknessAffected Software

Frequently Asked Questions

1

Are unprivileged users affected by this issue?

Yes. Any authenticated user can exploit it, including an unprivileged account in the default User group.

2

What does an attacker need to do to trigger the issue?

The attacker needs to send several upload-session requests concurrently. Each request can pass the quota check using the same stale storage-usage value before the declared sizes are charged.

3

Can this lead to disk exhaustion even when user quotas are configured?

Yes. Concurrent requests can reserve capacity far beyond the group's MaxStorage, and the attacker can complete chunked uploads to write the excess data to disk. This can be amplified into a storage-based denial of service.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203