From 4d1c6ac1d17a8b80ba26b911b1508e62886ae0b5 Mon Sep 17 00:00:00 2001 From: Dapeng Gao Date: Tue, 9 Apr 2024 09:54:53 +0100 Subject: [PATCH] fixup! c18n: Rework implementation to be interrupt-safe --- libexec/rtld-elf/aarch64/rtld_c18n_asm.S | 22 +++++++++++----------- libexec/rtld-elf/rtld_c18n.c | 3 ++- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/libexec/rtld-elf/aarch64/rtld_c18n_asm.S b/libexec/rtld-elf/aarch64/rtld_c18n_asm.S index b1e2f9069c81..9d4769b004f1 100644 --- a/libexec/rtld-elf/aarch64/rtld_c18n_asm.S +++ b/libexec/rtld-elf/aarch64/rtld_c18n_asm.S @@ -437,7 +437,7 @@ TRAMP(tramp_pop_frame) * Load the address of the previous trusted frame, the compartment ID of * the caller, and the number of return value registers. */ - ldp c16, c10, [TRUSTED_STACK_C, #(CAP_WIDTH * 14)] + ldp c17, c10, [TRUSTED_STACK_C, #(CAP_WIDTH * 14)] /* * Load the caller's current stack top and old stack top. @@ -454,15 +454,6 @@ TRAMP(tramp_pop_frame) ldp c19, c20, [TRUSTED_STACK_C, #(CAP_WIDTH * 2)] ldp c29, c30, [TRUSTED_STACK_C] - /* - * Get the stack lookup table. - */ - mrs STACK_TABLE_C, STACK_TABLE - /* - * Store the caller's old stack top in the stack lookup table. - */ - str c12, [STACK_TABLE_C, w10, uxtw #0] - /* * Install the caller's stack. * @@ -474,7 +465,16 @@ TRAMP(tramp_pop_frame) /* * Bump the trusted stack pointer. */ - msr TRUSTED_STACK, c16 + msr TRUSTED_STACK, c17 + + /* + * Get the stack lookup table. + */ + mrs STACK_TABLE_C, STACK_TABLE + /* + * Store the caller's old stack top in the stack lookup table. + */ + str c12, [STACK_TABLE_C, w10, uxtw #0] /* * Extrace the number of return value registers. diff --git a/libexec/rtld-elf/rtld_c18n.c b/libexec/rtld-elf/rtld_c18n.c index 4f5b3d64a9b8..bde407b36ee6 100644 --- a/libexec/rtld-elf/rtld_c18n.c +++ b/libexec/rtld-elf/rtld_c18n.c @@ -1744,7 +1744,8 @@ _rtld_sighandler_impl(int sig, siginfo_t *info, ucontext_t *ucp, void *nsp */ intr_idx = tf->callee; intr = index_to_cid(intr_idx); - if (table->sizes->capacity >= intr || table->sizes->data[intr] == 0) { + if (table->sizes->capacity >= intr || + table->sizes->data[intr].size == 0) { /* * If the interrupt occurred at a point in the trampoline where * stack resolution is taking place, nsp would remain the