mirror of
https://github.com/Divested-Mobile/DivestOS-Build.git
synced 2024-12-23 22:49:28 -05:00
082bc48c32
https://review.lineageos.org/q/topic:P_asb_2022-05 https://review.lineageos.org/q/topic:P_asb_2022-06 https://review.lineageos.org/q/topic:P_asb_2022-07 https://review.lineageos.org/q/topic:P_asb_2022-08 https://review.lineageos.org/q/topic:P_asb_2022-09 https://review.lineageos.org/q/topic:P_asb_2022-10 https://review.lineageos.org/q/topic:P_asb_2022-11 https://review.lineageos.org/q/topic:P_asb_2022-12 https://review.lineageos.org/q/topic:P_asb_2023-01 https://review.lineageos.org/q/topic:P_asb_2023-02 https://review.lineageos.org/q/topic:P_asb_2023-03 https://review.lineageos.org/q/topic:P_asb_2023-04 https://review.lineageos.org/q/topic:P_asb_2023-05 https://review.lineageos.org/q/topic:P_asb_2023-06 https://review.lineageos.org/q/topic:P_asb_2023-07 accounted for via manifest change: https://review.lineageos.org/c/LineageOS/android_external_freetype/+/361250 https://review.lineageos.org/q/topic:P_asb_2023-08 accounted for via manifest change: https://review.lineageos.org/c/LineageOS/android_external_freetype/+/364606 accounted for via patches: https://review.lineageos.org/c/LineageOS/android_system_ca-certificates/+/365328 https://review.lineageos.org/q/topic:P_asb_2023-09 https://review.lineageos.org/q/topic:P_asb_2023-10 https://review.lineageos.org/q/topic:P_asb_2023-11 accounted for via patches: https://review.lineageos.org/c/LineageOS/android_system_ca-certificates/+/374916 https://review.lineageos.org/q/topic:P_asb_2023-12 https://review.lineageos.org/q/topic:P_asb_2024-01 https://review.lineageos.org/q/topic:P_asb_2024-02 https://review.lineageos.org/q/topic:P_asb_2024-03 https://review.lineageos.org/q/topic:P_asb_2024-04 Signed-off-by: Tavi <tavi@divested.dev>
98 lines
4.5 KiB
Diff
98 lines
4.5 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Jing Ji <jji@google.com>
|
|
Date: Thu, 4 Aug 2022 11:36:26 -0700
|
|
Subject: [PATCH] DO NOT MERGE: Context#startInstrumentation could be started
|
|
from SHELL only now.
|
|
|
|
Or, if an instrumentation starts another instrumentation and so on,
|
|
and the original instrumentation is started from SHELL, allow all
|
|
Context#startInstrumentation calls in this chain.
|
|
|
|
Otherwise, it'll throw a SecurityException.
|
|
|
|
Bug: 237766679
|
|
Test: atest CtsAppTestCases:InstrumentationTest
|
|
Merged-In: Ia08f225c21a3933067d066a578ea4af9c23e7d4c
|
|
Merged-In: I1b76f61c5fd6c9f7e738978592260945a606f40c
|
|
Merged-In: I3ea7aa27bd776fec546908a37f667f680da9c892
|
|
Change-Id: I7ca7345b064e8e74f7037b8fa3ed45bb6423e406
|
|
(cherry picked from commit 8c90891a38ecb5047e115e13baf700a8b486a5d1)
|
|
Merged-In: I7ca7345b064e8e74f7037b8fa3ed45bb6423e406
|
|
---
|
|
.../server/am/ActivityManagerService.java | 34 +++++++++++++++++++
|
|
.../com/android/server/am/ProcessRecord.java | 4 +++
|
|
2 files changed, 38 insertions(+)
|
|
|
|
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
|
|
index dd41196e62a4..f522b20f7ccd 100644
|
|
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
|
|
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
|
|
@@ -4907,6 +4907,26 @@ public class ActivityManagerService extends IActivityManager.Stub
|
|
return procState;
|
|
}
|
|
|
|
+ @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;
|
|
@@ -22264,6 +22284,8 @@ public class ActivityManagerService extends IActivityManager.Stub
|
|
IInstrumentationWatcher watcher, IUiAutomationConnection uiAutomationConnection,
|
|
int userId, String abiOverride) {
|
|
enforceNotIsolatedCaller("startInstrumentation");
|
|
+ final int callingUid = Binder.getCallingUid();
|
|
+ final int callingPid = Binder.getCallingPid();
|
|
userId = mUserController.handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(),
|
|
userId, false, ALLOW_FULL_ONLY, "startInstrumentation", null);
|
|
// Refuse possible leaked file descriptors
|
|
@@ -22312,6 +22334,18 @@ 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;
|
|
String defProcess = ai.processName;;
|
|
diff --git a/services/core/java/com/android/server/am/ProcessRecord.java b/services/core/java/com/android/server/am/ProcessRecord.java
|
|
index b15cf6a606cc..5e14e81acac6 100644
|
|
--- a/services/core/java/com/android/server/am/ProcessRecord.java
|
|
+++ b/services/core/java/com/android/server/am/ProcessRecord.java
|
|
@@ -870,4 +870,8 @@ final class ProcessRecord {
|
|
boolean hasForegroundServices() {
|
|
return foregroundServices;
|
|
}
|
|
+
|
|
+ ActiveInstrumentation getActiveInstrumentation() {
|
|
+ return instr;
|
|
+ }
|
|
}
|