[LTP] [PATCH] sigaltstack01: Fix check about alternative stack
陈力恒
791960492@qq.com
Mon Aug 18 15:48:27 CEST 2025
Hi Petr Vorel,
Recently I want to test if Gramine-SGX (emulates Linux in Intel SGX trusted execution environment) works exactly like Linux, and avoid it from harming users.
sigaltstack01 mallocs a buffer with size SIGSTKSZ (8192) and uses this buffer as an alternative stack. However, in Gramine-SGX, it needs to reserve a large memory to save xstate, sigframe, and restorer's address, thus it needs to reserve memory larger than 11452 bytes, which overflows SIGSTKSZ. In this situation, I noticed the wrong check we talked about. (Detail: https://github.com/gramineproject/gramine/issues/2153 , is it OK to paste a link?)
Kind regards,
Liheng Chen
------------------ Original ------------------
Hi Liheng,
> Hi all,
> This check seems should be (alt_stk < sigstk.ss_sp) || (alt_stk > (sigstk.ss_sp + SIGSTKSZ)), not &&
You're right. IMHO the error goes down to the original addition in
865695bbc89088b9526ea9045410e5afb70a985c
Out of curiosity, did you find a system where it should fail but it didn't?
Reviewed-by: Petr Vorel <pvorel@suse.cz>
> Kind regards,
> Liheng Chen
> Signed-off-by: Liheng Chen <791960492@qq.com>
> ---
> testcases/kernel/syscalls/sigaltstack/sigaltstack01.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
> diff --git a/testcases/kernel/syscalls/sigaltstack/sigaltstack01.c b/testcases/kernel/syscalls/sigaltstack/sigaltstack01.c
> index 9a2e3a440..147659467 100644
> --- a/testcases/kernel/syscalls/sigaltstack/sigaltstack01.c
> +++ b/testcases/kernel/syscalls/sigaltstack/sigaltstack01.c
> @@ -142,7 +142,7 @@ int main(int ac, char **av)
> * Check that main_stk is outside the
> * alternate stk boundaries.
> */
> - if ((alt_stk < sigstk.ss_sp) &&
> + if ((alt_stk < sigstk.ss_sp) ||
> (alt_stk > (sigstk.ss_sp + SIGSTKSZ))) {
> tst_resm(TFAIL,
> "alt. stack is not within the "
More information about the ltp
mailing list