Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Mark Brown <broonie@kernel.org>
To: Bill Roberts <bill.roberts@foss.arm.com>
Cc: "linux-riscv@lists.infradead.org"
	<linux-riscv@lists.infradead.org>,
	linux-arm-kernel@lists.infradead.org,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	linux-hardening@vger.kernel.org, linux-api@vger.kernel.org,
	dave.hansen@linux.intel.com, rick.p.edgecombe@intel.com,
	debug@rivosinc.com
Subject: Re: Shadow Stack Locking Semantics between arch's
Date: Thu, 27 Aug 2026 19:14:28 +0100	[thread overview]
Message-ID: <d20ccb74-69ed-45d7-a810-846904873588@sirena.org.uk> (raw)
In-Reply-To: <3bb672e0-7bc3-434f-904e-aa00394dd01f@foss.arm.com>

[-- Attachment #1: Type: text/plain, Size: 2950 bytes --]

On Thu, Aug 27, 2026 at 12:52:28PM -0500, Bill Roberts wrote:

> I have noticed some semantic differences between the arches. Given this
> example of current thread state, current thread locking state and the
> new features requested, as shown below:

> unsigned long locked = 0x2; // Kernel Task State -> LOCK WRITE
> unsigned long cur_val = 0x3; // Kernel Task State -> WRITE and SHADOWSTACK
> ENABLED
> unsigned long new_val = 0x0; // Userspace Feature Change via syscall ->
> DISABLE

> | x86-64 | risc-v | arm64 |
> | ---------- | -------- | --------- |
> | Works  | Fails  | Fails     |

I would not have expected that combination to work at all with the
prctl() (as opposed to arch_prctl()) interface TBH, if you've locked
write on you shouldn't be able to disable it.  The reason that works on
x86 at the minute is that for x86 you can only change one bit at a time
so the new value when disabling is effectively 0x2, not 0x0.

> I am proposing and have questions over the following:
> 1. What should the behavior be if you had write locked and disable the
> shadow stack?
>   - I can argue both ways here, -EPERM or success. I think I and most arches
> lead to failure.

Given that RISC-V doesn't support control of writes it's moot there
at the minute, and x86 currently uses arch_prctl() so will need an
additional API, it seems the path of least resistance is to allow it.
This also avoids locking writes (or pushes, for arm64) on effectively
also locking enable which seems neater.

> 2. riscv should check that the low bit is set in locking not just that its
> 0, it should be 1

I think for ABI compatibility RISC-V will have to continue accepting 0
as being equivalent to locking PR_SHADOW_STACK_ENABLE (or everything,
but it only supports that one bit right now).

> 3. riscv should return -EPERM vs -EINVAL

If you mean for arch_lock_shadow_stack_status() I think -EINVAL is a
sensible error code when the system or task does not support shadow
stacks, I'm not sure we should return -EPERM at all.  On arm64 we
support locking any bit, not just the ones that we currently know about.
This is for future proofing, userspace can lock unknown flags.

> If we can all agree on item 1, that locked bits check can be refactored and
> shared in one of
> two ways:
> 1. within prctl itself, before the arch hook is called, we would need
> helpers per-arch to extract the thread features and lock bits
> 2. as a helper where folks just pass the unsigned long of the bits to get
> the result

For me option 1 seems a bit nicer, and moves more of the implementation
into generic code which is something we should really be doing in
general with the shadow stack support - there's a lot of cross arch
duplication at the minute.  It has been on my list to look at this
repitition at some point, it had been held up by the clone3() stuff but
that seems to have died a death for now.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2026-08-27 18:14 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-27 17:15 Shadow Stack Locking Semantics between arch's Bill Roberts
2026-08-27 17:52 ` Bill Roberts
2026-08-27 18:14   ` Mark Brown [this message]
2026-08-27 21:27     ` Edgecombe, Rick P
2026-08-27 21:41       ` Mark Brown
2026-08-27 22:37         ` Edgecombe, Rick P
2026-08-28 13:27           ` Mark Brown
2026-08-28 16:48             ` Edgecombe, Rick P
2026-08-28 17:11               ` Mark Brown

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=d20ccb74-69ed-45d7-a810-846904873588@sirena.org.uk \
    --to=broonie@kernel.org \
    --cc=bill.roberts@foss.arm.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=debug@rivosinc.com \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=rick.p.edgecombe@intel.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