我有一个通过本地套接字在本机级别(C ++ / JNI)连接的应用程序和服务。两者均使用目标API级别21构建,并且可以正常工作数年。最近,我已将它们升级到API级别23,并且 现在我不断收到此错误:
10-31 10:07:37.413 5760-5760/com.mycompany.myservice W/pool-151-thread: type=1400 audit(0.0:47942): avc: denied { connectto } for path=00494E554445565F4C4F43414C5F534F434B45545F53455256455200 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:r:untrusted_app_25:s0:c512,c768 tclass=unix_stream_socket permissive=0
10-31 10:17:44.373 4221-4221/com.mycompany.myapp W/pool-1-thread-1: type=1400 audit(0.0:72703): avc: denied { connectto } for path=00494E554445565F4C4F43414C5F534F434B45545F53455256455200 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:r:untrusted_app_25:s0:c512,c768 tclass=unix_stream_socket permissive=0
这些行在logcat中不断重复,仅此而已。
从此输出中可以看到,应用程序和服务均被视为不受信任。我知道API 23请求运行时权限,并且服务和应用程序请求都获得写,读和Internet运行时权限。
我的服务清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mycompany.myservice"
android:versionCode="1"
android:versionName="2.03.0018.104"
>
<uses-feature android:name="android.hardware.usb.host" />
<uses-sdk android:minSdkVersion="23" />
<!-- Required for TCP IPC and for local socket -->
<uses-permission android:name="android.permission.INTERNET"/>
<!-- Copy data to SDcard + recording + temporary files -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application android:label="@string/app_name">
<!-- Attacher hack -->
<activity
android:name="mynamespace.myservice$myserviceLauncher"
android:theme="@android:style/Theme.NoDisplay"
android:launchMode="singleInstance"
android:excludeFromRecents="true">
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
<action android:name="android.hardware.usb.action.USB_DEVICE_DETACHED" />
</intent-filter>
<meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" android:resource="@xml/device_filter" />
<meta-data android:name="android.hardware.usb.action.USB_DEVICE_DETACHED" android:resource="@xml/device_filter" />
</activity>
<!-- Detacher hack -->
<receiver android:name="mynamespace.myservice$Detacher">
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_DETACHED" />
</intent-filter>
<meta-data android:name="android.hardware.usb.action.USB_DEVICE_DETACHED" android:resource="@xml/device_filter" />
</receiver>
<service android:name="mynamespace.myservice">
</service>
</application>
</manifest>
我的应用清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mycompany.myapp"
android:versionCode="1"
android:versionName="2.01.00.06"
>
<uses-sdk
android:minSdkVersion="21"
android:targetSdkVersion="23" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:hardwareAccelerated="true"
android:allowBackup="true"
android:largeHeap="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:logo="@drawable/icon"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:screenOrientation="landscape" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
是否可以将我的服务和应用都添加到受信任的应用列表?
或者我该如何使本地套接字连接正常工作?
答案 0 :(得分:2)
这是由于平台的SE策略进一步收紧以消除潜在的攻击媒介所致。从适用于Android 6.0的AOSP发布信息中:
系统强化。通过SELinux实施的策略强化系统。这样可以更好地隔离用户,进行IOCTL过滤,减少暴露的服务的威胁,进一步收紧SELinux域以及/ proc访问的限制。
用于不受信任的应用程序的SE策略文件(第三方应用程序安装的默认策略文件)显式禁用对UNIX域套接字的访问:
https://android.googlesource.com/platform/external/sepolicy/+/android-6.0.1_r81/untrusted_app.te#141
Android的推荐做法是不对IPC使用套接字,对诸如调用之类的方法使用活页夹。