From 10458eca117abc6737a2efcd99f58e6a0b72437e Mon Sep 17 00:00:00 2001 From: Tej Singh Date: Tue, 17 Mar 2020 11:04:02 -0700 Subject: Enforce permission on native puller API Test: m Test: no security exceptions on boot Test: atest LibStatsPullTests Bug: 148955001 Change-Id: I4b06bfc41be2925270eaddd717f1499d98739dae --- apex/statsd/aidl/android/os/IStatsd.aidl | 14 +++++++++----- apex/statsd/tests/libstatspull/AndroidManifest.xml | 1 + cmds/statsd/src/StatsService.cpp | 17 +++++++++++++++-- data/etc/platform.xml | 2 ++ 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/apex/statsd/aidl/android/os/IStatsd.aidl b/apex/statsd/aidl/android/os/IStatsd.aidl index c8aec5337f6e..445ae1d7a13e 100644 --- a/apex/statsd/aidl/android/os/IStatsd.aidl +++ b/apex/statsd/aidl/android/os/IStatsd.aidl @@ -190,10 +190,12 @@ interface IStatsd { long timeoutMillis,in int[] additiveFields, IPullAtomCallback pullerCallback); - /** - * Registers a puller callback function that, when invoked, pulls the data - * for the specified atom tag. - */ + /** + * Registers a puller callback function that, when invoked, pulls the data + * for the specified atom tag. + * + * Enforces the REGISTER_STATS_PULL_ATOM permission. + */ oneway void registerNativePullAtomCallback(int atomTag, long coolDownNs, long timeoutNs, in int[] additiveFields, IPullAtomCallback pullerCallback); @@ -203,7 +205,9 @@ interface IStatsd { oneway void unregisterPullAtomCallback(int uid, int atomTag); /** - * Unregisters any pullAtomCallback for the given atom. + * Unregisters any pullAtomCallback for the given atom + caller. + * + * Enforces the REGISTER_STATS_PULL_ATOM permission. */ oneway void unregisterNativePullAtomCallback(int atomTag); diff --git a/apex/statsd/tests/libstatspull/AndroidManifest.xml b/apex/statsd/tests/libstatspull/AndroidManifest.xml index bffd400bdb2c..0c669b051c86 100644 --- a/apex/statsd/tests/libstatspull/AndroidManifest.xml +++ b/apex/statsd/tests/libstatspull/AndroidManifest.xml @@ -21,6 +21,7 @@ + & additiveFields, const shared_ptr& pullerCallback) { - + if (!checkPermission(kPermissionRegisterPullAtom)) { + return exception( + EX_SECURITY, + StringPrintf("Uid %d does not have the %s permission when registering atom %d", + AIBinder_getCallingUid(), kPermissionRegisterPullAtom, atomTag)); + } VLOG("StatsService::registerNativePullAtomCallback called."); int32_t uid = AIBinder_getCallingUid(); mPullerManager->RegisterPullAtomCallback(uid, atomTag, coolDownNs, timeoutNs, additiveFields, @@ -1226,6 +1233,12 @@ Status StatsService::unregisterPullAtomCallback(int32_t uid, int32_t atomTag) { } Status StatsService::unregisterNativePullAtomCallback(int32_t atomTag) { + if (!checkPermission(kPermissionRegisterPullAtom)) { + return exception( + EX_SECURITY, + StringPrintf("Uid %d does not have the %s permission when unregistering atom %d", + AIBinder_getCallingUid(), kPermissionRegisterPullAtom, atomTag)); + } VLOG("StatsService::unregisterNativePullAtomCallback called."); int32_t uid = AIBinder_getCallingUid(); mPullerManager->UnregisterPullAtomCallback(uid, atomTag); diff --git a/data/etc/platform.xml b/data/etc/platform.xml index 6929d0d1879d..f63ec6bd04c3 100644 --- a/data/etc/platform.xml +++ b/data/etc/platform.xml @@ -190,6 +190,8 @@ + + -- cgit v1.2.3-59-g8ed1b