From 812d7698d8728bba08c5abc27d58413d17f776de Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 23 Mar 2022 10:22:46 -0700 Subject: [PATCH] Fix the cgroup directory owner in createProcessGroupInternal() Without this patch attempts to modify the blkio cgroup attributes by /system/bin/mediaserver fail as follows: 03-23 09:27:59.542 517 1811 E libprocessgroup: Failed to write '100' to /sys/fs/cgroup/./uid_1013/pid_517/io.bfq.weight: Permission denied This is because the mediaserver process is started as user 'media', because the mediaserver process is not in the system group and hence does not have permission to write into a directory with the following owner, group and permissions: vsoc_x86_64:/ # ls -ld /sys/fs/cgroup/./uid_1013/pid_517/io.bfq.weight -rwxrwxr-x 1 system system 0 2022-03-23 09:27 /sys/fs/cgroup/./uid_1013/pid_517/io.bfq.weight Bug: 213617178 Test: Booted Android in Cuttlefish and inspected logcat. Change-Id: I788acc9a137ae29898177f492cae2f954a9c811c Signed-off-by: Bart Van Assche --- libprocessgroup/processgroup.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/libprocessgroup/processgroup.cpp b/libprocessgroup/processgroup.cpp index 54772b6f9..e9106805e 100644 --- a/libprocessgroup/processgroup.cpp +++ b/libprocessgroup/processgroup.cpp @@ -460,7 +460,6 @@ static int createProcessGroupInternal(uid_t uid, int initialPid, std::string cgr struct stat cgroup_stat; mode_t cgroup_mode = 0750; - uid_t cgroup_uid = AID_SYSTEM; gid_t cgroup_gid = AID_SYSTEM; int ret = 0; @@ -468,11 +467,10 @@ static int createProcessGroupInternal(uid_t uid, int initialPid, std::string cgr PLOG(ERROR) << "Failed to get stats for " << cgroup; } else { cgroup_mode = cgroup_stat.st_mode; - cgroup_uid = cgroup_stat.st_uid; cgroup_gid = cgroup_stat.st_gid; } - if (!MkdirAndChown(uid_path, cgroup_mode, cgroup_uid, cgroup_gid)) { + if (!MkdirAndChown(uid_path, cgroup_mode, uid, cgroup_gid)) { PLOG(ERROR) << "Failed to make and chown " << uid_path; return -errno; } @@ -486,7 +484,7 @@ static int createProcessGroupInternal(uid_t uid, int initialPid, std::string cgr auto uid_pid_path = ConvertUidPidToPath(cgroup.c_str(), uid, initialPid); - if (!MkdirAndChown(uid_pid_path, cgroup_mode, cgroup_uid, cgroup_gid)) { + if (!MkdirAndChown(uid_pid_path, cgroup_mode, uid, cgroup_gid)) { PLOG(ERROR) << "Failed to make and chown " << uid_pid_path; return -errno; }