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 0/1] arm64: gcs: bind signal GCS restore to the live GCSPR_EL0
Date: Mon, 23 Nov 2026 13:53:42 +0800 [thread overview]
Message-ID: <tencent_6173029B43F227BE37E581FB@qq.com> (raw)
Hello,
We audited the arm64 GCS signal-restore protocol against x86 CET and the RISC-V usercfi implementation and found that restore_gcs_context() accepts any gcspr from the user signal frame (the in-tree comment states "We let userspace set GCSPR_EL0 to anything here, we will validate later"), and gcs_restore_signal() then validates only a self-referential value relation at that address:cap == GCS_SIGNAL_CAP(gcspr). A still-live signal cap belonging to a different, never-restored signal context satisfies this by construction.
Consequence: with a memory-corruption primitive sufficient to corrupt a sigframe (the threat model shadow stacks exist for), a nested handler can point its own frame's gcspr at the outer handler's live cap. The kernel accepts it, zeroes the outer context's cap, and restores GCSPR_EL0 to the attacker-chosen position + 8 - a kernel-mediated rewind to a historical depth. We demonstrated the full chain on QEMU TCG FEAT_GCS with this kernel tree (9-arm probe, 5 runs each, fully
deterministic):
A1/A3C normal + nested legitimate round-trips : PASS
A2 frame.gcspr +8 to a capless address : killed
(the value check exists and works)
A3/A5 cross-context stale-cap rewrite (A5 locates its own
frame by stack scan only - no privileged ucontext
pointer, the realistic attacker model) : GCSPR
rewound, control resumes at the attacker depth, 5/5
A4 the stolen-from outer handler's later sigreturn : killed
(its cap was consumed by the thief)
A6 full CFI bypass: after the rewind, a deliberate
ldr x30/<RA>; ret pops the rewound slot and is
ACCEPTED, returning at a historical return address
and skipping the rest of the anchor function - 5/5,
while the identical ret without the rewind is killed.
x86 CET does not have this shape (its sigframe carries no SSP field); RISC-V usercfi had the same shape and an equivalent six-line binding has been proposed there in parallel.
The patch binds the frame's gcspr to the live GCSPR_EL0 (equality; pinned empirically at zero delta for every legitimate restore at every nesting depth - the handlr's return pops its trampoline record before rt_sigreturn). Userspace cannot move the live GCSPR_EL0 without
executing GCS instructions, which are themselves policed.
Compatibility evidence (the question we expect first):
R1-R3 normal / nested / sigaltstack round-trips : PASS both
R4-R6 raw (non-GCS-aware) longjmp/setcontext/swapcontext : killed
on BOTH unpatched and patched kernels - architectural
GCS behavior (raw jumps that skip sigreturn are exactly
what GCS rejects); the patch adds zero behavioral delta
R7 GCSPOPM userspace unwind - the primitive glibc's GCS
series actually uses for __longjmp (v9, Khrustalev:
MRS_GCSPR save + GCSPOPM pop loop + GCSSS1/GCSSS2
cross-stack switch, no rt_sigreturn dependency): PASS on
both kernels; ordinary longjmp is orthogonal to this patch
R8 GCSPOPM attempted across a signal cap: killed on both -
the architecture forbids userspace cap-crossing, so no
libc can bypass sigreturn via GCSPOPM; the only sanctioned
restore path is the kernel's, whose legitimate forms all
satisfy the binding
One semantic boundary worth naming: a siglongjmp that abandons a still-pending outer handler frame leaves live GCSPR inconsistent with that outer frame; with this patch such a frame's later sigreturn fails with -EINVAL instead of silently rewinding to an arbitrary position. We believe reject-by-default is the correct side of that trade, but flag it for discussion; a per-signal-depth token stack would also close the attack and avoid the question at higher bookkeeping cost.
Reproducer (probe, scripts, pinned kernel-image hashes, logs) available on request or via a branch.
Thanks,
Looking forward to your reply!
reply other threads:[~2026-11-23 5:54 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_6173029B43F227BE37E581FB@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
all inboxes | Powered by JetHome®