ANDROID: sched: Make uclamp changes depend on CAP_SYS_NICE
There is currently nothing preventing tasks from changing their per-task
clamp values in anyway that they like. The rationale is probably that
system administrators are still able to limit those clamps thanks to the
cgroup interface. However, this causes pain in a system where both
per-task and per-cgroup clamp values are expected to be under the
control of core system components (as is the case for Android).
To fix this, let's require CAP_SYS_NICE to change per-task clamp values.
There are ongoing discussions upstream about more flexible approaches
than this using the RLIMIT API -- see [1]. But the upstream discussion
has not converged yet, and this is way too late for UAPI changes in
android12-5.10 anyway, so let's apply this change which provides the
behaviour we want without actually impacting UAPIs.
This patch is cherry picked from commit 0bb784e623 because the original patch
was dropped due to upstream code merge. Also it uses a new Change-Id because it conflicts with the original one.
[1] https://lore.kernel.org/lkml/20210623123441.592348-4-qperret@google.com/
Bug: 187186685
Change-Id: Ib2dbd3a2fb8a8512714f36e626203898c0b8b67b
Signed-off-by: Quentin Perret <qperret@google.com>
Signed-off-by: Rick Yiu <rickyiu@google.com>
This commit is contained in:
@@ -514,6 +514,12 @@ static int user_check_sched_setscheduler(struct task_struct *p,
|
||||
if (p->sched_reset_on_fork && !reset_on_fork)
|
||||
goto req_priv;
|
||||
|
||||
if (!capable(CAP_SYS_NICE)) {
|
||||
/* Can't change util-clamps */
|
||||
if (attr->sched_flags & SCHED_FLAG_UTIL_CLAMP)
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
req_priv:
|
||||
|
||||
Reference in New Issue
Block a user