Add net_raw capability to android app

145 views
Skip to first unread message

Alexander Vilkov

unread,
Jan 23, 2023, 12:15:19 PM1/23/23
to android-ndk
Hi,

I've created the native library for android app. And loading it by the System.loadLibrary(). Android app is a prebuilt application of the custom AOSP build. And the native lib is using RAW sockets under the hood. Right now I'm receiving error on socket creation in .cpp file due the lack of CAP_NET_RAW for the socket creation. 

I'm wondering how to give such accesses to the app to be able to launch sockets? In terms of AOSP. Maybe some manipulations of the Linux sepolicies have to be made?

Currently my app is placed as .apk file in out/product/.../MyApp/myapp.apk and the native lib in out/product/.../MyApp/lib/mylib.so 

Many thanks for the answers.

enh

unread,
Jan 23, 2023, 12:29:12 PM1/23/23
to andro...@googlegroups.com
On Mon, Jan 23, 2023 at 9:15 AM Alexander Vilkov <sasha.bt...@gmail.com> wrote:
Hi,

I've created the native library for android app. And loading it by the System.loadLibrary(). Android app is a prebuilt application of the custom AOSP build. And the native lib is using RAW sockets under the hood. Right now I'm receiving error on socket creation in .cpp file due the lack of CAP_NET_RAW for the socket creation. 

I'm wondering how to give such accesses to the app to be able to launch sockets? In terms of AOSP. Maybe some manipulations of the Linux sepolicies have to be made?

no, there's no supported way to do this for apps.

yes, if this is just for a custom build, you'd have to do something like that. (search for net_raw in the sepolicy files. you'll definitely need to read https://source.android.com/docs/security/features/selinux/device-policy if you haven't already. sepolicy is hard.)
 
Currently my app is placed as .apk file in out/product/.../MyApp/myapp.apk and the native lib in out/product/.../MyApp/lib/mylib.so 

Many thanks for the answers.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/b50f6bda-24e1-4cf2-9451-3f562eede27bn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages