libtimeinstate: check for invalid buckets when reading map
The indexing logic in getUidsUpdatedConcurrentTimes relies on the keys
read from the BPF map being valid and assumes that the maximum bucket
number is determined by the number of CPUs. Add a check to fail
immediately if an invalid, higher bucket is encountered.
Also add a new test in libtimeinstate_test to check this case.
Test: added test case passes only if the check is present.
Bug: 166696502
Signed-off-by: Connor O'Brien <connoro@google.com>
Change-Id: I129a3b6491c869124dbbf5c694f82def9d5a8c98
diff --git a/libs/cputimeinstate/cputimeinstate.cpp b/libs/cputimeinstate/cputimeinstate.cpp
index 5e785b6..6058430 100644
--- a/libs/cputimeinstate/cputimeinstate.cpp
+++ b/libs/cputimeinstate/cputimeinstate.cpp
@@ -425,6 +425,7 @@
uint64_t newLastUpdate = lastUpdate ? *lastUpdate : 0;
do {
+ if (key.bucket > (gNCpus - 1) / CPUS_PER_ENTRY) return {};
if (lastUpdate) {
auto uidUpdated = uidUpdatedSince(key.uid, *lastUpdate, &newLastUpdate);
if (!uidUpdated.has_value()) return {};