statsig-go: Fix A — NUL-scan + non-canonical ptr guard#10
Closed
nsaini-figma wants to merge 1 commit into
Closed
Conversation
Defends against the SIGSEGV in labmate caused by garbage ptr/len returning from purego trampolines. - UseRustString now ignores the inout length and uses UnperformantGoStringFromPointer to scan to NUL (Rust buffers are CString::into_raw, so NUL-terminated by construction). - GoStringFromPointer and UnperformantGoStringFromPointer now reject non-canonical x86-64 user addresses and absurd lengths. See ~/nsaini/state/explorations/labmate-statsig-ffi-fix.md Fix A and Fix B sections. Crash signature: github.com/statsig-io/statsig-go-core/internal. GoStringFromPointer panics in runtime.memmove with ptr= 0x88e50e9746d53405 (non-canonical) under sustained gRPC load in labmate staging.
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
Prototype of the minimal fix for the labmate SIGSEGV in the Rust→Go FFI
string return path. Companion prototype with the structural fix (Fix C —
JNI-style callback) lives on branch
nsaini/fix-c-callback. Bothprototypes are draft for side-by-side review.
What changed
statsig-go/statsig_ffi.goUseRustStringnow ignores the inoutlength and calls
UnperformantGoStringFromPointer(already intree at
statsig-go/internal/ffi_utils.go:14-29). Safe becauseevery Rust producer is
CString::into_raw, so the buffer isNUL-terminated.
statsig-go/internal/ffi_utils.goadds non-canonical-address +length-bound guards to both
GoStringFromPointerandUnperformantGoStringFromPointer.Failure modes covered
lenfrom purego trampoline → no longer usedptrfrom purego trampoline → returns nil instead of SIGSEGVTest plan
go vet ./...clean (run fromstatsig-go/)go build ./...buildsstatsig-go/internal/ffi_utils_test.go(9/9 pass)Crash signature
0x88e50e9746d53405is non-canonical for x86-64 userspace, so thepointer was never valid — purego ABI hazard, not a UAF.
Refs
~/nsaini/state/explorations/labmate-statsig-ffi-crash.md~/nsaini/state/explorations/labmate-statsig-ffi-fix.mdnsaini/fix-c-callback