Skip to content

adapter/statsclient: bounds-check a symlink's target index - #389

Merged
otroan merged 1 commit into
FDio:masterfrom
otroan:ole/statsclient-symlink-bounds
Sep 9, 2026
Merged

otroan merged 1 commit into
FDio:masterfrom
otroan:ole/statsclient-symlink-bounds

Conversation

@otroan

@otroan otroan commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

Fixes #388.

CopyEntryData derives a symlink's target directory segment from the index the
entry 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. 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 accessEnd validates the epoch only after the reads, which is
too late to prevent a fault.

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.

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>
@otroan
otroan merged commit 1514468 into FDio:master Sep 9, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

statsclient: CopyEntryData dereferences an unchecked symlink target index

2 participants