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

x/mobile: Calling net.InterfaceAddrs() fails on Android SDK 30 #40569

Open
halseth opened this issue Aug 4, 2020 · 101 comments
Open

x/mobile: Calling net.InterfaceAddrs() fails on Android SDK 30 #40569

halseth opened this issue Aug 4, 2020 · 101 comments
Labels
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

@halseth
Copy link

halseth commented Aug 4, 2020

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

$ go version
go version go1.14.6 darwin/amd64

$gomobile version
gomobile version +973feb4 Sat Aug 1 11:21:45 2020 +0000 (android,ios); androidSDK=/sdk/platforms/android-30

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/user/Library/Caches/go-build"
GOENV="/Users/user/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/user/golang"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.14.6/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.14.6/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/user/golang/src/golang.org/x/mobile/go.mod"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/kq/3436m_v11sg0l7zqtmv2r1gw0000gn/T/go-build713467523=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Calling net.InterfaceAddrs() fails on Android app targetting SDK version 30. With build.gradle looking like:

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.0"
    defaultConfig {
        applicationId "com.example.testapp"
        minSdkVersion 29
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

Building the exact same app targetting SDK 29 works, and returns no error:

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.0"
    defaultConfig {
        applicationId "com.example.testapp"
        minSdkVersion 29
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

What did you expect to see?

Targetting SDK 30 would behave no differently.

What did you see instead?

Calling net.InterfaceAddrs() results in error route ip+net: netlinkrib: permission denied when embedded in Android app targetting SDK 30 (R):

2020-08-04 15:10:21.386 15754-15754/? W/Thread-2: type=1400 audit(0.0:616): avc: denied { bind } for scontext=u:r:untrusted_app:s0:c158,c256,c512,c768 tcontext=u:r:untrusted_app:s0:c158,c256,c512,c768 tclass=netlink_route_socket permissive=0 b/155595000 app=com.example.testapp
@gopherbot gopherbot added the mobile Android, iOS, and x/mobile label Aug 4, 2020
@gopherbot gopherbot added this to the Unreleased milestone Aug 4, 2020
@halseth halseth changed the title x/mobile: Calling net.InterfaceAddrs() fails on Android ADK 30 x/mobile: Calling net.InterfaceAddrs() fails on Android SDK 30 Aug 4, 2020
@toothrot toothrot added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 4, 2020
@toothrot
Copy link
Contributor

toothrot commented Aug 4, 2020

/cc @hyangah

@hsjoberg
Copy link

hsjoberg commented Sep 8, 2020

Any more updates on this one? Android 11 was released today.

@vikulin
Copy link

vikulin commented Oct 23, 2020

Reproduced in Yggdrasil project for net.Interfaces():
https://github.com/yggdrasil-network/yggdrasil-go/blob/master/src/multicast/multicast.go#L192

@vikulin
Copy link

vikulin commented Nov 21, 2020

Any updates?

@rschulman
Copy link

I'd also love an update, if possible. This is blocking a project of mine right now.

@halseth
Copy link
Author

halseth commented Mar 9, 2021

Anybody looking into this?

@bt90
Copy link

bt90 commented Mar 24, 2021

Seems to be caused by these new restrictions in Android 11:

The following is a list of the ways that apps are affected by this change:

  • NetworkInterface.getHardwareAddress() returns null for every interface.
  • Apps cannot use the bind() function on NETLINK_ROUTE sockets.
  • The ip command does not return information about interfaces.
  • Apps cannot send RTM_GETLINK messages.

https://developer.android.com/training/articles/user-data-ids#mac-11-plus

@Catfriend1
Copy link

@DentonGentry
Copy link

https://developer.android.com/distribute/best-practices/develop/target-sdk

In August 2021, new apps in the Google Play Store will be required to target API level 30.
In November 2021, updates to existing apps in the Google Play Store will be required to target API level 30.

@uburoiubu
Copy link

Any updates on this one? This fix did not work for us: Catfriend1/syncthing-android#800

@simbadMarino
Copy link

Hello golang dev team, any update on this issue? This is blocking the Android 11 compatibility of my app :/. Thanks!

@DentonGentry
Copy link

We ended up developing an alternative using Android APIs, which we call instead of getInterfaceAddrs().
tailscale/tailscale-android#21

@simbadMarino
Copy link

simbadMarino commented Dec 10, 2021 via email

fengzie added a commit to mobazha/mobazha that referenced this issue Dec 12, 2021
@wlynxg
Copy link

wlynxg commented Dec 7, 2023

PS: I can confirm that I only see this problem on my Android 13 device. The older Android 8 device doesn't have that issue.

Yes, this problem exists since Android 11, if you need help, you can contact me.

@monkeyWie
Copy link

@wlynxg Hi, I've seen this PR hanging for a long time, is it has any progress now? Thanks!

@wlynxg
Copy link

wlynxg commented Dec 7, 2023

@wlynxg Hi, I've seen this PR hanging for a long time, is it has any progress now? Thanks!

The current main problem is that you cannot get the Android version number directly through go. However, you can tell go the Android version number by calling the go function on Android. There are no other problems for the time being.

@monkeyWie
Copy link

@wlynxg Hi, I've seen this PR hanging for a long time, is it has any progress now? Thanks!

The current main problem is that you cannot get the Android version number directly through go. However, you can tell go the Android version number by calling the go function on Android. There are no other problems for the time being.

Is the background that you want to use the Andoird version instead of os.IsPermission as a fallback?

@wlynxg
Copy link

wlynxg commented Dec 7, 2023

instead of os.IsPermission as a fallback?

yeah

@monkeyWie
Copy link

monkeyWie commented Dec 7, 2023

@wlynxg
Alright, if this is just to solve the cyclic dependency problem , can we use the oserror.ErrPermission assertion instead?

@wlynxg
Copy link

wlynxg commented Dec 7, 2023

@wlynxg Alright, if this is just to solve the cyclic dependency problem , can we use the oserror.ErrPermission assertion instead?

I fixed this problem in a later update and used oserror.ErrPermission

@monkeyWie
Copy link

@wlynxg Alright, if this is just to solve the cyclic dependency problem , can we use the assertion instead?oserror.ErrPermission

I fixed this problem in a later update and used oserror.ErrPermission

Sorry, my mistake. So what exactly is the problem? It looks like it can be merged now from my perspective.

@neilyoung
Copy link

Yes, this problem exists since Android 11, if you need help, you can contact me.

Hi @wlynxg, thanks for the offer. Well, I see the changes linked above, but I wouldn't know how to apply them. I generally know how to apply a PR, but in this scenario I'm just a GOMOBILE user under Android, and my GOLANG is maybe three days old or so :) I basically don't know, where to apply the change.

@wlynxg
Copy link

wlynxg commented Dec 7, 2023

Yes, this problem exists since Android 11, if you need help, you can contact me.

Hi @wlynxg, thanks for the offer. Well, I see the changes linked above, but I wouldn't know how to apply them. I generally know how to apply a PR, but in this scenario I'm just a GOMOBILE user under Android, and my GOLANG is maybe three days old or so :) I basically don't know, where to apply the change.

The official has not accepted this change for the time being. My suggestion is to temporarily use a third-party library on the Android platform instead of the net package to obtain network card information. You can refer to my code: https://github.com/wlynxg/anet.

@neilyoung
Copy link

neilyoung commented Dec 7, 2023

@wlynxg Thanks, did that right now. My problem is, I'm using net.Listen for a Unix socket. This is not part of your fork, seemingly.

EDIT: But even if you support that, I'm sure it is not my code which provokes that problem. It is the LiveKit SDKs problem, which most likely also uses net. I'm sure I can't convince them to use anet.

@wlynxg
Copy link

wlynxg commented Dec 7, 2023

@wlynxg Thanks, did that right now. My problem is, I'm using net.Listen for a Unix socket. This is not part of your fork, seemingly.

If you can provide relevant code, I can help you analyze it.

@neilyoung
Copy link

Well, yes. I'm just calling net once in my code with socket, err := net.Listen(socketType, address). This can't currently be replaced by anet, because missing. But as said in my post editing above: This is not my problem, it is a problem provoked by valid net calls from the LiveKit GOLANG SDK and so the problem needs to be solved in net most likely.

@bt90
Copy link

bt90 commented Dec 7, 2023

There are still unaddressed review comments which might explain why the PR has stalled.

https://go-review.googlesource.com/c/go/+/507415/3/src/syscall/netlink_linux.go

https://go-review.googlesource.com/c/go/+/507415/3/src/net/interface_linux.go

@neilyoung
Copy link

neilyoung commented Dec 11, 2023

I'm having a question: This problem is open since 2020. There is no workaround. Basically it means, that all Android apps, relying on GO in some way and "doing network things", will not work if they are running Android 11 or higher (at least the latter is for sure not that exotic anymore as it was in 2020)

I'm wondering why this issue is not making bigger waves, but most likely the relevance of gomobile for Android is lower than expected (which is kind of a pity, since it is in some limited ways a perfect replacement of C++).

But at least network things should be working.

@invented-pro
Copy link

Same suffering here. 4 years old bug, unbelievable!

Findings, while using same gomobile arr in Android App,

  • If App built with targetSdkVersion 29, it can run flawlessly on Android 11 device, but fail on Android 13 device.
  • If App built with targetSdkVersion 30 and above, it fails on all devices, with err msg "netlinkrib: permission denied"

Is there any workaround available, even only with targetSdkVersion 29?

@neilyoung
Copy link

@invented-pro At least for me it is solved. Apply this PR to a source installation of GOLANG #61089

@invented-pro
Copy link

I'll take a try. Thanks @neilyoung

@bt90
Copy link

bt90 commented Jan 22, 2024

@wlynxg what's the current state of the PR?

@neilyoung
Copy link

Merging is blocked for some reasons.

@invented-pro
Copy link

I'll take a try. Thanks @neilyoung

image

src + PR build on macos failed due to some tests.
which platfrom did you manage? @neilyoung

@neilyoung
Copy link

@invented-pro I'm on macOS 14.2.1, M1

@invented-pro
Copy link

@invented-pro I'm on macOS 14.2.1, M1

cannot build on 14.2.1 M2

@neilyoung
Copy link

neilyoung commented Jan 22, 2024

I had a recent binary installation on disk, then followed this gist https://go.dev/doc/install/source. Applied the patch manually. Made the patched GOLANG default then.

EDIT: Aarggh.... Realized right now, that I did it on Ubuntu 20.04. Sorry for this...

@invented-pro
Copy link

I had a recent binary installation on disk, then followed this gist https://go.dev/doc/install/source. Applied the patch manually. Made the patched GOLANG default then.

EDIT: Aarggh.... Realized right now, that I did it on Ubuntu 20.04. Sorry for this...

Thanks. I'll try on linux.

@invented-pro
Copy link

I built golang from src patched with PR61089, then used it to build aar file, finally it works as expected now on Android11 & 13, no "netlinkrib: permission denied" anymore.

Sincerely thank @wlynxg for the PR !!! Thank @neilyoung for guidance!!!

Hints to whom it may concern:

  • Golang built from src failed on my Mac M2; it's done on a Debian11 host with no error.
  • If you see error "zipdata redeclared in this block" during build, that's only because you build src multi times, time/tzdata/zzipdata.go is generated automatically, just delete it.
  • For linux env, don't forget to config Android SDK, NDK, etc.
  • GOROOT is your new go bin directory, don't point GOPATH to this GOROOT.
  • New aar file from Go 1.21 makes my App crash on Android frequently, while Go 1.20 seams ok.

@neilyoung
Copy link

@invented-pro Thanks for letting me know. Yes, this PR is really worth to be merged finally.

Thanks also for the extra information, even though I cannot confirm your last issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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