簡體   English   中英

SELinux用於從APP運行“ ps”命令的策略

[英]SELinux policy for running “ps” command from APP

我希望運行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;

-

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM