Skip to content

Commit

Permalink
Make sure that only system_server uses the BinderService
Browse files Browse the repository at this point in the history
The android:ui process is running with the same UID, but in the system_app
context, so it should be treated like a normal app.
  • Loading branch information
rovo89 committed Mar 7, 2015
1 parent 6b49688 commit 9b647cc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
12 changes: 5 additions & 7 deletions src/de/robv/android/xposed/SELinuxHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static de.robv.android.xposed.XposedHelpers.callStaticMethod;
import static de.robv.android.xposed.XposedHelpers.findClass;
import android.os.Build;
import android.os.Process;
import de.robv.android.xposed.XposedHelpers.ClassNotFoundError;
import de.robv.android.xposed.services.BaseService;
import de.robv.android.xposed.services.BinderService;
Expand Down Expand Up @@ -59,7 +58,7 @@ public static BaseService getAppDataFileService() {

private static BaseService sServiceAppDataFile = null;

static void initOnce() {
/*package*/ static void initOnce() {
if (Build.VERSION.SDK_INT < 17)
return;

Expand All @@ -70,17 +69,16 @@ static void initOnce() {
} catch (ClassNotFoundError ignored) {};
}

static void initForProcess() {
/*package*/ static void initForProcess(String packageName) {
if (sIsSELinuxEnabled)
sContext = (String) callStaticMethod(sClassSELinux, "getContext");

if (sIsSELinuxEnforced) {
int uid = Process.myUid();
if (uid == 0) {
if (packageName == null) { // Zygote
sServiceAppDataFile = new ZygoteService();
} else if (uid == Process.SYSTEM_UID) {
} else if (packageName.equals("android")) { //system_server
sServiceAppDataFile = BinderService.getService(BinderService.TARGET_APP);
} else {
} else { // app
sServiceAppDataFile = new DirectAccessService();
}
} else {
Expand Down
8 changes: 4 additions & 4 deletions src/de/robv/android/xposed/XposedBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected static void main(String[] args) {
log("Initializing XposedBridge version " + XPOSED_BRIDGE_VERSION);

SELinuxHelper.initOnce();
SELinuxHelper.initForProcess();
SELinuxHelper.initForProcess(null);

runtime = getRuntime();
if (initNative()) {
Expand Down Expand Up @@ -180,10 +180,10 @@ private static void initForZygote() throws Throwable {
// normal process initialization (for new Activity, Service, BroadcastReceiver etc.)
findAndHookMethod(ActivityThread.class, "handleBindApplication", "android.app.ActivityThread.AppBindData", new XC_MethodHook() {
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
SELinuxHelper.initForProcess();
ActivityThread activityThread = (ActivityThread) param.thisObject;
ApplicationInfo appInfo = (ApplicationInfo) getObjectField(param.args[0], "appInfo");
String reportedPackageName = appInfo.packageName.equals("android") ? "system" : appInfo.packageName;
SELinuxHelper.initForProcess(reportedPackageName);
ComponentName instrumentationName = (ComponentName) getObjectField(param.args[0], "instrumentationName");
if (instrumentationName != null) {
XposedBridge.log("Instrumentation detected, disabling framework for " + reportedPackageName);
Expand Down Expand Up @@ -218,7 +218,7 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
Build.VERSION.SDK_INT < 19 ? "run" : "initAndLoop", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
SELinuxHelper.initForProcess();
SELinuxHelper.initForProcess("android");
loadedPackagesInProcess.add("android");

LoadPackageParam lpparam = new LoadPackageParam(sLoadedPackageCallbacks);
Expand All @@ -238,7 +238,7 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
findAndHookMethod("com.android.server.SystemServer", cl, "startBootstrapServices", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
SELinuxHelper.initForProcess();
SELinuxHelper.initForProcess("android");
loadedPackagesInProcess.add("android");

LoadPackageParam lpparam = new LoadPackageParam(sLoadedPackageCallbacks);
Expand Down

0 comments on commit 9b647cc

Please sign in to comment.