diff options
| author | 2022-10-29 18:43:31 +0000 | |
|---|---|---|
| committer | 2022-10-29 18:43:31 +0000 | |
| commit | 3aefd55cf8f950cb15cd5a52326db26d464ccd2b (patch) | |
| tree | 38eae6fe48cdac8ec85886e4ab5c0a0d13094444 | |
| parent | 8ed0832a3b20fbddad713dc30b5d017493303780 (diff) | |
| parent | 5985225e777cdb96b738aeda859dff49f6c6f853 (diff) | |
[automerge] DO NOT MERGE: Context#startInstrumentation could be started from SHELL only now. 2p: 5985225e77
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/20319635
Bug: 237766679
Change-Id: Ic925ffab89a9243984156bdcd1c8b8a898abf5ba
Merged-In: Ia08f225c21a3933067d066a578ea4af9c23e7d4c
Merged-In: I1b76f61c5fd6c9f7e738978592260945a606f40c
Merged-In: I3ea7aa27bd776fec546908a37f667f680da9c892
| -rw-r--r-- | services/core/java/com/android/server/am/ActivityManagerService.java | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index 32e7ec41992f..1faa690f1a01 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -13793,6 +13793,17 @@ public class ActivityManagerService extends IActivityManager.Stub throw new SecurityException(msg); } } + if (!Build.IS_DEBUGGABLE && callingUid != ROOT_UID && callingUid != SHELL_UID + && callingUid != SYSTEM_UID && !hasActiveInstrumentationLocked(callingPid)) { + // If it's not debug build and not called from root/shell/system uid, reject it. + final String msg = "Permission Denial: instrumentation test " + + className + " from pid=" + callingPid + ", uid=" + callingUid + + ", pkgName=" + getPackageNameByPid(callingPid) + + " not allowed because it's not started from SHELL"; + Slog.wtfQuiet(TAG, msg); + reportStartInstrumentationFailureLocked(watcher, className, msg); + throw new SecurityException(msg); + } ActiveInstrumentation activeInstr = new ActiveInstrumentation(this); activeInstr.mClass = className; @@ -13891,6 +13902,29 @@ public class ActivityManagerService extends IActivityManager.Stub } } + @GuardedBy("this") + private boolean hasActiveInstrumentationLocked(int pid) { + if (pid == 0) { + return false; + } + synchronized (mPidsSelfLocked) { + ProcessRecord process = mPidsSelfLocked.get(pid); + return process != null && process.getActiveInstrumentation() != null; + } + } + + private String getPackageNameByPid(int pid) { + synchronized (mPidsSelfLocked) { + final ProcessRecord app = mPidsSelfLocked.get(pid); + + if (app != null && app.info != null) { + return app.info.packageName; + } + + return null; + } + } + private boolean isCallerShell() { final int callingUid = Binder.getCallingUid(); return callingUid == SHELL_UID || callingUid == ROOT_UID; |