mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/1] arm64: gcs: bind signal GCS restore to the live GCSPR_EL0
@ 2026-11-23 15:56 黄华成
  2026-11-24 17:32 ` Catalin Marinas
  0 siblings, 1 reply; 2+ messages in thread
From: 黄华成 @ 2026-11-23 15:56 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: catalin.marinas, will, mark.rutland, broonie, szabolcs.nagy,
	yury.khrustalev, linux-kernel, stable

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!

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH 1/1] arm64: gcs: bind signal GCS restore to the live GCSPR_EL0
  2026-11-23 15:56 [PATCH 1/1] arm64: gcs: bind signal GCS restore to the live GCSPR_EL0 黄华成
@ 2026-11-24 17:32 ` Catalin Marinas
  0 siblings, 0 replies; 2+ messages in thread
From: Catalin Marinas @ 2026-11-24 17:32 UTC (permalink / raw)
  To: 黄华成
  Cc: linux-arm-kernel, will, mark.rutland, broonie, szabolcs.nagy,
	yury.khrustalev, linux-kernel, stable

On Mon, Nov 23, 2026 at 11:56:52PM +0800, 黄华成 wrote:
> 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.

(that's a pretty malformed patch, missing sign-off, lines not wrapped,
based on an older tree)

Changing GCSPR_EL0 via sigreturn is the intended ABI (see
preserve_gcs_context() and Documentation/arch/arm64/gcs.rst). Any valid
signal cap token is acceptable, including an outer context's token.

The patch would also break handlers that call rt_sigreturn directly,
user-space stack switching and checkpoint/restore.

In conclusion, NAK.

-- 
Catalin

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-24 17:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-23 15:56 [PATCH 1/1] arm64: gcs: bind signal GCS restore to the live GCSPR_EL0 黄华成
2026-11-24 17:32 ` Catalin Marinas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®