x/mobile: gomobile apps crash inside runtime.usleep() on Android O beta #20409

Closed
cjb opened this Issue May 18, 2017 · 17 comments

Comments

Projects
None yet
7 participants
@cjb
Contributor

cjb commented May 18, 2017

Please answer these questions before submitting your issue. Thanks!

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

go version go1.8.1 linux/amd64

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

This is gomobile on Android O -- crashes on both x86 inside the simulator, and on device with arm64 on a Nexus 6P.

What did you do?

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.

I called runtime.usleep() from Go code. I haven't made a minimal testcase yet, sorry.

What did you expect to see?

A delay.

What did you see instead?

Crashes due to seccomp policy violation. On amd64, in the Android simulator:

05-17 16:43:08.084 18543 18543 F DEBUG   : Build fingerprint: 'Android/sdk_gphone_x86/generic_x86:O/OSR1.170321.002/3834619:userdebug/test-keys'
05-17 16:43:08.084 18543 18543 F DEBUG   : Revision: '0'
05-17 16:43:08.084 18543 18543 F DEBUG   : ABI: 'x86'
05-17 16:43:08.084 18543 18543 F DEBUG   : pid: 18519, tid: 18538, name: ybase.ossifrage  >>> io.keybase.ossifrage <<<
05-17 16:43:08.084 18543 18543 F DEBUG   : signal 31 (SIGSYS), code 1 (SYS_SECCOMP), fault addr --------
05-17 16:43:08.084 18543 18543 F DEBUG   : Cause: seccomp prevented call to disallowed x86 system call 142
05-17 16:43:08.084 18543 18543 F DEBUG   :     eax 0000008e  ebx 00000000  ecx 00000000  edx 00000000
05-17 16:43:08.084 18543 18543 F DEBUG   :     esi 00000000  edi 91e9a77c
05-17 16:43:08.084 18543 18543 F DEBUG   :     xcs 00000073  xds 0000007b  xes 0000007b  xfs 0000003b  xss 0000007b
05-17 16:43:08.084 18543 18543 F DEBUG   :     eip 92342149  ebp 5fa84690  esp 91e9a77c  flags 00000246
05-17 16:43:08.094 18543 18543 F DEBUG   : 
05-17 16:43:08.094 18543 18543 F DEBUG   : backtrace:
05-17 16:43:08.094 18543 18543 F DEBUG   :     #00 pc 002ad149  /data/app/io.keybase.ossifrage-vN7ak8XPsBIXVVyb4sc7EA==/lib/x86/libgojni.so (runtime.usleep+41)
05-17 16:43:08.094 18543 18543 F DEBUG   :     #01 pc 0028ab6b  /data/app/io.keybase.ossifrage-vN7ak8XPsBIXVVyb4sc7EA==/lib/x86/libgojni.so (runtime.runqgrab+155)
05-17 16:43:08.094 18543 18543 F DEBUG   :     #02 pc 0028ad30  /data/app/io.keybase.ossifrage-vN7ak8XPsBIXVVyb4sc7EA==/lib/x86/libgojni.so (runtime.runqsteal+80)
05-17 16:43:08.094 18543 18543 F DEBUG   :     #03 pc 002844ca  /data/app/io.keybase.ossifrage-vN7ak8XPsBIXVVyb4sc7EA==/lib/x86/libgojni.so (runtime.findrunnable+2346)
05-17 16:43:08.094 18543 18543 F DEBUG   :     #04 pc 00284a2d  /data/app/io.keybase.ossifrage-vN7ak8XPsBIXVVyb4sc7EA==/lib/x86/libgojni.so (runtime.schedule+573)
05-17 16:43:08.094 18543 18543 F DEBUG   :     #05 pc 00282027  /data/app/io.keybase.ossifrage-vN7ak8XPsBIXVVyb4sc7EA==/lib/x86/libgojni.so (runtime.mstart1+263)
05-17 16:43:08.094 18543 18543 F DEBUG   :     #06 pc 00281f12  /data/app/io.keybase.ossifrage-vN7ak8XPsBIXVVyb4sc7EA==/lib/x86/libgojni.so (runtime.mstart+82)
05-17 16:43:08.094 18543 18543 F DEBUG   :     #07 pc 010e1db2  /data/app/io.keybase.ossifrage-vN7ak8XPsBIXVVyb4sc7EA==/lib/x86/libgojni.so

On ARM on a Nexus 6P:

05-17 15:27:53.222 15775-15775/? A/DEBUG: Build fingerprint: 'google/angler/angler:O/OPP2.170420.017/3990407:user/release-keys'
05-17 15:27:53.222 15775-15775/? A/DEBUG: Revision: '0'
05-17 15:27:53.222 15775-15775/? A/DEBUG: ABI: 'arm'
05-17 15:27:53.222 15775-15775/? A/DEBUG: pid: 15749, tid: 15769, name: ybase.ossifrage  >>> io.keybase.ossifrage <<<
05-17 15:27:53.222 15775-15775/? A/DEBUG: signal 31 (SIGSYS), code 1 (SYS_SECCOMP), fault addr --------
05-17 15:27:53.222 15775-15775/? A/DEBUG: Cause: seccomp prevented call to disallowed arm system call 142
05-17 15:27:53.223 15775-15775/? A/DEBUG:     r0 00000000  r1 00000000  r2 00000000  r3 00000000
05-17 15:27:53.223 15775-15775/? A/DEBUG:     r4 cea92890  r5 00000000  r6 00000000  r7 0000008e
05-17 15:27:53.223 15775-15775/? A/DEBUG:     r8 00003d85  r9 dfbfeb40  sl 8b0885a0  fp 00002710
05-17 15:27:53.223 15775-15775/? A/DEBUG:     ip ec32f63c  sp cea9288c  lr cee3f8a8  pc cee3f8cc  cpsr 800f0010
05-17 15:27:53.258 15775-15775/? A/DEBUG: backtrace:
05-17 15:27:53.258 15775-15775/? A/DEBUG:     #00 pc 002af8cc  /data/app/io.keybase.ossifrage-ZEUhtPsnVNpH6KCvHYNzEQ==/lib/arm/libgojni.so (runtime.usleep+48)
05-17 15:27:53.258 15775-15775/? A/DEBUG:     #01 pc 00000000  <unknown>

I think system call 142 is sys_newselect, which makes sense -- that's how runtime.usleep() is implemented. But I don't understand why select(2) would be denied by the seccomp policy on Android O. Has anyone else noticed this, any ideas? Thanks!

@gopherbot gopherbot added this to the Unreleased milestone May 18, 2017

@cjb

This comment has been minimized.

Show comment
Hide comment
@cjb

cjb May 18, 2017

Contributor

Ah, I have a theory on what's happening. My theory is:

So it seems like the potential fixes are:

  1. Android adds sys_newselect to the syscall whitelist, even though it is not exposed by bionic.

  2. Golang switches runtime.usleep to use pselect6(2) instead of select(2), perhaps only on Android.

(1) seems preferable to me.

Contributor

cjb commented May 18, 2017

Ah, I have a theory on what's happening. My theory is:

So it seems like the potential fixes are:

  1. Android adds sys_newselect to the syscall whitelist, even though it is not exposed by bionic.

  2. Golang switches runtime.usleep to use pselect6(2) instead of select(2), perhaps only on Android.

(1) seems preferable to me.

@bradfitz

This comment has been minimized.

Show comment
Hide comment
@bradfitz

bradfitz May 18, 2017

Member

The Go project can much more easily do (2) than (1).

Member

bradfitz commented May 18, 2017

The Go project can much more easily do (2) than (1).

@cjb

This comment has been minimized.

Show comment
Hide comment
@cjb

cjb May 18, 2017

Contributor

Yeah, certainly true. (2) is quite a large change -- there's an argument change (struct timespec vs. struct timeval) as well as the syscall number, across every runtime/sys_linux_*.s.

Well, maybe we could limit the change to runtime/sys_linux_{amd64,arm,arm64}.s. I think those are the only platforms that can run Android?

What do you think? Thanks.

Contributor

cjb commented May 18, 2017

Yeah, certainly true. (2) is quite a large change -- there's an argument change (struct timespec vs. struct timeval) as well as the syscall number, across every runtime/sys_linux_*.s.

Well, maybe we could limit the change to runtime/sys_linux_{amd64,arm,arm64}.s. I think those are the only platforms that can run Android?

What do you think? Thanks.

@bradfitz

This comment has been minimized.

Show comment
Hide comment
@bradfitz

bradfitz May 18, 2017

Member

pselect was added to Linux in kernel 2.6.16 and Go requires 2.6.23 or later, so that seems fine to me at least.

@aclements, @ianlancetaylor?

Member

bradfitz commented May 18, 2017

pselect was added to Linux in kernel 2.6.16 and Go requires 2.6.23 or later, so that seems fine to me at least.

@aclements, @ianlancetaylor?

@bradfitz bradfitz modified the milestones: Go1.10, Unreleased May 18, 2017

@aclements

This comment has been minimized.

Show comment
Hide comment
@aclements

aclements May 18, 2017

Member

It makes me sad, but, yes, we could pretty easily switch to pselect. In fact, linux/arm64 already uses pselect. Of course, Go binaries that haven't been recompiled won't work with Android O.

Member

aclements commented May 18, 2017

It makes me sad, but, yes, we could pretty easily switch to pselect. In fact, linux/arm64 already uses pselect. Of course, Go binaries that haven't been recompiled won't work with Android O.

@gopherbot

This comment has been minimized.

Show comment
Hide comment

CL https://golang.org/cl/43641 mentions this issue.

@eliasnaur

This comment has been minimized.

Show comment
Hide comment
@eliasnaur

eliasnaur May 19, 2017

Contributor

Could this be included in Go 1.9? Android O will probably be out (much) sooner than Go 1.10.

Contributor

eliasnaur commented May 19, 2017

Could this be included in Go 1.9? Android O will probably be out (much) sooner than Go 1.10.

@gopherbot gopherbot closed this in 4dcba02 May 19, 2017

@aclements

This comment has been minimized.

Show comment
Hide comment
@aclements

aclements May 19, 2017

Member

It will be included in Go 1.9.

A more interesting question is whether we should include this in Go 1.8.3. I'll reopen this on Go 1.8.3 for consideration.

Member

aclements commented May 19, 2017

It will be included in Go 1.9.

A more interesting question is whether we should include this in Go 1.8.3. I'll reopen this on Go 1.8.3 for consideration.

@aclements aclements reopened this May 19, 2017

@aclements aclements modified the milestones: Go1.8.3, Go1.10 May 19, 2017

@cjb cjb referenced this issue in keybase/client May 20, 2017

Open

Crashes on open with Android O #7072

@cjb

This comment has been minimized.

Show comment
Hide comment
@cjb

cjb May 22, 2017

Contributor

@aclements Thanks for the quick fix! Verified that it works on device, but the simulator's still crashing -- even though I'm on an amd64 machine, gomobile compiles for 386 and that's what the Android simulator's using. So we'll need the same select()->pselect6() fix for sys_linux_386.s too.

Contributor

cjb commented May 22, 2017

@aclements Thanks for the quick fix! Verified that it works on device, but the simulator's still crashing -- even though I'm on an amd64 machine, gomobile compiles for 386 and that's what the Android simulator's using. So we'll need the same select()->pselect6() fix for sys_linux_386.s too.

@bradfitz

This comment has been minimized.

Show comment
Hide comment
@bradfitz

bradfitz May 23, 2017

Member

Punting to maybe Go 1.8.4 since this reportedly doesn't work yet anyway and we're doing Go 1.8.3 today.

Member

bradfitz commented May 23, 2017

Punting to maybe Go 1.8.4 since this reportedly doesn't work yet anyway and we're doing Go 1.8.3 today.

@bradfitz bradfitz modified the milestones: Go1.8.4, Go1.8.3 May 23, 2017

@gopherbot

This comment has been minimized.

Show comment
Hide comment

CL https://golang.org/cl/44011 mentions this issue.

@cjb

This comment has been minimized.

Show comment
Hide comment
@cjb

cjb May 23, 2017

Contributor

Thanks very much! Tested CL 44011 working in the simulator.

Contributor

cjb commented May 23, 2017

Thanks very much! Tested CL 44011 working in the simulator.

@bradfitz

This comment has been minimized.

Show comment
Hide comment
@bradfitz

bradfitz May 23, 2017

Member

@ianlancetaylor, is this something you're also comfortable backporting to the Go 1.8 branch?

Member

bradfitz commented May 23, 2017

@ianlancetaylor, is this something you're also comfortable backporting to the Go 1.8 branch?

@ianlancetaylor

This comment has been minimized.

Show comment
Hide comment
@ianlancetaylor

ianlancetaylor May 23, 2017

Contributor

This is fine for 1.8 as far as I'm concerned.

Contributor

ianlancetaylor commented May 23, 2017

This is fine for 1.8 as far as I'm concerned.

@gopherbot gopherbot closed this in e26b51b May 23, 2017

@bradfitz bradfitz modified the milestones: Go1.8.3, Go1.8.4 May 23, 2017

@aclements

This comment has been minimized.

Show comment
Hide comment
@aclements

aclements May 23, 2017

Member

Re-re-opened for cherry-pick.

Member

aclements commented May 23, 2017

Re-re-opened for cherry-pick.

@aclements aclements reopened this May 23, 2017

@gopherbot

This comment has been minimized.

Show comment
Hide comment

CL https://golang.org/cl/44002 mentions this issue.

@gopherbot

This comment has been minimized.

Show comment
Hide comment

CL https://golang.org/cl/44001 mentions this issue.

gopherbot pushed a commit that referenced this issue May 23, 2017

[release-branch.go1.8] runtime: use pselect6 for usleep on linux/amd6…
…4 and linux/arm

Android O black-lists the select system call because its libc, Bionic,
does not use this system call. Replace our use of select with pselect6
(which is allowed) on the platforms that support targeting Android.
linux/arm64 already uses pselect6 because there is no select on arm64,
so only linux/amd64 and linux/arm need changing. pselect6 has been
available since Linux 2.6.16, which is before Go's minimum
requirement.

Fixes #20409.

Change-Id: Ic526b5b259a9e01d2f145a1f4d2e76e8c49ce809
Reviewed-on: https://go-review.googlesource.com/43641
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
(cherry picked from commit 4dcba02)
Reviewed-on: https://go-review.googlesource.com/44001
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Chris Broadfoot <cbro@golang.org>

gopherbot pushed a commit that referenced this issue May 23, 2017

[release-branch.go1.8] runtime: use pselect6 for usleep on linux/386
Commit 4dcba02 replaced select with pselect6 on linux/amd64 and
linux/arm, but it turns out the Android emulator uses linux/386. This
makes the equivalent change there, too.

Fixes #20409 more.

Change-Id: If542d6ade06309aab8758d5f5f6edec201ca7670
Reviewed-on: https://go-review.googlesource.com/44011
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
(cherry picked from commit ecad34a40ea390ddf5ba2da8f3c3f2c5f15297c8)
Reviewed-on: https://go-review.googlesource.com/44002
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Chris Broadfoot <cbro@golang.org>

@broady broady closed this May 24, 2017

@golang golang locked and limited conversation to collaborators May 24, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.