Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/1] arm64: gcs: bind signal GCS restore to the live GCSPR_EL0
@ 2026-11-23  5:53 黄华成
  0 siblings, 0 replies; only message in thread
From: 黄华成 @ 2026-11-23  5:53 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: catalin.marinas, will, mark.rutland, broonie, szabolcs.nagy,
	yury.khrustalev, linux-kernel, stable

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!

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-23  5:54 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23  5:53 [PATCH 0/1] arm64: gcs: bind signal GCS restore to the live GCSPR_EL0 黄华成

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