trusty: Increase limit on coverage counters

Keymaster has more than 4096 counters, so we need to allocate a larger
section for the libfuzzer extra counters. Increases the size of the
extra counters section to 16384.

Bug: 171750250
Test: atest libtrusty_coverage_test
Change-Id: Iaee2c74b6d0c7ae8a2e5a30525759f89f825a091
This commit is contained in:
Stephen Crane 2021-01-07 15:04:14 -08:00
parent 6bd77df8fc
commit 6735f8475e
1 changed files with 11 additions and 1 deletions

View File

@ -21,6 +21,7 @@
#include <trusty/fuzz/counters.h>
#include <android-base/logging.h>
#include <log/log.h>
#include <trusty/coverage/coverage.h>
#include <trusty/coverage/tipc.h>
@ -32,7 +33,8 @@ using android::base::Result;
* We don't know how many counters the coverage record will contain. So, eyeball
* the size of this section.
*/
__attribute__((section("__libfuzzer_extra_counters"))) volatile uint8_t counters[PAGE_SIZE];
static const size_t kMaxNumCounters = 0x4000;
__attribute__((section("__libfuzzer_extra_counters"))) volatile uint8_t counters[kMaxNumCounters];
namespace android {
namespace trusty {
@ -62,8 +64,16 @@ void ExtraCounters::Flush() {
volatile uint8_t* end = NULL;
record_->GetRawCounts(&begin, &end);
if (!begin || !end) {
ALOGE("Could not get raw counts from coverage record\n");
return;
}
size_t num_counters = end - begin;
if (num_counters > kMaxNumCounters) {
ALOGE("Too many counters (%zu) to fit in the extra counters section!\n", num_counters);
num_counters = kMaxNumCounters;
}
for (size_t i = 0; i < num_counters; i++) {
*(counters + i) = *(begin + i);
}