Skip to content

Commit 28107c9

Browse files
Flavio Ceolinhenrikbrixandersen
authored andcommitted
userspace: dynamic: Fix k_thread_stack_free verification
k_thread_stack_free syscall was not checking if the caller had permission to given stack object. Signed-off-by: Flavio Ceolin <[email protected]> (cherry picked from commit c12f050)
1 parent c9473ca commit 28107c9

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

kernel/dynamic.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,15 @@ int z_impl_k_thread_stack_free(k_thread_stack_t *stack)
166166
#ifdef CONFIG_USERSPACE
167167
static inline int z_vrfy_k_thread_stack_free(k_thread_stack_t *stack)
168168
{
169+
/* The thread stack object must not be in initialized state.
170+
*
171+
* Thread stack objects are initialized when the thread is created
172+
* and de-initialized whent the thread is destroyed. Since we can't
173+
* free a stack that is in use, we have to check that the caller
174+
* has access to the object but that it is not in use anymore.
175+
*/
176+
K_OOPS(K_SYSCALL_OBJ_NEVER_INIT(stack, K_OBJ_THREAD_STACK_ELEMENT));
177+
169178
return z_impl_k_thread_stack_free(stack);
170179
}
171180
#include <syscalls/k_thread_stack_free_mrsh.c>

0 commit comments

Comments
 (0)