Skip to content

Commit 034f06d

Browse files
[HUST CSE][core] validate thread priority at syscall entry
1 parent 774c2b7 commit 034f06d

2 files changed

Lines changed: 27 additions & 11 deletions

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 & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -400,11 +400,6 @@ static rt_err_t _rt_sched_update_priority(struct rt_thread *thread, rt_uint8_t p
400400
*/
401401
rt_err_t rt_sched_thread_change_priority(struct rt_thread *thread, rt_uint8_t priority)
402402
{
403-
if (priority >= RT_THREAD_PRIORITY_MAX)
404-
{
405-
return -RT_EINVAL;
406-
}
407-
408403
return _rt_sched_update_priority(thread, priority, RT_FALSE);
409404
}
410405

@@ -413,11 +408,6 @@ rt_err_t rt_sched_thread_change_priority(struct rt_thread *thread, rt_uint8_t pr
413408
*/
414409
rt_err_t rt_sched_thread_reset_priority(struct rt_thread *thread, rt_uint8_t priority)
415410
{
416-
if (priority >= RT_THREAD_PRIORITY_MAX)
417-
{
418-
return -RT_EINVAL;
419-
}
420-
421411
return _rt_sched_update_priority(thread, priority, RT_TRUE);
422412
}
423413

@@ -533,4 +523,4 @@ void rt_scheduler_stack_check(struct rt_thread *thread)
533523
#endif /* ARCH_CPU_STACK_GROWS_UPWARD */
534524
}
535525

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

0 commit comments

Comments
 (0)