After commit a509a7cd7974 (sched/uclamp: Extend sched_setattr() to support utilization clamping), using sched_getattr with size 48 will return E2BIG.
This breaks, for example, chrt. $ chrt -p $$ chrt: failed to get pid 26306's policy: Argument list too long $ With this fix, when using the old size, the utilization clamping values will be absent from sched_attr. When using the new size or some larger size, they will be present. After the fix, chrt works again. $ chrt -p $$ pid 4649's current scheduling policy: SCHED_OTHER pid 4649's current scheduling priority: 0 $ The drawback with this solution is that userspace will ignore there are non-default utilization clamps, but it's arguable whether returning E2BIG in this case makes sense when that same userspace doesn't know about those values anyway. Signed-off-by: Thadeu Lima de Souza Cascardo <casca...@canonical.com> Fixes: a509a7cd7974 (sched/uclamp: Extend sched_setattr() to support utilization clamping) Cc: Patrick Bellasi <patrick.bell...@arm.com> --- kernel/sched/core.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 0fd67281e656..0ccc7fa80da6 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -5183,8 +5183,10 @@ SYSCALL_DEFINE4(sched_getattr, pid_t, pid, struct sched_attr __user *, uattr, attr.sched_nice = task_nice(p); #ifdef CONFIG_UCLAMP_TASK - attr.sched_util_min = p->uclamp_req[UCLAMP_MIN].value; - attr.sched_util_max = p->uclamp_req[UCLAMP_MAX].value; + if (size >= SCHED_ATTR_SIZE_VER1) { + attr.sched_util_min = p->uclamp_req[UCLAMP_MIN].value; + attr.sched_util_max = p->uclamp_req[UCLAMP_MAX].value; + } #endif rcu_read_unlock(); -- 2.20.1