Android12开放root权限给上层系统级应用执行su
2026/9/1 13:30:49 网站建设 项目流程
1.需要编译userdebug版本
2.关闭selinux
android/device/softwinner/peony-perf1/BoardConfig.mk
ifneq ($(PRODUCT_BOARD),qa) -# BOARD_KERNEL_CMDLINE += selinux=1 androidboot.selinux=enforcing androidboot.dtbo_idx=0,1,2 +BOARD_KERNEL_CMDLINE += selinux=1 androidboot.selinux=permissive androidboot.dtbo_idx=0,1,2 elseBOARD_KERNEL_CMDLINE += selinux=1 androidboot.selinux=permissive androidboot.dtbo_idx=0,1,2 endif
3.修改su.cpp注释用户组权限检测
android/system/extras/su/su.cpp
int main(int argc, char** argv) { uid_t current_uid = getuid(); -if (current_uid != AID_ROOT && current_uid != AID_SHELL) error(1, 0, "not allowed"); +if (current_uid != AID_ROOT && current_uid != AID_SHELL && current_uid != AID_SYSTEM) error(1, 0, "not allowed"); // Handle -h and --help. ++argv; if (*argv && (strcmp(*argv, "--help") == 0 || strcmp(*argv, "-h") == 0)) {

4.su文件默认授予root权限

android/system/core/libcutils/fs_config.cpp
//static const struct fs_path_config android_dirs[] { 00755, AID_ROOT, AID_SHELL, 0, "system/vendor" }, -{ 00751, AID_ROOT, AID_SHELL, 0, "system/xbin" }, +{ 00755, AID_ROOT, AID_SHELL, 0, "system/xbin" }, { 00751, AID_ROOT, AID_SHELL, 0, "system/apex/*/bin" }, 💡 //static const struct fs_path_config android_files[] //the following two files are INTENTIONALLY set-uid, but they // are NOT included on user builds. { 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/procmem" }, -{ 04750, AID_ROOT, AID_SHELL, 0, "system/xbin/su" }, +{ 06755, AID_ROOT, AID_SHELL, 0, "system/xbin/su" },
android/frameworks/base/core/jni/com_android_internal_os_Zygote.cpp
static void DropCapabilitiesBoundingSet(fail_fn_t fail_fn) { +// for (int i = 0; prctl(PR_CAPBSET_READ, i, 0, 0, 0) >= 0; i++) {; +// if (prctl(PR_CAPBSET_DROP, i, 0, 0, 0) == -1) { +// if (errno == EINVAL) { +// ALOGE("prctl(PR_CAPBSET_DROP) failed with EINVAL. Please verify " +// "your kernel is compiled with file capabilities support"); +// } else { +// fail_fn(CREATE_ERROR("prctl(PR_CAPBSET_DROP, %d) failed: %s", i, strerror(errno))); +// } +// } +// }}
lichee/kernel/linux-4.9/security/commoncap.c
static int cap_prctl_drop(unsigned long cap){ struct cred *new; +// if (!ns_capable(current_user_ns(), CAP_SETPCAP)) +// return -EPERM; +// if (!cap_valid(cap)) +// return -EINVAL; new = prepare_creds(); if (!new) return -ENOMEM; cap_lower(new->cap_bset, cap); return commit_creds(new); }

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询