Android ServiceManager: add_service('nfc_settings',97) uid=1027 - PERMISSION DENIED

今天遇到一问题,刷机后设备开机启动就不断报NFC-service异常问题,然后紧接着就恢复出厂设置进入Recerver 模式,抓log看是因为NFC的SElinux权限问题,百度了一下selinux的权限问题,就网上所说的该有文件中都在对此NFC服务有权限定义,且此套源码的其它项目也未出现此问题,且userdebug版本与eng版本也未出现此问题

     后面....,这问题是因为把Selinux关闭了造成的问题,到alps\system\core\init\Android.mk文件中的

ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
init_options += \
    -DALLOW_LOCAL_PROP_OVERRIDE=1 \
    -DALLOW_PERMISSIVE_SELINUX=1 \
    -DREBOOT_BOOTLOADER_ON_PANIC=1 \
    -DDUMP_ON_UMOUNT_FAILURE=1
else
ifeq ($(strip $(MTK_BUILD_ROOT)),yes)
init_options += \
    -DALLOW_LOCAL_PROP_OVERRIDE=1 \
    -DALLOW_PERMISSIVE_SELINUX=1 \
    -DREBOOT_BOOTLOADER_ON_PANIC=1 \
    -DDUMP_ON_UMOUNT_FAILURE=1
else
init_options += \
    -DALLOW_LOCAL_PROP_OVERRIDE=0 \
    -DALLOW_PERMISSIVE_SELINUX=1 \//从0修改1
    -DREBOOT_BOOTLOADER_ON_PANIC=0 \
    -DDUMP_ON_UMOUNT_FAILURE=0
endif

第二部分修改

03-01 00:14:28.663518   349   349 E SELinux : avc:  denied  { add } for service=nfc_settings pid=4570 uid=1027 scontext=u:r:nfc:s0 tcontext=u:object_r:default_android_service:s0 tclass=service_manager
03-01 00:14:28.663652   349   349 E ServiceManager: add_service('nfc_settings',97) uid=1027 - PERMISSION DENIED
03-01 00:14:28.664463  4570  4570 D AndroidRuntime: Shutting down VM
03-01 00:14:28.681301  1050  4588 D AES     : onEndOfErrorDumpThread: system_app_crash Process: com.android.nfc
03-01 00:14:28.681301  1050  4588 D AES     : PID: 4570
03-01 00:14:28.681301  1050  4588 D AES     : Flags: 0x10c8be4d
03-01 00:14:28.681301  1050  4588 D AES     : Package: com.android.nfc v26 (8.0.0)
03-01 00:14:28.681301  1050  4588 D AES     : Foreground: No
03-01 00:14:28.681301  1050  4588 D AES     : Build: KTE/t7/t7:8.0.0/O00623/1574390874:user/test-keys
03-01 00:14:28.681301  1050  4588 D AES     : 
03-01 00:14:28.681301  1050  4588 D AES     : java.lang.RuntimeException: Unable to create application com.android.nfc.NfcApplication: java.lang.SecurityException
03-01 00:14:28.681301  1050  4588 D AES     :     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5955)
03-01 00:14:28.681301  1050  4588 D AES     :     at android.app.ActivityThread.-wrap1(Unknown Source:0)
03-01 00:14:28.681301  1050  4588 D AES     :     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1726)
03-01 00:14:28.681301  1050  4588 D AES     :     at android.os.Handler.dispatchMessage(Handler.java:108)
03-01 00:14:28.681301  1050  4588 D AES     :     at android.os.Looper.loop(Looper.java:206)
03-01 00:14:28.681301  1050  4588 D AES     :     at android.app.ActivityThread.main(ActivityThread.java:6733)
03-01 00:14:28.681301  1050  4588 D AES     :     at java.lang.reflect.Method.invoke(Native Method)
03-01 00:14:28.681301  1050  4588 D AES     :     at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
03-01 00:14:28.681301  1050  4588 D AES     :     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:845)
03-01 00:14:28.681301  1050  4588 D AES     : Caused by: java.lang.SecurityException
03-01 00:14:28.681301  1050  4588 D AES     :     at android.os.BinderProxy.transactNative(Native Method)
03-01 00:14:28.681301  1050  4588 D AES     :     at android.os.BinderProxy.transact(Binder.java:748)
03-01 00:14:28.681301  1050  4588 D AES     :     at android.os.ServiceManagerProxy.addService(ServiceManagerNative.java:150)
03-01 00:14:28.681301  1050  4588 D AES     :     at android.os.ServiceManager.addService(ServiceManager.java:88)
03-01 00:14:28.681301  1050  4588 D AES     :     at com.android.nfc.NfcService.<init>(NfcService.java:861)
03-01 00:14:28.681301  1050  4588 D AES     :     at com.android.nfc.NfcApplication.onCreate(NfcApplication.java:66)
03-01 00:14:28.681301  1050  4588 D AES     :     at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1118)
03-01 00:14:28.681301  1050  4588 D AES     :     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5952)
03-01 00:14:28.681301  1050  4588 D AES     :     ... 8 more
03-01 00:14:28.681301  1050  4588 D AES     :  4570
03-01 00:14:28.681434  1050  4588 W AES     : Exception Log handling...
03-01 00:14:28.683058  1050  4588 D AES     : ExceptionLog: notify aed
03-01 00:14:28.683142  1050  4588 D AES     :     process : com.android.nfc
03-01 00:14:28.683157  1050  4588 D AES     :      module : com.android.nfc v26 (8.0.0)
03-01 00:14:28.683157  1050  4588 D AES     : 
03-01 00:14:28.683169  1050  4588 D AES     :       cause : system_app_crash
03-01 00:14:28.683182  1050  4588 D AES     :       pid : 4570
03-01 00:14:28.683201  1050  4588 D AEE_LIBAEE: shell: raise_exp(4, 4570, -1361051648, com.android.nfc, 0x0x728f238040, 0x0x0)
03-01 00:14:28.684653  1050  4588 D AEE_LIBAEE: com.mtk.aee.aed_64shell: connected with AED OK
03-01 00:14:28.685154   621   621 D AEE_AED : $===AEE===AEE===AEE===$
03-01 00:14:28.685203   621   621 D AEE_AED : p 1 poll events 1 revents 1
03-01 00:14:28.685461   621   621 D AEE_AED : PPM cpu cores:10, online:3
03-01 00:14:28.690180   621   621 D AEE_AED : aed_main_fork_worker: generator 0x769403c020, worker 0x7ff3e5ede8, recv_fd 10
03-01 00:14:28.692328  4589  4589 D AEE_AED : read success, handling msg (Ind, AE_IND_EXP_RAISED)
03-01 00:14:28.692876  4589  4589 I AEE_AED : [preset_info] pid: 4570, tid: -1361051648, name: UNKNOWN  >>> com.android.nfc <<<
03-01 00:14:28.693067  4589  4589 D AEE_AED : u:r:nfc:s0
03-01 00:14:28.693111  4589  4589 V AEE_AED : dashboard_record_update() : rec->module = com.android.nfc 
03-01 00:14:28.693125  4589  4589 D AEE_AED : Skip duplicated exception ! 
03-01 00:14:28.693139  4589  4589 D AEE_AED : Exception Class: 4 
03-01 00:14:28.693149  4589  4589 D AEE_AED : Module: com.android.nfc 
03-01 00:14:28.693157  4589  4589 D AEE_AED : Count: 14 
03-01 00:14:28.693167  4589  4589 D AEE_AED : Last exception time: 1519863267 
03-01 00:14:28.693167  4589  4589 D AEE_AED :  
03-01 00:14:28.693177  4589  4589 V AEE_AED : process session - skipped 
03-01 00:14:28.693326  1050  4588 D AEE_LIBAEE: shell: got the request (cmd:Ind,AE_IND_LOG_CLOSE)
03-01 00:14:28.693366  1050  4588 D AEE_LIBAEE: shell: Got session close ind from AED
03-01 00:14:28.697469   621   621 D AEE_AED : clear ppm settings
03-01 00:14:28.698565   621   621 D AEE_AED : $===AEE===AEE===AEE===$
03-01 00:14:28.704135  1050  1059 I zygote64: Background concurrent copying GC freed 99306(4MB) AllocSpace objects, 5(100KB) LOS objects, 42% free, 7MB/12MB, paused 400us total 104.300ms
03-01 00:14:28.706417  1050  1057 I BufferQueue: [SurfaceTexture-1-1050-0](this:0x72841c1800,id:8,api:1,p:-1,c:-1) ~BufferQueueCore
03-01 00:14:28.707332  1050  1070 D WindowClient: Add to mViews: DecorView@b729220[nfc], this = android.view.WindowManagerGlobal@ebd278a
03-01 00:14:28.707765  1050  2823 D OpenGLRenderer: CanvasContext() 0x7283376740


[Description]
linux SELinux 分成Enforce 以及 Permissive 两种模式,如何进行设置与确认当前SELinux模式?
 
[Keyword]
android, SELinux, Enforce, Permissive
 
[Solution]
在Android KK 4.4 版本后,Google 有正式有限制的启用SELinux, 来增强android 的安全保护。
在ENG 版本中, 可以使用setenforce 命令进行设置:

(USERDEBUG版本中需要先执行adb root命令获取root权限)
adb shell setenforce 0    //设置成permissive 模式
adb shell setenforce 1    //设置成enforce 模式
 
在ENG/USER 版本中,都可以使用getenforce 命令进行查询,如:
root@mt6589_phone_720pv2:/ # getenforce
getenforce
Enforcing
 
如果想开机一启动就设置模式,你可以用下面方式:
KK 版本:更新mediatek/custom/{platform}/lk/rules_platform.mk
L  版本: 更新bootable/bootloader/lk/platform/mt6xxx/rules.mk

M/N/O 版本: 更新vendor/mediatek/proprietary/bootable/bootloader/lk/platform/mt6XXX/rules.mk
# choose one of following value -> 1: disabled/ 2: permissive /3: enforcing
SELINUX_STATUS := 3
可直接调整这个SELINUX_STATUS这个的值为2, 严禁直接设置成1:disabled, 此会造成生成的文件无法正确的打上标签,造成在再次设置成enforcing时,难以预料的情况发生。

 

注意的是:

在L 版本后, Google 要求强制性开启enforcing mode, 前面的设置只针对userdebug, eng 版本有效, 如果要对user 版本有效,

需要修改system/core/init/Android.mk

如果是L 版本 新增:
ifeq ($(strip $(TARGET_BUILD_VARIANT)),user)
LOCAL_CFLAGS += -DALLOW_DISABLE_SELINUX=1
endif

 

如果是在M 版本 将:

ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
init_options += -DALLOW_LOCAL_PROP_OVERRIDE=1 -DALLOW_DISABLE_SELINUX=1
init_options += -DINIT_ENG_BUILD
else

修改成:
ifneq (,$(filter user userdebug eng,$(TARGET_BUILD_VARIANT)))
init_options += -DALLOW_LOCAL_PROP_OVERRIDE=1 -DALLOW_DISABLE_SELINUX=1
init_options += -DINIT_ENG_BUILD
else

 

N/O 版本上宏ALLOW_DISABLE_SELINUX 被Google 用 ALLOW_PERMISSIVE_SELINUX 替换了, 即 N 版本后已经禁止直接关闭掉selinux, 只能设定成permissive , 否则将直接无法开机.

 

另外前面的处理方式比较文雅, 不涉及代码修改, 附加 N/O 版本最快速暴力设定 permissive mode 的手法.

/system/core/init/init.cpp

static bool selinux_is_enforcing(void)
{
    return false; //force set selinux permissive.
    if (ALLOW_PERMISSIVE_SELINUX) {
        return selinux_status_from_cmdline() == SELINUX_ENFORCING;
    }
    return true;
}

P0:

/system/core/init/selinux.cpp

bool IsEnforcing() {
 return false; //force set selinux permissive.
 if (ALLOW_PERMISSIVE_SELINUX) {
 return StatusFromCmdline() == SELINUX_ENFORCING;
 }
 return true;
}

 需要注意的是, Google 要求强制性开启SELinux Enforcing Mode, 如果您关闭,将无法通过Google CTS. 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值