v2fly / v2ray-core

A platform for building proxies to bypass network restrictions.
https://v2fly.org
MIT License
28.94k stars 4.58k forks source link

4.31.0运行即非法退出 #298

Closed bigjunda closed 3 years ago

bigjunda commented 3 years ago

SIGILL: illegal instruction PC=0x4436c0 m=0 sigcode=1 instruction bytes: 0x0 0x6 0x38 0xd5 0xe0 0x7 0x0 0xf9 0xc0 0x3 0x5f 0xd6 0x0 0x0 0x0 0x0

goroutine 1 [running, locked to thread]: golang.org/x/sys/cpu.getisar0(0x862140) golang.org/x/sys@v0.0.0-20201006155630-ac719f4daadf/cpu/cpu_arm64.s:13 fp=0x400010fd50 sp=0x400010fd50 pc=0x4436c0 golang.org/x/sys/cpu.readARM64Registers() golang.org/x/sys@v0.0.0-20201006155630-ac719f4daadf/cpu/cpu_arm64.go:65 +0x30 fp=0x400010fd70 sp=0x400010fd50 pc=0x442ee0 golang.org/x/sys/cpu.doinit() golang.org/x/sys@v0.0.0-20201006155630-ac719f4daadf/cpu/cpu_linux_arm64.go:38 +0x2c fp=0x400010fd90 sp=0x400010fd70 pc=0x4431bc golang.org/x/sys/cpu.archInit() golang.org/x/sys@v0.0.0-20201006155630-ac719f4daadf/cpu/cpu_arm64.go:55 +0x20 fp=0x400010fda0 sp=0x400010fd90 pc=0x442e90 golang.org/x/sys/cpu.init.0() golang.org/x/sys@v0.0.0-20201006155630-ac719f4daadf/cpu/cpu.go:199 +0x20 fp=0x400010fdb0 sp=0x400010fda0 pc=0x442430 runtime.doInit(0xf556a0) runtime/proc.go:5625 +0x9c fp=0x400010fdf0 sp=0x400010fdb0 pc=0x50b4c runtime.doInit(0xf62280) runtime/proc.go:5620 +0x58 fp=0x400010fe30 sp=0x400010fdf0 pc=0x50b08 runtime.doInit(0xf5aca0) runtime/proc.go:5620 +0x58 fp=0x400010fe70 sp=0x400010fe30 pc=0x50b08 runtime.doInit(0xf5dee0) runtime/proc.go:5620 +0x58 fp=0x400010feb0 sp=0x400010fe70 pc=0x50b08 runtime.doInit(0xf5dc40) runtime/proc.go:5620 +0x58 fp=0x400010fef0 sp=0x400010feb0 pc=0x50b08 runtime.doInit(0xf63aa0) runtime/proc.go:5620 +0x58 fp=0x400010ff30 sp=0x400010fef0 pc=0x50b08 runtime.doInit(0xf5b420) runtime/proc.go:5620 +0x58 fp=0x400010ff70 sp=0x400010ff30 pc=0x50b08 runtime.main() runtime/proc.go:191 +0x1b8 fp=0x400010ffd0 sp=0x400010ff70 pc=0x439c8 runtime.goexit() runtime/asm_arm64.s:1136 +0x4 fp=0x400010ffd0 sp=0x400010ffd0 pc=0x72e34

r0 0x1 r1 0x400010e3a0 r2 0x400010fd70 r3 0x4000195920 r4 0xa81ec0 r5 0xdb10 r6 0x1000 r7 0x4 r8 0xf2 r9 0x400019594f r10 0x1000 r11 0x1 r12 0xa61624 r13 0x0 r14 0xf2 r15 0x0 r16 0x0 r17 0x8 r18 0x0 r19 0xf6a858 r20 0x400010fb10 r21 0x400010fc28 r22 0x4000002000 r23 0x0 r24 0x0 r25 0x0 r26 0xf556d8 r27 0xff7cb7 r28 0x4000000180 r29 0x400010fd48 lr 0x442ee0 sp 0x400010fd50 pc 0x4436c0 fault 0x0

bigjunda commented 3 years ago

arm64版本运行在骁龙660

DuckSoft commented 3 years ago

看样子是 CPU 指令集不支持对应的指令。 给我们一点时间调查。

RPRX commented 3 years ago

原因是 XTLS 用的 copy go 1.15.2 的 cpu 换成了 x/sys/cpu(标准做法)

根据 TG 上的反馈,该 CPU 上 termux 直接运行 v2ray-core v4.31.0 没有问题,但 magisk 有问题,所以建议给 magisk 提个 issue

https://github.com/topjohnwu/Magisk

dyhkwong commented 3 years ago

I can reproduce this with Magisk-Modules-Repo/v2ray on a Snapdragon 845 Android 10 phone. Replacing v2ray with v4.31.0 arm32 ones works for me. Replacing v2ray with arm64 versions before commit VLESS PREVIEW 2.3 work for me. (Maybe related to XTLS/Go commit import "golang.org/x/sys/cpu")

根据 TG 上的反馈,该 CPU 上 termux 直接运行 v2ray-core v4.31.0 没有问题,但 magisk 有问题,所以建议给 magisk 提个 issue

But I can grab v4.31.0 arm64 binaries from release and make a minimal Magisk module without illegal instruction error.

dyhkwong commented 3 years ago

OK, seems chmod 6755 v2ray cause the crash. Commenting this line and chmod 0755 v2ray can temporarily solve it.

To reproduce the crash, v2ray binary should be

dyhkwong commented 3 years ago

I grabbed the latest source code and built Android version of v2ray and v2ctl on Termux. It totally works and I cannot reproduce the crash anymore. Maybe we should not grab Linux builds for Android use?

Those who encounter the same error can try if this build works.

v2ray-android-arm64-v8a.tar.gz

:/data/data/com.termux/files/home # v2ray -version
V2Ray 4.31.0 (V2Fly, a community-driven edition of V2Ray.) Custom (go1.15.2 android/arm64)
A unified platform for anti-cencorship.
:/data/data/com.termux/files/home # 
kslr commented 3 years ago

I grabbed the latest source code and built Android version of v2ray and v2ctl on Termux. It totally works and I cannot reproduce the crash anymore. Maybe we should not grab Linux builds for Android use?

Those who encounter the same error can try if this build works.

v2ray-android-arm64-v8a.tar.gz

:/data/data/com.termux/files/home # v2ray -version
V2Ray 4.31.0 (V2Fly, a community-driven edition of V2Ray.) Custom (go1.15.2 android/arm64)
A unified platform for anti-cencorship.
:/data/data/com.termux/files/home # 

magisk test ?

How did you compile?

dyhkwong commented 3 years ago

magisk test ?

Yes.

How did you compile?

just follow https://www.v2fly.org/developer/intro/compile.html and run on Termux:

apt install golang git
git clone https://github.com/v2fly/v2ray-core.git
cd v2ray-core
go mod download
CGO_ENABLED=0 go build -o $../v2ray -trimpath -ldflags "-s -w -buildid=" ./main
CGO_ENABLED=0 go build -o $../v2ctl -trimpath -ldflags "-s -w -buildid=" -tags confonly ./infra/control/main

cross-compilation GOOS=android GOARCH=arm64 on PC also works.

Go env on Termux ``` $ go env GO111MODULE="" GOARCH="arm64" GOBIN="" GOCACHE="/data/data/com.termux/files/home/.cache/go-build" GOENV="/data/data/com.termux/files/home/.config/go/env" GOEXE="" GOFLAGS="" GOHOSTARCH="arm64" GOHOSTOS="android" GOINSECURE="" GOMODCACHE="/data/data/com.termux/files/home/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="android" GOPATH="/data/data/com.termux/files/home/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/data/data/com.termux/files/usr/lib/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/data/data/com.termux/files/usr/lib/go/pkg/tool/android_arm64" GCCGO="gccgo" AR="ar" CC="aarch64-linux-android-clang" CXX="aarch64-linux-android-clang++" CGO_ENABLED="1" GOMOD="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/data/data/com.termux/files/usr/tmp/go-build414125910=/tmp/go-build -gno-record-gcc-switches" $ ```
kslr commented 3 years ago

Did you modify the permissions?

dyhkwong commented 3 years ago

Of cource I tested it. The go1.15.2 android/arm64 build works even if permission 6755 and magisk-mounted.

dyhkwong commented 3 years ago

似乎不是 v2ray-core 的问题? 推测: v2ray Magisk模块的作者将v2ray所有者、用户组为设置为inet,权限设置为6755 see this Android 上/proc/self/auxv权限为0400,所有者、用户组为root

v2ray读取/proc/self/auxv返回错误,转而执行一段汇编代码getisar0()并crash

其他情况下能够正常读取/proc/self/auxv,规避了这个问题 arm linux版本和goos=android 版本则完全没有这部分代码

dyhkwong commented 3 years ago

重新刷magisk 20.3 版本即可解决,20.4有兼容问题。

not Magisk fault and Magisk 20.3 not work for me (tested with v2ray-core 4.31.0)

Anyway this issue should be closed due to the removal of xtls. (XTLS/Xray-core added Android arm64-v8a build for this as well)