Skip to content

Commit a10520d

Browse files
committed
Fix ANGLE Driver Setting permission on multiuser builds
Flag: com.android.frameworks.gpuservice.flags.multiuser_permission_check Test: atest -c GraphicsDriverEnableAngleAsSystemDriverControllerJUnitTest Bug: b/389867658 Change-Id: I761519e00a8042006c1785d70fa7244073d3533a
1 parent 0499b3e commit a10520d

5 files changed

Lines changed: 53 additions & 4 deletions

File tree

services/gpuservice/Android.bp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ package {
77
default_applicable_licenses: ["frameworks_native_license"],
88
}
99

10+
aconfig_declarations {
11+
name: "gpuservice_flags",
12+
package: "com.android.frameworks.gpuservice.flags",
13+
container: "system",
14+
srcs: ["gpuservice_flags.aconfig"],
15+
}
16+
1017
cc_defaults {
1118
name: "gpuservice_defaults",
1219
cflags: [
@@ -19,6 +26,11 @@ cc_defaults {
1926
],
2027
}
2128

29+
cc_aconfig_library {
30+
name: "gpuservice_multiuser_flags_c_lib",
31+
aconfig_declarations: "gpuservice_flags",
32+
}
33+
2234
cc_aconfig_library {
2335
name: "gpuservice_flags_c_lib",
2436
aconfig_declarations: "graphicsenv_flags",
@@ -92,6 +104,9 @@ cc_library_static {
92104
srcs: [
93105
":libgpuservice_sources",
94106
],
107+
shared_libs: [
108+
"gpuservice_multiuser_flags_c_lib",
109+
],
95110
}
96111

97112
cc_defaults {
@@ -126,4 +141,7 @@ cc_binary {
126141
static_libs: [
127142
"libgpuservice",
128143
],
144+
shared_libs: [
145+
"gpuservice_multiuser_flags_c_lib",
146+
],
129147
}

services/gpuservice/GpuService.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
#include <binder/IResultReceiver.h>
2525
#include <binder/Parcel.h>
2626
#include <binder/PermissionCache.h>
27+
#include <com_android_frameworks_gpuservice_flags.h>
2728
#include <cutils/properties.h>
29+
#include <cutils/multiuser.h>
2830
#include <gpumem/GpuMem.h>
2931
#include <gpuwork/GpuWork.h>
3032
#include <gpustats/GpuStats.h>
@@ -38,6 +40,8 @@
3840
#include <thread>
3941
#include <memory>
4042

43+
namespace gpuservice_flags = com::android::frameworks::gpuservice::flags;
44+
4145
namespace android {
4246

4347
using base::StringAppendF;
@@ -113,11 +117,22 @@ void GpuService::toggleAngleAsSystemDriver(bool enabled) {
113117

114118
// only system_server with the ACCESS_GPU_SERVICE permission is allowed to set
115119
// persist.graphics.egl
116-
if (uid != AID_SYSTEM ||
117-
!PermissionCache::checkPermission(sAccessGpuServicePermission, pid, uid)) {
118-
ALOGE("Permission Denial: can't set persist.graphics.egl from setAngleAsSystemDriver() "
120+
if (gpuservice_flags::multiuser_permission_check()) {
121+
// retrieve the appid of Settings app on multiuser builds
122+
const int multiuserappid = multiuser_get_app_id(uid);
123+
if (multiuserappid != AID_SYSTEM ||
124+
!PermissionCache::checkPermission(sAccessGpuServicePermission, pid, uid)) {
125+
ALOGE("Permission Denial: can't set persist.graphics.egl from setAngleAsSystemDriver() "
126+
"pid=%d, uid=%d\n, multiuserappid=%d", pid, uid, multiuserappid);
127+
return;
128+
}
129+
} else {
130+
if (uid != AID_SYSTEM ||
131+
!PermissionCache::checkPermission(sAccessGpuServicePermission, pid, uid)) {
132+
ALOGE("Permission Denial: can't set persist.graphics.egl from setAngleAsSystemDriver() "
119133
"pid=%d, uid=%d\n", pid, uid);
120-
return;
134+
return;
135+
}
121136
}
122137

123138
std::lock_guard<std::mutex> lock(mLock);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package: "com.android.frameworks.gpuservice.flags"
2+
container: "system"
3+
4+
flag {
5+
name: "multiuser_permission_check"
6+
namespace: "gpu"
7+
description: "Whether to consider headless system user mode/multiuser when checking toggleAngleAsSystemDriver permission."
8+
bug: "389867658"
9+
metadata {
10+
purpose: PURPOSE_BUGFIX
11+
}
12+
}

services/gpuservice/tests/fuzzers/Android.bp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ cc_fuzz {
1313
"libgpuservice",
1414
"liblog",
1515
],
16+
shared_libs: [
17+
"gpuservice_multiuser_flags_c_lib",
18+
],
1619
fuzz_config: {
1720
cc: [
1821
"paulthomson@google.com",

services/gpuservice/tests/unittests/Android.bp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ cc_test {
8989
],
9090
header_libs: ["bpf_headers"],
9191
shared_libs: [
92+
"gpuservice_multiuser_flags_c_lib",
9293
"libbase",
9394
"libbinder",
9495
"libbpf_bcc",

0 commit comments

Comments
 (0)