fix(files): skip directory symlinks that loop back onto the scanned path - #63868
Open
nikaiw wants to merge 1 commit into
Open
fix(files): skip directory symlinks that loop back onto the scanned path#63868nikaiw wants to merge 1 commit into
nikaiw wants to merge 1 commit into
Conversation
A directory symlink whose target is one of its own ancestors, e.g. `device -> ..` in a copied /sys tree or docker-ce's `bundles/latest -> .`, makes the scanner re-enter the same tree until the 4000 character path limit: .../4:0:0:0/bsg/4:0:0:0/device/bsg/4:0:0:0/device/... (~140 levels) Each level adds a filecache row, so scanning such a storage grows oc_filecache without bound and the background scan never finishes. In effect this is a denial of service: anything able to write symlinks to the backing storage (a build job, rsync, sftp) can grow the database until the disk is full. On one instance two stale build trees produced 30M bogus rows and a 185 GB database, and at their peak filled the node's disk, taking the server down. The bug has been open since 2017 (nextcloud#6395, see also nextcloud#20197 and nextcloud#23022). The previous attempt, nextcloud#21723, compared the logical path to the resolved one, which cannot match when an ancestor is itself a symlink, and was closed unmerged. Skip a child symlink in Local::getDirectoryContent() when its resolved target equals the listed directory or one of its ancestors, comparing resolved paths on both sides. This also catches indirect cycles (a -> b, b -> a). The loop above now stops where it closes, with a single log line instead of a runaway descent: Skipping looping directory symlink '.../4:0:0:0/bsg/4:0:0:0/device' -> '.../4:0:0:0' Only listing is affected; files behind such links stay readable and writable (see testDisallowSymlinksInsideDatadir). Signed-off-by: NK <nicolas.devillers@airbus.com>
nikaiw
requested review from
Altahrim,
icewind1991,
leftybournes and
sorbaugh
and removed request for
a team
September 1, 2026 00:14
Member
|
Also #41563 |
Contributor
|
Thank you for your contribution! Please follow our AI policy: https://github.com/nextcloud/.github/blob/master/AI_POLICY.md#disclosure |
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
A directory symlink whose target is one of its own ancestors, e.g.
device -> ..in a copied /sys tree or docker-ce'sbundles/latest -> ., makes the scanner re-enter the same tree until the 4000 character path limit:.../4:0:0:0/bsg/4:0:0:0/device/bsg/4:0:0:0/device/... (~140 levels)
Each level adds a filecache row, so scanning such a storage grows oc_filecache table without bound and the background scan never finishes.
In effect this is a DoS: anything able to write symlinks to the backing storage (a build job, rsync, sftp) can grow the database until the disk is full. On one instance two stale build trees produced 30M bogus rows and a 185 GB database, and at their peak filled the node's disk, taking the server down.
The bug has been open since 2017 (#6395, see also #20197 and #23022). The previous attempt, #21723, compared the logical path to the resolved one, which cannot match when an ancestor is itself a symlink, and was closed unmerged.
Skip a child symlink in Local::getDirectoryContent() when its resolved target equals the listed directory or one of its ancestors, comparing resolved paths on both sides.
This also catches indirect cycles (a -> b, b -> a). The loop above now stops where it closes, with a single log line instead of a runaway descent:
Skipping looping directory symlink '.../4:0:0:0/bsg/4:0:0:0/device'
-> '.../4:0:0:0'
Only listing is affected; files behind such links stay readable and writable (see testDisallowSymlinksInsideDatadir).
AI (if applicable)