修改文件:
system/extras/su/su.c
system/core/include/private/android_filesystem_config.h
system/core/libcutils/fs_config.c
frameworks/base/core/jni/com_android_internal_os_Zygote.cpp
frameworks/base/cmds/app_process/app_main.cpp
device/qcom/msm8909/BoardConfig.mk
目的:为了在应用层App中可以通过调用su来获取root权限,进而执行一些命令。
在“main”函数中,注释掉uid的验证条件:
//uid_t current_uid = getuid();
//if (current_uid != AID_ROOT && current_uid != AID_SHELL) error(1, 0, "not allowed");
修改su程序的权限配置相关的内容:
/* the following two files are INTENTIONALLY set-uid, but they
* are NOT included on user builds. */
{ 06755, AID_ROOT, AID_SHELL, 0, "system/xbin/su" },
注释掉如下内容:
static void DropCapabilitiesBoundingSet(JNIEnv* env) {
/*
for (int i = 0; prctl(PR_CAPBSET_READ, i, 0, 0, 0) >= 0; i++) {
int rc = prctl(PR_CAPBSET_DROP, i, 0, 0, 0);
if (rc == -1) {
if (errno == EINVAL) {
ALOGE("prctl(PR_CAPBSET_DROP) failed with EINVAL. Please verify "
"your kernel is compiled with file capabilities support");
} else {
RuntimeAbort(env, __LINE__, "prctl(PR_CAPBSET_DROP) failed");
}
}
}
*/
}
注释“main”函数中的如下内容:
/*
if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) < 0) {
// Older kernels don't understand PR_SET_NO_NEW_PRIVS and return
// EINVAL. Don't die on such kernels.
if (errno != EINVAL) {
LOG_ALWAYS_FATAL("PR_SET_NO_NEW_PRIVS failed: %s", strerror(errno));
return 12;
}
}
*/
在启动参数“BOARD_KERNEL_CMDLINE”中加入对SELinux的设置“androidboot.selinux=permissive”,放宽权限:
BOARD_KERNEL_CMDLINE := console=ttyHSL0,115200,n8 androidboot.selinux=permissive androidboot.console=ttyHSL0 androidboot.hardware=qcom msm_rtb.filter=0x237 ehci-hcd.park=3 androidboot.bootdevice=7824900.sdhci lpm_levels.sleep_disabled=1 earlyprintk
或者
BOARD_KERNEL_CMDLINE := androidboot.selinux=permissive