registry/hive: reject malformed cell sizes instead of panicking#17
Merged
registry/hive: reject malformed cell sizes instead of panicking#17
Conversation
readCell trusted the cell's size header without bounds-checking the positive side, so any cell whose raw size field was 0 or a negative value with absolute magnitude smaller than the 4-byte cell header produced an inverted slice expression (h.data[pos+4 : pos+size] with size < 4) and crashed the process. Reported as a runtime panic `slice bounds out of range [5052:5048]` in secretsdump's cached domain logon parse path. Treat raw size >= 0 as free/invalid (return error) and require the allocated size to be at least 4 bytes so the data slice is never inverted. Regression test synthesizes a minimal hive with each of the previously-panicking inputs. Removes the now-resolved entry from KNOWN_ISSUES.md and renumbers the remaining sections.
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
Fixes the
panic: runtime error: slice bounds out of range [5052:5048]crash documented inKNOWN_ISSUES.md#2 under secretsdump's cached-domain-logon parse path.readCell()inpkg/registry/hive.gotrusted the 4-byte cell-size header on the wire without validating the positive side of it:|size|total bytes including the 4-byte header)The old code checked
if size > 0(free) but let zero fall through. It then didsize = -size(still 0) and computed the final slice ash.data[pos+4 : pos+0], which panics. Same for raw values -1, -2, -3 (negation gives 1, 2, 3 respectively, still less than the 4-byte header).The fix
Treat
rawSize >= 0as "free or malformed, return error", and after negation requiresize >= 4so the slice can never be inverted. Both paths return a descriptive error instead of crashing.Test plan
pkg/registry/hive_test.gosynthesizes a minimal hive with each previously-panicking input (raw size 0, positive, -1, -3) and assertsreadCellreturns an error rather than panickinggit stash-ing the fix, running the test, and watching it fail with the exact[x+4 : x]slice-bounds shape before restoringgo build ./...cleango vet ./...cleango test ./...passesImpact for secretsdump
The cached-domain-logon parse path walks SECURITY hive
NL$Nvalues, which occasionally encounter a bogus cell header. Previously this crashed the whole tool after SAM and LSA secrets had already been dumped (so you'd lose the cached creds and the process would exit non-zero). The tool now skips the bad entry with an error and continues to the next.Also removes the now-resolved entry from
KNOWN_ISSUES.mdand renumbers the remaining sections.