From c6827cd8b558a4fa191ad285bde4a17efdd758db Mon Sep 17 00:00:00 2001 From: Carlos Eduardo Seo Date: Thu, 17 Mar 2022 20:51:32 -0300 Subject: [PATCH] cheri: nptl: Check user provided stack for PCS constraints In pthread_attr_setstack fail with EINVAL if the input stack does not meet the PCS constraints. --- nptl/pthread_attr_setstack.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/nptl/pthread_attr_setstack.c b/nptl/pthread_attr_setstack.c index e08b167df69..a0338c27528 100644 --- a/nptl/pthread_attr_setstack.c +++ b/nptl/pthread_attr_setstack.c @@ -19,7 +19,9 @@ #include #include "pthreadP.h" #include - +#ifdef __CHERI_PURE_CAPABILITY__ +# include +#endif #ifndef NEW_VERNUM # define NEW_VERNUM GLIBC_2_3_3 @@ -43,6 +45,11 @@ __pthread_attr_setstack (pthread_attr_t *attr, void *stackaddr, EXTRA_PARAM_CHECKS; #endif +#ifdef __CHERI_PURE_CAPABILITY__ + if (!STACK_CAP_CHECK (stackaddr, stacksize)) + return EINVAL; +#endif + iattr->stacksize = stacksize; #if _STACK_GROWS_DOWN iattr->stackaddr = (char *) stackaddr + stacksize; -- 2.47.2