Hello, restore_gcs_context() copies gcspr from the user signal frame into GCSPR_EL0 with no restriction ("We let userspace set GCSPR_EL0 to anything here, we will validate later"), and gcs_restore_signal() validates only the self-referential cap value at that address. A still-live cap from another signal context satisfies the check by construction, so a corrupted sigframe can make the kernel consume an outer context's cap and rewind GCSPR_EL0 to an attacker-chosen historical position - after which returns validate against the rewound depth instead of the real one, turning a contained memory-corruption primitive into a backward-CFI bypass. We demonstrated the full chain (stale-cap cross-context replay, rewind, protected-action ret accepted at the rewound depth) deterministically on QEMU TCG FEAT_GCS. Bind the restore to the live, kernel-visible GCSPR_EL0: for every legitimate restore at every nesting depth the innermost frame's gcspr equals the live GCSPR_EL0 (the handler's return pops its trampoline record before rt_sigreturn). Userspace cannot move the live GCSPR_EL0 without executing GCS instructions, which are themselves checked. glibc compatibility: the GCS series' setjmp/longjmp unwinds via GCSPOPM in userspace and never depends on a relaxed sigreturn; GCSPOPM cannot cross a signal cap, so the kernel path bound here is the only sanctioned restore path and all its legitimate forms satisfy the binding. Raw (non-GCS-aware) longjmp/setcontext/swapcontext fail identically with and without this patch. --- diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c --- a/arch/arm64/kernel/signal.c +++ b/arch/arm64/kernel/signal.c @@ -772,6 +772,16 @@ static int restore_gcs_context(struct user_ctxs *user) current->thread.gcs_el0_mode = enabled; + /* + * Bind the frame's gcspr to the live, kernel-visible GCSPR_EL0. + * For every legitimate restore (any nesting depth) the innermost + * frame's gcspr equals live GCSPR_EL0; a mismatch means the frame + * is pointing the restore at another context's still-live cap - + * a cross-context stale-cap replay that would rewind GCSPR_EL0 to + * an attacker-chosen historical position. + */ + if (gcspr != read_sysreg_s(SYS_GCSPR_EL0)) { + pr_info_ratelimited("%s[%d]: GCS restore ptr unbound: frame=%px live=%px\n", + current->comm, task_pid_nr(current), + (void *)gcspr, + (void *)read_sysreg_s(SYS_GCSPR_EL0)); + return -EINVAL; + } + -- Thank!