Repository navigation
adapter/statsclient: bounds-check a symlink's target index - #389
Merged
Merged
Conversation
CopyEntryData derives the target's directory segment from the index a symlink carries and dereferences it without checking either the index or the vector. A directory entry is 144 bytes, so an out-of-range uint32 addresses hundreds of gigabytes past the mapping: the recursive call reads directoryType at an address that is almost always unmapped, and faults. Where it is mapped it returns unrelated process memory as a counter. The index comes out of shared memory another process writes, so it is only as trustworthy as that process. Nothing in govpp can produce a bad one - it takes VPP publishing an index that is structurally valid but wrong, or a directory read astride a re-layout, and the segment's optimistic lock does not help with the second, because accessEnd validates the epoch only after the reads, which is too late to prevent a fault. adjust() returning nil was unchecked here too, alone among the call sites in that function. UpdateDir was already covered: updateSymlinkGroups rejects target >= dirLen before resolving a group. DumpStats and PrepareDir reach the symlink case through CopyEntryData directly and were not. That guard reads as an inconsistency next to the shape mismatch below it, which does fall back to resolving each symlink on its own, so it now says why it cannot: the fallback would hand CopyEntryData the very index just found to be out of range. The sibling skip for a target whose name is empty - a freed directory slot, since VPP zeroes an entry's name when it removes it - gets the same note and the debugf it was missing. The test points a symlink at a directory slot the synthetic v2 segment holds but its declared vector length excludes, so resolving it succeeds without the check and is refused with it - reverting the check fails the test with the counter value it read past the end. An index chosen to be wildly out of range would prove nothing: it lands in unrelated mapped memory, reads garbage as the directory type and falls out of the type switch as nil, which is what the fix produces anyway. Two further tests pin the existing skips in updateSymlinkGroups, the ones whose comments this commit adds: the grouped refresh leaves an out-of-range group at its previous value while refreshing the rest, and a symlink whose target names a freed slot does not resolve through it. Fixes FDio#388. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
ondrej-fabry
approved these changes
Sep 8, 2026
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.
Fixes #388.
CopyEntryDataderives a symlink's target directory segment from the index theentry carries and dereferences it without checking either the index or the
vector. A directory entry is 144 bytes, so an out-of-range
uint32addresseshundreds of gigabytes past the mapping: the recursive call reads
directoryTypeat an address that is almost always unmapped, and faults. Whereit is mapped it returns unrelated process memory as a counter.
adjust()returning nil was unchecked here too, alone among the call sites in that
function.
The index comes out of shared memory another process writes, so it is only as
trustworthy as that process. Nothing in govpp can produce a bad one - it takes
VPP publishing an index that is structurally valid but wrong, or a directory
read astride a re-layout, and the optimistic lock does not help with the
second, because
accessEndvalidates the epoch only after the reads, which istoo late to prevent a fault.
UpdateDirwas already covered:updateSymlinkGroupsrejectstarget >= dirLenbefore resolving a group.DumpStatsandPrepareDirreachthe symlink case through
CopyEntryDatadirectly and were not.That guard reads as an inconsistency next to the shape mismatch below it, which
does fall back to resolving each symlink on its own, so it now says why it
cannot: the fallback would hand
CopyEntryDatathe very index just found to beout of range. The sibling skip for a target whose name is empty - a freed
directory slot, since VPP zeroes an entry's name when it removes it - gets the
same note and the
debugfit was missing.The test points a symlink at a directory slot the synthetic v2 segment holds but
its declared vector length excludes, so resolving it succeeds without the check
and is refused with it; reverting the check fails the test with the counter
value it read past the end. An index chosen to be wildly out of range would
prove nothing - it lands in unrelated mapped memory, reads garbage as the
directory type and falls out of the type switch as nil, which is what the fix
produces anyway.