@@ -505,8 +505,9 @@ Status ServiceManager::addService(const std::string& name, const sp<IBinder>& bi
505505 return Status::fromExceptionCode (Status::EX_SECURITY, " App UIDs cannot add services." );
506506 }
507507
508- if (!mAccess ->canAdd (ctx, name)) {
509- return Status::fromExceptionCode (Status::EX_SECURITY, " SELinux denied." );
508+ std::optional<std::string> accessorName;
509+ if (auto status = canAddService (ctx, name, &accessorName); !status.isOk ()) {
510+ return status;
510511 }
511512
512513 if (binder == nullptr ) {
@@ -888,8 +889,9 @@ Status ServiceManager::registerClientCallback(const std::string& name, const sp<
888889 }
889890
890891 auto ctx = mAccess ->getCallingContext ();
891- if (!mAccess ->canAdd (ctx, name)) {
892- return Status::fromExceptionCode (Status::EX_SECURITY, " SELinux denied." );
892+ std::optional<std::string> accessorName;
893+ if (auto status = canAddService (ctx, name, &accessorName); !status.isOk ()) {
894+ return status;
893895 }
894896
895897 auto serviceIt = mNameToService .find (name);
@@ -1051,8 +1053,9 @@ Status ServiceManager::tryUnregisterService(const std::string& name, const sp<IB
10511053 }
10521054
10531055 auto ctx = mAccess ->getCallingContext ();
1054- if (!mAccess ->canAdd (ctx, name)) {
1055- return Status::fromExceptionCode (Status::EX_SECURITY, " SELinux denied." );
1056+ std::optional<std::string> accessorName;
1057+ if (auto status = canAddService (ctx, name, &accessorName); !status.isOk ()) {
1058+ return status;
10561059 }
10571060
10581061 auto serviceIt = mNameToService .find (name);
@@ -1110,6 +1113,23 @@ Status ServiceManager::tryUnregisterService(const std::string& name, const sp<IB
11101113 return Status::ok ();
11111114}
11121115
1116+ Status ServiceManager::canAddService (const Access::CallingContext& ctx, const std::string& name,
1117+ std::optional<std::string>* accessor) {
1118+ if (!mAccess ->canAdd (ctx, name)) {
1119+ return Status::fromExceptionCode (Status::EX_SECURITY, " SELinux denied for service." );
1120+ }
1121+ #ifndef VENDORSERVICEMANAGER
1122+ *accessor = getVintfAccessorName (name);
1123+ #endif
1124+ if (accessor->has_value ()) {
1125+ if (!mAccess ->canAdd (ctx, accessor->value ())) {
1126+ return Status::fromExceptionCode (Status::EX_SECURITY,
1127+ " SELinux denied for the accessor of the service." );
1128+ }
1129+ }
1130+ return Status::ok ();
1131+ }
1132+
11131133Status ServiceManager::canFindService (const Access::CallingContext& ctx, const std::string& name,
11141134 std::optional<std::string>* accessor) {
11151135 if (!mAccess ->canFind (ctx, name)) {
0 commit comments