cch123 / supermonkey

Patch all Go functions for testing
MIT License
250 stars 17 forks source link

panic: permission denied #19

Open pherzheyu opened 2 years ago

pherzheyu commented 2 years ago

image panic: permission denied [recovered] panic: permission denied

goroutine 162 [running]: testing.tRunner.func1.2({0x4b819e0, 0x55a90a8}) /usr/local/go/src/testing/testing.go:1209 +0x24e testing.tRunner.func1() /usr/local/go/src/testing/testing.go:1212 +0x218 panic({0x4b819e0, 0x55a90a8}) /usr/local/go/src/runtime/panic.go:1038 +0x215 github.com/cch123/supermonkey/internal/bouk.mprotectCrossPage(0x461f6e0, 0xc, 0x10) /Users/sangtianyu/go/pkg/mod/github.com/cch123/supermonkey@v1.0.1/internal/bouk/replace_unix.go:15 +0xc5 github.com/cch123/supermonkey/internal/bouk.CopyToLocation(0x461f6e0, {0xc000651cc4, 0xc, 0xc000384108}) /Users/sangtianyu/go/pkg/mod/github.com/cch123/supermonkey@v1.0.1/internal/bouk/replace_unix.go:26 +0x5c github.com/cch123/supermonkey/internal/bouk.ReplaceFunction(0x461f6e0, 0x4cf9f08) /Users/sangtianyu/go/pkg/mod/github.com/cch123/supermonkey@v1.0.1/internal/bouk/replace.go:29 +0xb2 github.com/cch123/supermonkey/internal/bouk.patchValue({0x4b4e800, 0x4cf9f08, 0x0}, {0x4b4e800, 0x4cf9c18, 0x13}, 0x0) /Users/sangtianyu/go/pkg/mod/github.com/cch123/supermonkey@v1.0.1/internal/bouk/monkey.go:96 +0x2b6 github.com/cch123/supermonkey/internal/bouk.Patch({0x4b4e800, 0x4cf9f08}, {0x4b4e800, 0x4cf9c18}) /Users/sangtianyu/go/pkg/mod/github.com/cch123/supermonkey@v1.0.1/internal/bouk/monkey.go:50 +0x17a github.com/cch123/supermonkey.Patch({0x4b4e800, 0x4cf9f08}, {0x4b4e800, 0x4cf9c18}) /Users/sangtianyu/go/pkg/mod/github.com/cch123/supermonkey@v1.0.1/supermonkey.go:23 +0x2d

go env GO111MODULE="on" GOARCH="amd64" GOHOSTARCH="amd64" GOHOSTOS="darwin"

cch123 commented 2 years ago

may you provide a demo to reproduce this panic?

ma642 commented 1 year ago

same error got. when patch

ma642 commented 1 year ago

reproduce code:

package main

import _ "github.com/google/gopacket/pcap"

func main() { patchFunc() patchFuncSymbol()

patchInstanceFunc()
patchInstanceFuncSymbol()

patchStructMethod()
patchStructMethodSymbol()

}

Marakai commented 1 year ago

I suspect the issue the same one discussed elsewhere on this issue on M1 Macs.

In replace_unix.go

err := syscall.Mprotect(page, prot)
        if err != nil {
            panic(err)
        }

fails on Apple silicon. Diving through threads, first this seemed to be a bug, but now Apple says this is working as intended and you're supposed to use pthread_jit_write_protect_np as per

https://developer.apple.com/documentation/apple-silicon/porting-just-in-time-compilers-to-apple-silicon?language=objc

Alas, I have no idea how you would call that in Go, barring using C extensions.