android - 从 APP 运行 "ps"命令的 SELinux 策略

标签 android linux selinux

我想运行 ps 命令来查找系统中正在运行的进程数。但是我在 M 中违反了 SElinux

private int read_procs() {
    int nProcs = 0;
    String line = null;

    // "ps" output
    try {
        Process p = Runtime.getRuntime().exec("ps");
        BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
        if (in == null)  {
            mLog.e("cmd output _in_ is null");
            return 1;
        }

        while ((line = in.readLine()) != null) {
            nProcs++;
        }
        in.close();
        mLog.i("Processes :" + (nProcs-1));
    } catch (Exception e) {
        e.printStackTrace();
    }

    return nProcs;
}

如何设置策略以允许“ps”命令访问:

 avc: denied { getattr } for path="/proc/2" dev="proc" ino=9461 scontext=u:r:system_app:s0 tcontext=u:r:kernel:s0 tclass=dir       permissive=0 ppid=3853 pcomm="Thread-52" tgid=3761 tgcomm="test:app"

谢谢

最佳答案

我通过添加如下规则解决了这个问题

allow  [source context] [target context object]:[type] [permission needed];

allow system_app kernel:dir getattr;

-

关于android - 从 APP 运行 "ps"命令的 SELinux 策略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35265039/

相关文章:

android - 如何从phonegap上的本地数据库中获取数据

linux - 如何使用awk/sed增加文件中数字的匹配模式?

linux - 使用 kickstart 文件向 Red Hat ISO 附加 rpm

android - 如何将 alpha 设置为 recyclerview 项目,除了点击一个

Android:仅加载大图像的细节

linux - 是否有可能阻止任何人从 ELF 二进制文件中剥离调试符号(例如,标签)?

linux - Apache 使用 SELinux 在 CentOS 7 上执行 MATLAB 二进制文件

android - Android 操作系统上的 TEE/HSM 支持

android - 为什么 SELinux 拒绝此访问

Android:如何捕捉线性布局中任何按钮的点击?