AOSP中出现“su:setgid failed: Operation not permitted”错误

4

aosp版本为android-8.1.0_r18 手机型号nexus5x 工程版系统 我的应用是系统签名 图片

Shell中没有问题

# adb shell
# getenforce selinux status is disabled
Permissive
# su system
$ su

没有任何错误。

su的权限描述。

-rwsrwsrwx 1 root shell 11080 2021-06-07 17:14 /system/xbin/su

我修改了su.cpp文件。

    if (current_uid != AID_ROOT && current_uid != AID_SHELL && current_uid != AID_SYSTEM) error(1, 0, "not allowed");

应用程序代码
process = Runtime.getRuntime().exec("su");
                BufferedReader resultReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
                BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
                result = new StringBuffer();
                error = new StringBuffer();
                DataOutputStream os = new DataOutputStream(process.getOutputStream());
                process.waitFor();
                String line;
                while ((line = resultReader.readLine()) != null) {
                    line += "\n";
                    result.append(line);
                    Log.d("AC", line);
                }

                resultReader.close();

                while ((line = errorReader.readLine()) != null) {
                    line += "\n";
                    error.append(line);
                    Log.e("AC", "exec err:" + line);
                }

我得到了su:setgid失败:操作不允许的错误。


它可能被sepolicy阻止。尝试在内核日志中查找avc:denied:adb shell su root dmesg | grep 'avc:'。https://source.android.com/security/selinux/validate#reading_denials - Yong
@Yong 禁用SELinux

getenforce

宽容模式
- balalals
看起来它缺少 CAP_SETGID,而 shell 进程具备这个能力。https://man7.org/linux/man-pages/man7/capabilities.7.html - Yong
2
@user10357064,你找到什么了吗?我也被卡住了。 - Amit Hooda
1个回答

0
@Yong,我设置了su文件的cap_setgid权限,运行应用程序时出现以下错误:java.io.IOException: Cannot run program "su": error=1, Operation not permitted
bullhead:/ # getcap /system/xbin/su                                                                                                                                                                        
/system/xbin/su = cap_setgid+eip
bullhead:/ # 


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接