diff options
| author | AFWEF_147 <[email protected]> | 2026-03-23 12:09:59 +0000 |
|---|---|---|
| committer | Rbb666 <[email protected]> | 2026-03-31 10:37:11 +0800 |
| commit | 7cd7e05ba4179ac3d73fe127c103083a648ae1c4 (patch) | |
| tree | d72ed0b5cd0149af5d4fd6668178b791d2280229 /components | |
| parent | d65076d83de30ce23b5d62e21e7fffb83f162f1e (diff) | |
fix(lwp): validate thread priority in sched syscalls
Diffstat (limited to 'components')
| -rw-r--r-- | components/lwp/lwp_syscall.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/components/lwp/lwp_syscall.c b/components/lwp/lwp_syscall.c index 6efc3a0e16..33c0cdfffd 100644 --- a/components/lwp/lwp_syscall.c +++ b/components/lwp/lwp_syscall.c @@ -8746,6 +8746,8 @@ sysret_t sys_sysinfo(void *info) #endif } +static rt_bool_t _sys_sched_priority_is_valid(int priority); + /** * @brief Set scheduling parameters for a specific thread. * @@ -8785,6 +8787,12 @@ sysret_t sys_sched_setparam(pid_t tid, void *param) return -EINVAL; } + if (!_sys_sched_priority_is_valid(sched_param->sched_priority)) + { + kmem_put(sched_param); + return -EINVAL; + } + thread = lwp_tid_get_thread_and_inc_ref(tid); if (thread) @@ -8915,6 +8923,18 @@ sysret_t sys_sched_get_priority_min(int policy) return 0; } +static rt_bool_t _sys_sched_priority_is_valid(int priority) +{ + return (priority >= 0) && (priority < RT_THREAD_PRIORITY_MAX); +} + +#if defined(RT_USING_UTESTCASES) && defined(RT_USING_SMART) +rt_bool_t rt_utest_sys_sched_priority_is_valid(int priority) +{ + return _sys_sched_priority_is_valid(priority); +} +#endif + /** * @brief Set the scheduling policy and parameters for a thread. * @@ -8958,6 +8978,12 @@ sysret_t sys_sched_setscheduler(int tid, int policy, void *param) return -EINVAL; } + if (!_sys_sched_priority_is_valid(sched_param->sched_priority)) + { + kmem_put(sched_param); + return -EINVAL; + } + thread = lwp_tid_get_thread_and_inc_ref(tid); ret = rt_thread_control(thread, RT_THREAD_CTRL_RESET_PRIORITY, (void *)&sched_param->sched_priority); lwp_tid_dec_ref(thread); |
