This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 7e17f24e037 sched/pthread: validate entry and stacksize in
nx_pthread_create
7e17f24e037 is described below
commit 7e17f24e0376a517491f90a602f18c833fbc5baa
Author: pangzhen1 <[email protected]>
AuthorDate: Fri Nov 20 17:48:20 2026 +0800
sched/pthread: validate entry and stacksize in nx_pthread_create
nx_pthread_create() is a system call, so in PROTECTED and KERNEL builds
user space can call it directly and bypass the checks done in libc by
pthread_create() and pthread_attr_setstacksize(). It only asserted the
trampoline and relied on the attribute setters for the stack size:
- a NULL trampoline trips the DEBUGASSERT() in nx_pthread_create() and
panics the system, or starts the new thread at address 0 without
assertions;
- a NULL entry point is accepted, and the new thread then trips the
DEBUGASSERT() in pthread_start();
- a stack size below PTHREAD_STACK_MIN gives a stack that may be too
small for the TLS data tls_init_info() writes at its base.
Reject a NULL trampoline, a NULL entry point and a stack size below
PTHREAD_STACK_MIN with EINVAL.
Signed-off-by: pangzhen1 <[email protected]>
---
sched/pthread/pthread_create.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/sched/pthread/pthread_create.c b/sched/pthread/pthread_create.c
index eaaa165ef1e..c06d3c104a2 100644
--- a/sched/pthread/pthread_create.c
+++ b/sched/pthread/pthread_create.c
@@ -192,7 +192,12 @@ int nx_pthread_create(pthread_trampoline_t trampoline, FAR
pthread_t *thread,
int policy;
int ret;
- DEBUGASSERT(trampoline != NULL);
+ /* The trampoline and the thread entry point must be non-NULL */
+
+ if (trampoline == NULL || entry == NULL)
+ {
+ return EINVAL;
+ }
parent = this_task();
DEBUGASSERT(parent != NULL);
@@ -214,6 +219,13 @@ int nx_pthread_create(pthread_trampoline_t trampoline, FAR
pthread_t *thread,
attr = &default_attr;
}
+ /* The stack size must be at least PTHREAD_STACK_MIN */
+
+ if (attr->stacksize < PTHREAD_STACK_MIN)
+ {
+ return EINVAL;
+ }
+
#ifdef CONFIG_TLS_ALIGNED
/* The TLS alignment limits the size of the stack */