sched: only perform capability check on privileged operation
authorChristian Göttsche <cgzones@googlemail.com>
Wed, 15 Jun 2022 15:25:04 +0000 (17:25 +0200)
committerPeter Zijlstra <peterz@infradead.org>
Tue, 28 Jun 2022 07:08:29 +0000 (09:08 +0200)
commit700a78335fc28a59c307f420857fd2d4521549f8
treeaae5997212a93e654059896b14eb059f23e4173d
parentc64b551f6a338eb9724a2f9ef3dddf80ccef2894
sched: only perform capability check on privileged operation

sched_setattr(2) issues via kernel/sched/core.c:__sched_setscheduler()
a CAP_SYS_NICE audit event unconditionally, even when the requested
operation does not require that capability / is unprivileged, i.e. for
reducing niceness.
This is relevant in connection with SELinux, where a capability check
results in a policy decision and by default a denial message on
insufficient permission is issued.
It can lead to three undesired cases:
  1. A denial message is generated, even in case the operation was an
     unprivileged one and thus the syscall succeeded, creating noise.
  2. To avoid the noise from 1. the policy writer adds a rule to ignore
     those denial messages, hiding future syscalls, where the task
     performs an actual privileged operation, leading to hidden limited
     functionality of that task.
  3. To avoid the noise from 1. the policy writer adds a rule to allow
     the task the capability CAP_SYS_NICE, while it does not need it,
     violating the principle of least privilege.

Conduct privilged/unprivileged categorization first and perform a
capable test (and at most once) only if needed.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20220615152505.310488-1-cgzones@googlemail.com
kernel/sched/core.c