Skip to content

Commit

Permalink
Rirud should only allows u:r:zygote:s0 to connenct
Browse files Browse the repository at this point in the history
  • Loading branch information
yujincheng08 committed Aug 9, 2021
1 parent e8594e6 commit 5d176b0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 12 additions & 6 deletions rirud/src/main/java/riru/DaemonSocketServerThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.net.Credentials;
import android.net.LocalServerSocket;
import android.net.LocalSocket;
import android.os.SELinux;
import android.system.ErrnoException;
import android.system.Os;
import android.system.OsConstants;
Expand Down Expand Up @@ -336,16 +337,21 @@ private void startServer() throws IOException {
}

Credentials credentials = socket.getPeerCredentials();
if (credentials.getUid() != 0) {
var uid = credentials.getUid();
var pid = credentials.getPid();
var context = SELinux.getPidContext(pid);
if (uid != 0 || !context.equals("u:r:zygote:s0")) {
socket.close();
Log.w(TAG, "Accept from non-root (" +
"uid=" + credentials.getUid() + ", " +
"pid=" + credentials.getPid() + ")");
Log.w(TAG, "Unauthorized peer (" +
"uid=" + uid + ", " +
"pid=" + pid + ", " +
"context=" + context + ")");
continue;
}
Log.d(TAG, "Accepted " +
"uid=" + credentials.getUid() + " " +
"pid=" + credentials.getPid());
"uid=" + uid + ", " +
"pid=" + pid + ", " +
"context=" + context);

EXECUTOR.execute(() -> {
try {
Expand Down
2 changes: 2 additions & 0 deletions stub/src/main/java/android/os/SELinux.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public class SELinux {
public static final native String getFileContext(String path);

public static final native boolean setFileContext(String path, String context);

public static final native String getPidContext(int pid);
}

0 comments on commit 5d176b0

Please sign in to comment.