diff options
| author | 2025-02-12 13:59:18 -0800 | |
|---|---|---|
| committer | 2025-02-12 13:59:18 -0800 | |
| commit | c3d078a32ff664ded3fc34cdf1f12fa49e40dc65 (patch) | |
| tree | 6d711cf33e41e4d9baada28a59c586bf1242ca70 | |
| parent | 36a20c19cf2f799c6c3ef4ed548a3be6c8f99e2b (diff) | |
| parent | af5f4eaba71ca15c9de3d44db85d4eb44a4761b0 (diff) | |
[DO NOT MERGE] Impose a threshold on the number of attributed op entries returned in a binder call am: 8e7990cecc am: af5f4eaba7
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/31593362
Change-Id: I4810a689aa68bebdd8965203501a8d2a26430830
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 055b7ea37d34..6f7d72cc43a9 100644 --- a/services/core/java/com/android/server/appop/AppOpsService.java +++ b/services/core/java/com/android/server/appop/AppOpsService.java @@ -232,6 +232,12 @@ public class AppOpsService extends IAppOpsService.Stub { * {@link #upgradeLocked(int)} below. The first version was 1 */ 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; @@ -2192,6 +2198,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++) { @@ -2199,7 +2207,12 @@ public class AppOpsService extends IAppOpsService.Stub { if (opRestrictsRead(curOp.op) && !shouldReturnRestrictedAppOps) { continue; } - resOps.add(getOpEntryForResult(curOp, elapsedNow)); + if (totalAttributedOpEntryCount > NUM_ATTRIBUTED_OP_ENTRY_THRESHOLD) { + break; + } + OpEntry opEntry = getOpEntryForResult(curOp, elapsedNow); + resOps.add(opEntry); + totalAttributedOpEntryCount += opEntry.getAttributedOpEntries().size(); } } else { for (int j = 0; j < ops.length; j++) { @@ -2211,10 +2224,21 @@ public class AppOpsService extends IAppOpsService.Stub { if (resOps == null) { resOps = new ArrayList<>(); } - resOps.add(getOpEntryForResult(curOp, elapsedNow)); + if (totalAttributedOpEntryCount > NUM_ATTRIBUTED_OP_ENTRY_THRESHOLD) { + break; + } + OpEntry opEntry = getOpEntryForResult(curOp, elapsedNow); + 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; } |