Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: 黄华成 <1112433017@e.gzhu.edu.cn>
To: linux-arm-kernel <linux-arm-kernel@lists.infradead.org>
Cc: "catalin.marinas" <catalin.marinas@arm.com>,
	will <will@kernel.org>, "mark.rutland" <mark.rutland@arm.com>,
	broonie <broonie@kernel.org>,
	"szabolcs.nagy" <szabolcs.nagy@arm.com>,
	"yury.khrustalev" <yury.khrustalev@arm.com>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	stable <stable@vger.kernel.org>
Subject: [PATCH 1/1] arm64: gcs: bind signal GCS restore to the live GCSPR_EL0
Date: Mon, 23 Nov 2026 23:56:52 +0800	[thread overview]
Message-ID: <tencent_122AB752205D1FCC2B359940@qq.com> (raw)

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!

                 reply	other threads:[~2026-11-23 15:58 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tencent_122AB752205D1FCC2B359940@qq.com \
    --to=1112433017@e.gzhu.edu.cn \
    --cc=broonie@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=stable@vger.kernel.org \
    --cc=szabolcs.nagy@arm.com \
    --cc=will@kernel.org \
    --cc=yury.khrustalev@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox