[Xenomai] [PATCH 1/6] cobalt/posix: Harden cobalt_thread_shadow against invalid requests

Jan Kiszka jan.kiszka at siemens.com
Mon Jul 16 18:37:49 CEST 2018

From: Jan Kiszka <jan.kiszka at siemens.com>

If the caller has already a Xenomai shadow, we will crash rather than
failing gracefully. The reason is that pthread_discard expects secondary
mode - which may not be the case if the caller is already able to
migrate. So check early and avoid that we can run into this trap.

Signed-off-by: Jan Kiszka <jan.kiszka at siemens.com>
 kernel/cobalt/posix/thread.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/cobalt/posix/thread.c b/kernel/cobalt/posix/thread.c
index b5809e840b..d75a593536 100644
--- a/kernel/cobalt/posix/thread.c
+++ b/kernel/cobalt/posix/thread.c
@@ -625,6 +625,9 @@ cobalt_thread_shadow(struct task_struct *p,
 	struct sched_param_ex param_ex;
 	int ret;
+	if (xnthread_current())
+		return ERR_PTR(-EBUSY);
 	param_ex.sched_priority = 0;
 	trace_cobalt_pthread_create(hkey->u_pth, SCHED_NORMAL, &param_ex);
 	ret = pthread_create(&thread, SCHED_NORMAL, &param_ex, p);

More information about the Xenomai mailing list