Skip to content

fix: prevent GC from collecting DataExtract buffers#7

Open
chvancooten wants to merge 2 commits intopraetorian-inc:mainfrom
chvancooten:fix/data-extract-gc
Open

fix: prevent GC from collecting DataExtract buffers#7
chvancooten wants to merge 2 commits intopraetorian-inc:mainfrom
chvancooten:fix/data-extract-gc

Conversation

@chvancooten
Copy link
Contributor

DataExtract allocates a Go slice to hold extracted data and returns a raw uintptr to the caller (native BOF code). Since Go's GC doesn't track uintptr values, the backing array could be collected before the BOF finishes using it, causing memory corruption and garbled data. We encountered this issue for example in Outflank's Kerberoast BOF.

This fix stores extracted buffers in a global map keyed by their pointer address, keeping them alive for the duration of the BOF execution. Buffers are cleaned up when BeaconDataFree is called.

DataExtract allocates a Go slice to hold extracted data and returns a
raw uintptr to the caller (native BOF code). Since Go's GC doesn't
track uintptr values, the backing array could be collected before the
BOF finishes using it, causing memory corruption and garbled data.

This fix stores extracted buffers in a global map, keeping them alive
for the duration of the BOF execution. This prevents the GC from
reclaiming the memory while it's still in use by native code.
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.

1 participant