Skip to content

Commit 7cd7e05

Browse files
Telecaster2147Rbb666
authored andcommitted
fix(lwp): validate thread priority in sched syscalls
1 parent d65076d commit 7cd7e05

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

components/lwp/lwp_syscall.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8746,6 +8746,8 @@ sysret_t sys_sysinfo(void *info)
87468746
#endif
87478747
}
87488748

8749+
static rt_bool_t _sys_sched_priority_is_valid(int priority);
8750+
87498751
/**
87508752
* @brief Set scheduling parameters for a specific thread.
87518753
*
@@ -8785,6 +8787,12 @@ sysret_t sys_sched_setparam(pid_t tid, void *param)
87858787
return -EINVAL;
87868788
}
87878789

8790+
if (!_sys_sched_priority_is_valid(sched_param->sched_priority))
8791+
{
8792+
kmem_put(sched_param);
8793+
return -EINVAL;
8794+
}
8795+
87888796
thread = lwp_tid_get_thread_and_inc_ref(tid);
87898797

87908798
if (thread)
@@ -8915,6 +8923,18 @@ sysret_t sys_sched_get_priority_min(int policy)
89158923
return 0;
89168924
}
89178925

8926+
static rt_bool_t _sys_sched_priority_is_valid(int priority)
8927+
{
8928+
return (priority >= 0) && (priority < RT_THREAD_PRIORITY_MAX);
8929+
}
8930+
8931+
#if defined(RT_USING_UTESTCASES) && defined(RT_USING_SMART)
8932+
rt_bool_t rt_utest_sys_sched_priority_is_valid(int priority)
8933+
{
8934+
return _sys_sched_priority_is_valid(priority);
8935+
}
8936+
#endif
8937+
89188938
/**
89198939
* @brief Set the scheduling policy and parameters for a thread.
89208940
*
@@ -8958,6 +8978,12 @@ sysret_t sys_sched_setscheduler(int tid, int policy, void *param)
89588978
return -EINVAL;
89598979
}
89608980

8981+
if (!_sys_sched_priority_is_valid(sched_param->sched_priority))
8982+
{
8983+
kmem_put(sched_param);
8984+
return -EINVAL;
8985+
}
8986+
89618987
thread = lwp_tid_get_thread_and_inc_ref(tid);
89628988
ret = rt_thread_control(thread, RT_THREAD_CTRL_RESET_PRIORITY, (void *)&sched_param->sched_priority);
89638989
lwp_tid_dec_ref(thread);

src/scheduler_comm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,4 +523,4 @@ void rt_scheduler_stack_check(struct rt_thread *thread)
523523
#endif /* ARCH_CPU_STACK_GROWS_UPWARD */
524524
}
525525

526-
#endif /* RT_USING_OVERFLOW_CHECK */
526+
#endif /* RT_USING_OVERFLOW_CHECK */

0 commit comments

Comments
 (0)