diff options
| author | 2025-02-12 13:35:12 -0800 | |
|---|---|---|
| committer | 2025-02-12 13:35:12 -0800 | |
| commit | 1fce330b04b53ac4df42d9bbcb256057a2026b22 (patch) | |
| tree | 1f2791901f01c8994364af4e07868f86d49227da | |
| parent | ab293fe983f37dbe6712ef72db497e0249b9498d (diff) | |
| parent | 18818a3c23c4331b1c3fa7f0ed1bca235b09c4cb (diff) | |
Merge "Impose a threshold on the number of attributed op entries returned in a binder call" into udc-dev am: 18818a3c23
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/31591738
Change-Id: Ib7b3fd16b0979b52d91fe275af5c010ae5a9ad7d
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
| -rw-r--r-- | services/core/java/com/android/server/appop/AppOpsService.java | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/services/core/java/com/android/server/appop/AppOpsService.java b/services/core/java/com/android/server/appop/AppOpsService.java index fe98aa0be319..1211ee25bfd8 100644 --- a/services/core/java/com/android/server/appop/AppOpsService.java +++ b/services/core/java/com/android/server/appop/AppOpsService.java @@ -215,6 +215,12 @@ public class AppOpsService extends IAppOpsService.Stub { */ private static final int CURRENT_VERSION = 1; + /** + * The upper limit of total number of attributed op entries that can be returned in a binder + * transaction to avoid TransactionTooLargeException + */ + private static final int NUM_ATTRIBUTED_OP_ENTRY_THRESHOLD = 2000; + // Write at most every 30 minutes. static final long WRITE_DELAY = DEBUG ? 1000 : 30*60*1000; @@ -1434,6 +1440,8 @@ public class AppOpsService extends IAppOpsService.Stub { Manifest.permission.GET_APP_OPS_STATS, Binder.getCallingPid(), Binder.getCallingUid()) == PackageManager.PERMISSION_GRANTED; + int totalAttributedOpEntryCount = 0; + if (ops == null) { resOps = new ArrayList<>(); for (int j = 0; j < pkgOps.size(); j++) { @@ -1441,7 +1449,12 @@ public class AppOpsService extends IAppOpsService.Stub { if (opRestrictsRead(curOp.op) && !shouldReturnRestrictedAppOps) { continue; } - resOps.add(getOpEntryForResult(curOp)); + if (totalAttributedOpEntryCount > NUM_ATTRIBUTED_OP_ENTRY_THRESHOLD) { + break; + } + OpEntry opEntry = getOpEntryForResult(curOp); + resOps.add(opEntry); + totalAttributedOpEntryCount += opEntry.getAttributedOpEntries().size(); } } else { for (int j = 0; j < ops.length; j++) { @@ -1453,10 +1466,21 @@ public class AppOpsService extends IAppOpsService.Stub { if (resOps == null) { resOps = new ArrayList<>(); } - resOps.add(getOpEntryForResult(curOp)); + if (totalAttributedOpEntryCount > NUM_ATTRIBUTED_OP_ENTRY_THRESHOLD) { + break; + } + OpEntry opEntry = getOpEntryForResult(curOp); + resOps.add(opEntry); + totalAttributedOpEntryCount += opEntry.getAttributedOpEntries().size(); } } } + + if (totalAttributedOpEntryCount > NUM_ATTRIBUTED_OP_ENTRY_THRESHOLD) { + Slog.w(TAG, "The number of attributed op entries has exceeded the threshold. This " + + "could be due to DoS attack from malicious apps. The result is throttled."); + } + return resOps; } |