diff options
author | Catena cyber <35799796+catenacyber@users.noreply.github.com> | 2021-12-06 20:35:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-06 14:35:50 -0500 |
commit | c9d1f408b8cc40530046ebb9fde9657f5fcb0da2 (patch) | |
tree | bdfb58479ea62504f28ef70eef61e4111014619d | |
parent | b7f0b3e0477962bb8520bdf851a1d54115af8e6d (diff) |
gonids: try to test golang fix (#6971)
-rw-r--r-- | projects/gonids/372f9bd.diff | 129 | ||||
-rw-r--r-- | projects/gonids/Dockerfile | 1 | ||||
-rwxr-xr-x | projects/gonids/build.sh | 8 |
3 files changed, 138 insertions, 0 deletions
diff --git a/projects/gonids/372f9bd.diff b/projects/gonids/372f9bd.diff new file mode 100644 index 00000000..61dc4637 --- /dev/null +++ b/projects/gonids/372f9bd.diff @@ -0,0 +1,129 @@ +From 372f9bdd0a914945296123b51df92eed4ece3df6 Mon Sep 17 00:00:00 2001 +From: Keith Randall <khr@golang.org> +Date: Thu, 11 Nov 2021 19:58:23 -0500 +Subject: [PATCH] [release-branch.go1.17] reflect: keep pointer in aggregate-typed args live in Call + +When register ABI is used, reflect.Value.Call prepares the call +arguments in a memory representation of the argument registers. +It has special handling to keep the pointers in arguments live. +Currently, this handles pointer-typed arguments. But when an +argument is an aggregate-type that contains pointers and passed +in registers, it currently doesn't keep the pointers live. Do +so in this CL. + +Fixes #49961 + +Change-Id: I9264a8767e2a2c48573f6047144759b845dcf480 +--- + +diff --git a/src/internal/abi/abi.go b/src/internal/abi/abi.go +index aaff9ce..aa5083a 100644 +--- a/src/internal/abi/abi.go ++++ b/src/internal/abi/abi.go +@@ -33,6 +33,24 @@ + ReturnIsPtr IntArgRegBitmap + } + ++func (r *RegArgs) Dump() { ++ print("Ints:") ++ for _, x := range r.Ints { ++ print(" ", x) ++ } ++ println() ++ print("Floats:") ++ for _, x := range r.Floats { ++ print(" ", x) ++ } ++ println() ++ print("Ptrs:") ++ for _, x := range r.Ptrs { ++ print(" ", x) ++ } ++ println() ++} ++ + // IntArgRegBitmap is a bitmap large enough to hold one bit per + // integer argument/return register. + type IntArgRegBitmap [(IntArgRegs + 7) / 8]uint8 +diff --git a/src/reflect/all_test.go b/src/reflect/all_test.go +index eac27e8..6f350af 100644 +--- a/src/reflect/all_test.go ++++ b/src/reflect/all_test.go +@@ -6270,6 +6270,29 @@ + *CallGC = false + } + ++func TestCallArgLive(t *testing.T) { ++ type T struct{ X, Y *string } // pointerful aggregate ++ ++ F := func(t T) { *t.X = "ok" } ++ ++ // In reflect.Value.Call, trigger a garbage collection in reflect.call ++ // between marshaling argument and the actual call. ++ *CallGC = true ++ ++ x := new(string) ++ runtime.SetFinalizer(x, func(p *string) { ++ if *p != "ok" { ++ t.Errorf("x dead prematurely") ++ } ++ }) ++ v := T{x, nil} ++ ++ ValueOf(F).Call([]Value{ValueOf(v)}) ++ ++ // Stop garbage collecting during reflect.call. ++ *CallGC = false ++} ++ + func TestMakeFuncStackCopy(t *testing.T) { + target := func(in []Value) []Value { + runtime.GC() +diff --git a/src/reflect/value.go b/src/reflect/value.go +index 6f878eb..520dc69 100644 +--- a/src/reflect/value.go ++++ b/src/reflect/value.go +@@ -352,7 +352,7 @@ + return v.call("CallSlice", in) + } + +-var callGC bool // for testing; see TestCallMethodJump ++var callGC bool // for testing; see TestCallMethodJump and TestCallArgLive + + const debugReflectCall = false + +@@ -509,12 +509,16 @@ + // Copy values to "integer registers." + if v.flag&flagIndir != 0 { + offset := add(v.ptr, st.offset, "precomputed value offset") +- memmove(unsafe.Pointer(®Args.Ints[st.ireg]), offset, st.size) +- } else { + if st.kind == abiStepPointer { + // Duplicate this pointer in the pointer area of the + // register space. Otherwise, there's the potential for + // this to be the last reference to v.ptr. ++ regArgs.Ptrs[st.ireg] = *(*unsafe.Pointer)(offset) ++ } ++ memmove(unsafe.Pointer(®Args.Ints[st.ireg]), offset, st.size) ++ } else { ++ if st.kind == abiStepPointer { ++ // See the comment in abiStepPointer case above. + regArgs.Ptrs[st.ireg] = v.ptr + } + regArgs.Ints[st.ireg] = uintptr(v.ptr) +@@ -539,6 +543,15 @@ + // Mark pointers in registers for the return path. + regArgs.ReturnIsPtr = abi.outRegPtrs + ++ if debugReflectCall { ++ regArgs.Dump() ++ } ++ ++ // For testing; see TestCallArgLive. ++ if callGC { ++ runtime.GC() ++ } ++ + // Call. + call(frametype, fn, stackArgs, uint32(frametype.size), uint32(abi.retOffset), uint32(frameSize), ®Args) + diff --git a/projects/gonids/Dockerfile b/projects/gonids/Dockerfile index 13175c90..00fd7f2f 100644 --- a/projects/gonids/Dockerfile +++ b/projects/gonids/Dockerfile @@ -20,4 +20,5 @@ RUN git clone --depth 1 https://github.com/google/gonids ADD https://rules.emergingthreats.net/open/suricata/emerging.rules.zip emerging.rules.zip COPY build.sh $SRC/ +COPY *.diff $SRC/ WORKDIR $SRC/gonids diff --git a/projects/gonids/build.sh b/projects/gonids/build.sh index a7683257..1d75419a 100755 --- a/projects/gonids/build.sh +++ b/projects/gonids/build.sh @@ -15,6 +15,14 @@ # ################################################################################ +# Test to fix https://github.com/golang/go/issues/49075 +# with fix of https://github.com/golang/go/issues/49961 +# ie https://go-review.googlesource.com/c/go/+/369098/ +( +cd /root/.go +git apply $SRC/372f9bd.diff || true +) + export GODEBUG=cpu.all=off compile_go_fuzzer github.com/google/gonids FuzzParseRule fuzz_parserule |