From 5cbcb52b96b5a2b97234381af59002fbe32593cd Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Mon, 11 Apr 2016 14:40:10 -0600 Subject: [PATCH] Rate-limit how often we collect wtf() logs. We've seen that aggressive Log.wtf() calls can DoS the system process, since we fork and collect recent logcat output for each call. After this CL, we rate-limit to only perform this heavy lifting 5 times during any given 10 second window of time. We still log the wtf() message to the binary event log. Bug: 28117774, 28052546, 27994717, 27381069 Change-Id: Ic91b23fe7ee26818083a8d40fd4850fcb9d93643 --- .../android/server/am/ActivityManagerService.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index 0f48d218b9d43..b11dc1182f339 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -13164,6 +13164,9 @@ public final class ActivityManagerService extends ActivityManagerNative } } + private volatile long mWtfClusterStart; + private volatile int mWtfClusterCount; + /** * Write a description of an error (crash, WTF, ANR) to the drop box. * @param eventType to include in the drop box tag ("crash", "wtf", etc.) @@ -13190,6 +13193,16 @@ public final class ActivityManagerService extends ActivityManagerNative // Exit early if the dropbox isn't configured to accept this report type. if (dbox == null || !dbox.isTagEnabled(dropboxTag)) return; + // Rate-limit how often we're willing to do the heavy lifting below to + // collect and record logs; currently 5 logs per 10 second period. + final long now = SystemClock.elapsedRealtime(); + if (now - mWtfClusterStart > 10 * DateUtils.SECOND_IN_MILLIS) { + mWtfClusterStart = now; + mWtfClusterCount = 1; + } else { + if (mWtfClusterCount++ >= 5) return; + } + final StringBuilder sb = new StringBuilder(1024); appendDropBoxProcessHeaders(process, processName, sb); if (process != null) {