From 60dbeef46d3f6c696fd9586758bc6c1f94a84003 Mon Sep 17 00:00:00 2001 From: Alexander Potapenko Date: Mon, 8 Mar 2021 16:47:23 +0100 Subject: [PATCH] BootReceiver: cap the number of sent kernel memory corruptions Save the bandwidth by sending only the first few reports from a running kernel. Also fix a bug in the old code (strings must be compared with equals()). Bug: 172316664 Bug: 182159975 Test: running KFENCE manually Signed-off-by: Alexander Potapenko Change-Id: I3eb13596b5d9006637e110d000f64c46661cac4d --- services/core/java/com/android/server/BootReceiver.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/BootReceiver.java b/services/core/java/com/android/server/BootReceiver.java index d83e2fd2090d0..b7c5fba69c8a3 100644 --- a/services/core/java/com/android/server/BootReceiver.java +++ b/services/core/java/com/android/server/BootReceiver.java @@ -128,6 +128,9 @@ public class BootReceiver extends BroadcastReceiver { // Location of ftrace pipe for notifications from kernel memory tools like KFENCE and KASAN. private static final String ERROR_REPORT_TRACE_PIPE = "/sys/kernel/tracing/instances/bootreceiver/trace_pipe"; + // Stop after sending this many reports. See http://b/182159975. + private static final int MAX_ERROR_REPORTS = 8; + private static int sSentReports = 0; // Avoid reporing the same bug from processDmesg() twice. private static String sLastReportedBug = null; @@ -301,7 +304,7 @@ public class BootReceiver extends BroadcastReceiver { * - repeat the above steps till the last report is found. */ private void processDmesg(Context ctx) throws IOException { - + if (sSentReports == MAX_ERROR_REPORTS) return; /* * Only SYSTEM_KASAN_ERROR_REPORT and SYSTEM_KFENCE_ERROR_REPORT are supported at the * moment. @@ -352,7 +355,7 @@ public class BootReceiver extends BroadcastReceiver { } // Avoid sending the same bug report twice. - if (bugTitle == sLastReportedBug) return; + if (bugTitle.equals(sLastReportedBug)) return; final String reportTag = "SYSTEM_" + tool + "_ERROR_REPORT"; final DropBoxManager db = ctx.getSystemService(DropBoxManager.class); @@ -361,6 +364,7 @@ public class BootReceiver extends BroadcastReceiver { addTextToDropBox(db, reportTag, reportText, "/dev/kmsg", LOG_SIZE); sLastReportedBug = bugTitle; + sSentReports++; } private void removeOldUpdatePackages(Context context) {