Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795623332; b=1VOAhduPo0Zf4m3MI2sBVoHYkU8GFpX1vEQBPcLDOkYepz0zxoQHNIySxJk6kcBCGATZ +q30tleLK/mrKWaFWrNhsxjAgBCRr56zIC64JGi1Hkx2fAcMlpl1blItrWko0lVEFFS4n 2MMVBH2IDOZdsy/G508YzKBuBv4g8xpHz7pc0jwojixIhIGPQc/DNrWWvJ9D52EZBkF5E FK7kg4eD/P6TjVcHnDqS1ODtujaDDxSjykAJkZT8LyLWvgLB69QSC8VbIR5LRlmubGcyW rD1xkmtXuv8BuHyu6kWQxg2nE2zzJ0ejeEDc6l5mynhW8TYiQM+ppp6wpgidpPXnJ0g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795623332; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=M+WzXxjhDhD/IG32HPtzHvZncIIlO7kOMFaYO0Ht6og=; b=ehTyRnzBbM2haP2Yp6IFQHv25Y9NHeeYX0ju6mGFj4UFD0mv0LMyvu+cVf2ZjTOjsiZr 7GFs86uF+dY8jhIkiZOb6aNpRuOYL8RCGYrrqT+Jsq+HtywRK7OWPFbYePF1qpUK7euJW 0Ix6xVZxswtGRYzYR7OVVYMl2anGxAG0gDj8dRibxBl6UGax22F1eQFqCfesRC5jm89Kw WNcfEW5LuDoMv5N11xgVbB09xEqpu919o9bnsPnYn6HxtJtqM1Zk54lgsd0pDgFmQoq22 pPuzuDagITFxe7TE6qezO3U4s3/ecNcHYrz9MnLf0c6sASt8+4VBjoq6PMwWz+FciEw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=qAGvGXkU; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 99520606A31E; Wed, 25 Nov 2026 16:15:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=qAGvGXkU Received: by smtp.kernel.org (Postfix) with ESMTPSA id 568FC1F000C4; Wed, 25 Nov 2026 16:15:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795623331; bh=M+WzXxjhDhD/IG32HPtzHvZncIIlO7kOMFaYO0Ht6og=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=qAGvGXkU2uhJaitYLFEnLIFj/QiF3ctIOdoLpiCaQ/H2nC6nrHx7p1ZpFoa4Qpi2F 5h1LKi6JFLbwt2PEsDmADli9zEI59z5LbGdz8RQP5G3LPkW9ADr70jZL5/0kdNpwmy RKpJaPTsefPfiubWZHiHZ0fcN/l3KpUVtI/cR6nQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sashiko , Andrea Parri , "Peter Zijlstra (Intel)" , Ingo Molnar , Vincent Guittot Subject: [PATCH 6.18 787/990] sched/uclamp: Reject clamp values above SCHED_CAPACITY_SCALE Date: Wed, 25 Nov 2026 15:35:54 +0100 Message-ID: <20261125143840.481274510@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261125143822.072087159@linuxfoundation.org> References: <20261125143822.072087159@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Andrea Parri commit 8127ec8458df29bd702db602473042ccb9e619b9 upstream. sched_setattr() accepts sched_util_min and sched_util_max values that do not fit in uclamp_se::value. A single thread can do: sched_setattr(max = 800) returns 0 sched_setattr(min = 0xfffffffe) returns 0 sched_getattr() min=2046 max=800 which leaves the minimum above both SCHED_CAPACITY_SCALE and the task's own maximum. The range check in uclamp_validate() relies on the + 1 wrapping -1, the reset value, to 0: if (util_min + 1 > SCHED_CAPACITY_SCALE + 1) That only works for an unsigned type. util_min and util_max are int and SCHED_CAPACITY_SCALE is a long, so every negative value passes the check, and so does INT_MAX, whose + 1 wraps. uclamp_se_set() then truncates what got through to the 11 bits of uclamp_se::value, but computes the bucket from the full value. A minimum of 0xfffff800 is stored as 0 in the top bucket, where uclamp_rq_max_value() takes it for the highest active clamp once a higher value leaves the rq. The rq clamp falls below what the remaining tasks requested, and emptying their bucket trips the WARN_ON_ONCE() in uclamp_rq_dec_id(), without any privilege: WARNING: kernel/sched/core.c:1862 at dequeue_task+0x2a3/0x2b0, CPU#0: repro/126 Call Trace: __schedule+0x933/0x1320 schedule+0x36/0x100 do_nanosleep+0x61/0x190 hrtimer_nanosleep+0xb5/0x1d0 Make util_min and util_max unsigned int, so that -1 is the only value that wraps. The pair check below is unaffected, since it skips -1 explicitly and anything else is at most SCHED_CAPACITY_SCALE by then. Requests that were only accepted because of this now fail with -EINVAL. The following program triggers the warning when run by any user outside a child cpu cgroup. With this applied, its 0xfffff800 request fails with -EINVAL and the warning no longer appears: #define _GNU_SOURCE #include #include #include #include #include #include struct attr { uint32_t size, policy; uint64_t flags; int32_t nice; uint32_t prio; uint64_t runtime, deadline, period; uint32_t util_min, util_max; }; static volatile int stop; static void set_min(uint32_t v) { /* KEEP_POLICY | KEEP_PARAMS | UTIL_CLAMP_MIN */ struct attr a = { .size = sizeof(a), .flags = 0x38, .util_min = v }; syscall(SYS_sched_setattr, 0, &a, 0); } static void burn(long us) { struct timespec s, n; clock_gettime(CLOCK_MONOTONIC, &s); do clock_gettime(CLOCK_MONOTONIC, &n); while ((n.tv_sec - s.tv_sec) * 1000000 + (n.tv_nsec - s.tv_nsec) / 1000 < us); } static void *bogus(void *arg) { set_min(0xfffff800); while (!stop) burn(1000); return arg; } static void *worker(void *arg) { long v = (long)arg; set_min(v); while (!stop) { burn(v == 800 ? 300 : 1500); usleep(100); } return arg; } int main(void) { pthread_t t[3]; cpu_set_t c; int i; CPU_ZERO(&c); CPU_SET(0, &c); sched_setaffinity(0, sizeof(c), &c); pthread_create(&t[0], NULL, bogus, NULL); usleep(50000); pthread_create(&t[1], NULL, worker, (void *)500L); pthread_create(&t[2], NULL, worker, (void *)800L); sleep(15); stop = 1; for (i = 0; i < 3; i++) pthread_join(t[i], NULL); return 0; } An LLM helped find the warning and write this patch and its tests. Fixes: 480a6ca2dc6e ("sched/uclamp: Allow to reset a task uclamp constraint value") Reported-by: Sashiko Signed-off-by: Andrea Parri Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Ingo Molnar Reviewed-by: Vincent Guittot Cc: stable@vger.kernel.org Link: https://sashiko.dev/#/patchset/20261016062629.2102883-1-sh_def%40163.com Link: https://patch.msgid.link/20261102134831.243255-1-parri.andrea@gmail.com Signed-off-by: Greg Kroah-Hartman --- kernel/sched/syscalls.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/kernel/sched/syscalls.c +++ b/kernel/sched/syscalls.c @@ -328,8 +328,8 @@ static inline void __setscheduler_dl_pi( static int uclamp_validate(struct task_struct *p, const struct sched_attr *attr) { - int util_min = p->uclamp_req[UCLAMP_MIN].value; - int util_max = p->uclamp_req[UCLAMP_MAX].value; + unsigned int util_min = p->uclamp_req[UCLAMP_MIN].value; + unsigned int util_max = p->uclamp_req[UCLAMP_MAX].value; if (attr->sched_flags & SCHED_FLAG_UTIL_CLAMP_MIN) { util_min = attr->sched_util_min;