Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

syscall: accept(2) syscall blocked on Android, use accept4(2) instead #45767

Closed
jack5105 opened this issue Apr 26, 2021 · 7 comments
Closed

syscall: accept(2) syscall blocked on Android, use accept4(2) instead #45767

jack5105 opened this issue Apr 26, 2021 · 7 comments
Labels
FrozenDueToAge mobile Android, iOS, and x/mobile NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@jack5105
Copy link

What version of Go are you using (go version)?

go version go1.15.11 linux/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

GO111MODULE="on"
GOARCH="amd64"
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPRIVATE=""
GOPROXY="https://goproxy.io,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.google.cn"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build729311614=/tmp/go-build -gno-record-gcc-switches"

What did you do?

import (
	"net"
	"strconv"
	"strings"
	"time"
)

type NetDemoApi struct {
}

func (nda *NetDemoApi) Run(serverAddr string, localPort int) error {
	var localIP string
	if conn, e := net.DialTimeout("tcp4", serverAddr, 3*time.Second); e == nil {
		localIP = conn.LocalAddr().String()
		conn.Close()
		if idx := strings.LastIndexByte(localIP, ':'); idx >= 0 {
			localIP = localIP[:idx]
		}
	} else
	{
		return e
	}

	addr := net.JoinHostPort(localIP, strconv.Itoa(localPort))
	ln, err := net.Listen("tcp", addr)
	if err != nil {
		return err
	}

	go func() {
		_, err := ln.Accept()
		if err != nil {
			return
		}
	}()

	time.Sleep(time.Second * 60)

	return nil
}

I use gomobile to build aar with above code, then use this aar in app. When app running, I turn off the wifi, then app crash.

2021-04-26 14:26:16.276 30002-30002/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
2021-04-26 14:26:16.277 30002-30002/? A/DEBUG: Build fingerprint: 'HUAWEI/EML-AL00/HWEML:10/HUAWEIEML-AL00/10.0.0.156C00:user/release-keys'
2021-04-26 14:26:16.277 30002-30002/? A/DEBUG: Revision: '0'
2021-04-26 14:26:16.277 30002-30002/? A/DEBUG: ABI: 'arm64'
2021-04-26 14:26:16.277 1257-4257/system_process I/chatty: uid=1000(system) Binder:1257_13 expire 1 line
2021-04-26 14:26:16.277 30002-30002/? A/DEBUG: SYSVMTYPE: Maple
    APPVMTYPE: Art
2021-04-26 14:26:16.278 30002-30002/? A/DEBUG: Timestamp: 2021-04-26 14:26:16+0800
2021-04-26 14:26:16.278 30002-30002/? A/DEBUG: pid: 29812, tid: 29872, name: Thread-2  >>> org.golang.example.android <<<
2021-04-26 14:26:16.278 30002-30002/? A/DEBUG: uid: 10001
2021-04-26 14:26:16.278 30002-30002/? A/DEBUG: signal 31 (SIGSYS), code 1 (SYS_SECCOMP), fault addr --------
2021-04-26 14:26:16.278 30002-30002/? A/DEBUG: Cause: seccomp prevented call to disallowed arm64 system call 202
2021-04-26 14:26:16.278 30002-30002/? A/DEBUG:     x0  0000000000000056  x1  000000400002c498  x2  000000400002c478  x3  0000000000000000
2021-04-26 14:26:16.278 30002-30002/? A/DEBUG:     x4  0000000000000000  x5  0000000000000000  x6  0000000000000001  x7  00000000016944e8
2021-04-26 14:26:16.278 30002-30002/? A/DEBUG:     x8  00000000000000ca  x9  000ee6b280000000  x10 000000000001abdc  x11 000000000f92b524
2021-04-26 14:26:16.278 30002-30002/? A/DEBUG:     x12 0000000000000016  x13 0000000060865d08  x14 0001dac7eb968cd3  x15 0000088991354fbd
2021-04-26 14:26:16.278 30002-30002/? A/DEBUG:     x16 000000774d609ac8  x17 0000000000000000  x18 000000774703c000  x19 0000000000000030
2021-04-26 14:26:16.278 30002-30002/? A/DEBUG:     x20 000000400002c4f8  x21 000000774d869cc0  x22 0000000000000001  x23 000000774d8995b5
2021-04-26 14:26:16.278 30002-30002/? A/DEBUG:     x24 000000774d8691b0  x25 0000000000000018  x26 000000774d7c0120  x27 0000000000000000
2021-04-26 14:26:16.278 30002-30002/? A/DEBUG:     x28 0000004000000180  x29 0000000000000000
2021-04-26 14:26:16.278 30002-30002/? A/DEBUG:     sp  000000400002c3d0  lr  000000774d6f7ac8  pc  000000774d6f7ae8
2021-04-26 14:26:16.278 30002-30002/? A/DEBUG: backtrace:
2021-04-26 14:26:16.278 30002-30002/? A/DEBUG:       #00 pc 00000000000e9ae8  /data/app/org.golang.example.android-mzk5Nz7vrkXGh6877_slNQ==/lib/arm64/libgojni.so
@cherrymui
Copy link
Member

cc @hyangah @eliasnaur

@cherrymui cherrymui added this to the Unreleased milestone Apr 26, 2021
@cherrymui cherrymui added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 26, 2021
@cherrymui cherrymui changed the title gomobile Apps crash on Android with SYS_SECCOMP x/mobile: gomobile Apps crash on Android with SYS_SECCOMP Apr 26, 2021
@gopherbot gopherbot added the mobile Android, iOS, and x/mobile label Apr 26, 2021
@eliasnaur
Copy link
Contributor

Syscall 202 is accept which seems to match what the demonstration program does. My guess is that accept syscalls should map to accept4 on Android. We can't use accept4 on all linux because it was introduced in Linux 2.6.28 and Go's minimum is 2.6.23.

I don't have the time to do this, but see https://go-review.googlesource.com/c/go/+/235537 for a similar fix to map dup2 to dup3 on Android.

@eliasnaur eliasnaur changed the title x/mobile: gomobile Apps crash on Android with SYS_SECCOMP syscall: gomobile Apps crash on Android with SYS_SECCOMP Apr 26, 2021
@eliasnaur eliasnaur changed the title syscall: gomobile Apps crash on Android with SYS_SECCOMP syscall: accept syscall blocked on Android Apr 26, 2021
@eliasnaur eliasnaur changed the title syscall: accept syscall blocked on Android syscall: accept(2) syscall blocked on Android, use accept4(2) instead Apr 26, 2021
@OneOfOne
Copy link
Contributor

@eliasnaur off topic but is there a reason why linux support is linked to 2.6.x? it has reached EOL in Aug 2011.

@ianlancetaylor
Copy link
Contributor

@OneOfOne That is what we've written in https://golang.org/wiki/MinimumRequirements. We could decide to increase the required version, but that should be done in a separate and longer discussion. (In particular we have to consider RHEL, CentOS, and Debian LTS requirements.)

@gopherbot
Copy link

Change https://golang.org/cl/313769 mentions this issue: syscall: use accept4 in Accept on android

@gopherbot
Copy link

Change https://golang.org/cl/313690 mentions this issue: unix: use accept4 in Accept on android

gopherbot pushed a commit to golang/sys that referenced this issue Apr 26, 2021
Android seems to block the accept syscall in newer versions. Use accept4
instead on kernel versions that support it (Linux 2.6.28 and newer) and
fall back to accept on ENOSYS.

Updates golang/go#45767

Change-Id: If557eaaaa0b69112bbe66ed820fbb382afb53b04
Reviewed-on: https://go-review.googlesource.com/c/sys/+/313690
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
@jack5105
Copy link
Author

Thanks.

DentonGentry pushed a commit to tailscale/go that referenced this issue Jul 20, 2021
Android seems to block the accept syscall in newer versions. Use accept4
instead on kernel versions that support it (Linux 2.6.28 and newer) and
fall back to accept on ENOSYS.

Fixes golang#45767

Change-Id: If190ace0e0213207fdaf6eeb79a5543ef18456de
Reviewed-on: https://go-review.googlesource.com/c/go/+/313769
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
josharian pushed a commit to tailscale/go that referenced this issue Jul 20, 2021
… accept

Android seems to block the accept syscall in newer versions. Use accept4
instead on kernel versions that support it (Linux 2.6.28 and newer) and
fall back to accept on ENOSYS.

Fixes golang#45767

(cherry picked from golang.org/cl/313769)

Change-Id: If190ace0e0213207fdaf6eeb79a5543ef18456de
Reviewed-on: https://go-review.googlesource.com/c/go/+/313769
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
@golang golang locked and limited conversation to collaborators Apr 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge mobile Android, iOS, and x/mobile NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

6 participants