From 22d5ee5b2bc2df59423bdcea684b51c8a0ae532c Mon Sep 17 00:00:00 2001 From: yushuailong Date: Mon, 7 Sep 2026 00:34:16 +0800 Subject: [PATCH] sched/sched: Validate priority before applying sporadic parameters. nxsched_set_param() applied the sporadic parameters and restarted the replenishment timer in set_sporadic_param() before nxsched_reprioritize() rejected an out-of-range priority with EINVAL, leaving stale sporadic state (e.g. a truncated hi_priority) behind on failure. Validate sched_priority up front so the error path is atomic. Assisted-by: OpenAI Codex Signed-off-by: yushuailong --- sched/sched/sched_setparam.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sched/sched/sched_setparam.c b/sched/sched/sched_setparam.c index a302e6e660e..61e8c7a1b04 100644 --- a/sched/sched/sched_setparam.c +++ b/sched/sched/sched_setparam.c @@ -187,6 +187,12 @@ int nxsched_set_param(pid_t pid, FAR const struct sched_param *param) if (param != NULL) { + if (param->sched_priority < SCHED_PRIORITY_MIN || + param->sched_priority > SCHED_PRIORITY_MAX) + { + return -EINVAL; + } + /* Prohibit modifications to the head of the ready-to-run task * list while adjusting the priority */