Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: "Edgecombe, Rick P" <rick.p.edgecombe@intel.com>
To: "x86@kernel.org" <x86@kernel.org>, "bp@alien8.de" <bp@alien8.de>,
	"dave.hansen@linux.intel.com" <dave.hansen@linux.intel.com>,
	"pjw@kernel.org" <pjw@kernel.org>,
	"hpa@zytor.com" <hpa@zytor.com>,
	"aou@eecs.berkeley.edu" <aou@eecs.berkeley.edu>,
	"mingo@redhat.com" <mingo@redhat.com>,
	"alex@ghiti.fr" <alex@ghiti.fr>,
	"palmer@dabbelt.com" <palmer@dabbelt.com>,
	"bill.roberts@arm.com" <bill.roberts@arm.com>,
	"shuah@kernel.org" <shuah@kernel.org>,
	"tglx@kernel.org" <tglx@kernel.org>
Cc: "linux-riscv@lists.infradead.org"
	<linux-riscv@lists.infradead.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-kselftest@vger.kernel.org"
	<linux-kselftest@vger.kernel.org>
Subject: Re: [PATCH 1/2] x86/shstk: support via prctl
Date: Wed, 29 Jul 2026 13:29:15 +0000	[thread overview]
Message-ID: <33ac05a617a26b3d9c4a374d14a4f210bba0a991.camel@intel.com> (raw)
In-Reply-To: <20260714154740.140431-2-bill.roberts@arm.com>

On Tue, 2026-07-14 at 10:47 -0500, Bill Roberts wrote:
> Historically, managing the user-space shadow stack state on x86 has
> been handled exclusively through the arch_prctl() interface via the
> ARCH_SHSTK_* operations. However, other architectures (such as arm64 and
> riscv) do not implement arch_prctl() and instead utilize the newer,
> arch-agnostic, prctl() interface (i.e. PR_GET_SHADOW_STACK_STATUS and
> PR_SET_SHADOW_STACK_STATUS).
> 
> To provide language runtimes, toolchains, and libc implementations with a
> consistent, cross-architecture interface for managing control-flow
> integrity, wire up the generic shadow stack prctl handlers for x86.

I think glibc doesn't handles this in arch code, right? So the point of this is
only your SE Linux patches. Or is there other cross-arch code that wants to
handle shadow stack?

BTW, for non security module people, can you explain why it needs this design?

> 
> Map the generic PR_SHADOW_STACK_ENABLE, PR_SHADOW_STACK_DISABLE, and
> PR_SHADOW_STACK_LOCK operations onto the underlying x86 internal CET helper
> routines. This allows portable userspace applications to toggle or query
> shadow stack states without relying on architecture-specific system calls,
> while maintaining backward compatibility with existing arch_prctl() calls.

Can you explain why not to include ARCH_SHSTK_UNLOCK?
https://lore.kernel.org/lkml/e1362732ba86990b7707d3f5b785358b77c5f896.camel@intel.com/

> 
> Signed-off-by: Bill Roberts <bill.roberts@arm.com>
> ---
>  arch/x86/kernel/shstk.c | 35 +++++++++++++++++++++++++++++++++++
>  1 file changed, 35 insertions(+)
> 
> diff --git a/arch/x86/kernel/shstk.c b/arch/x86/kernel/shstk.c
> index 0ca64900192f..ef3db94eec6a 100644
> --- a/arch/x86/kernel/shstk.c
> +++ b/arch/x86/kernel/shstk.c
> @@ -18,6 +18,7 @@
>  #include <linux/sizes.h>
>  #include <linux/user.h>
>  #include <linux/syscalls.h>
> +#include <linux/prctl.h>
>  #include <asm/msr.h>
>  #include <asm/fpu/xstate.h>
>  #include <asm/fpu/types.h>
> @@ -630,3 +631,37 @@ bool shstk_is_enabled(void)
>  {
>  	return features_enabled(ARCH_SHSTK_SHSTK);
>  }
> +
> +/* We assume the prctl() feature bits line up with the arch_prctl() specific
> ones. */
> +static_assert(PR_SHADOW_STACK_ENABLE == ARCH_SHSTK_SHSTK);
> +static_assert(PR_SHADOW_STACK_WRITE  == ARCH_SHSTK_WRSS);

This is only needed for arch_get_shadow_stack_status()? So can we put it near by
and explain why?

> +
> +/* Handles the generic prctl interface for PR_SET_SHADOW_STACK_STATUS and its
> feature bits */
> +int arch_set_shadow_stack_status(struct task_struct *t, unsigned long status)
> +{
> +	int rc;

It needs to reject invalid options for status.

> +
> +	/* x86 arch_prctl is single bit at a time, so handle these one at
> time */
> +	if (!status & PR_SHADOW_STACK_ENABLE)
> +		return shstk_prctl(t, ARCH_SHSTK_DISABLE, ARCH_SHSTK_SHSTK);
> +
> +	rc = shstk_prctl(t, ARCH_SHSTK_ENABLE, ARCH_SHSTK_SHSTK);
> +	if (rc)
> +		return rc;
> +
> +	if (status & PR_SHADOW_STACK_WRITE)
> +		return shstk_prctl(t, ARCH_SHSTK_ENABLE, ARCH_SHSTK_WRSS);
> +
> +	return shstk_prctl(t, ARCH_SHSTK_DISABLE, ARCH_SHSTK_WRSS);
> +}
> +
> +/* Handles the generic prctl interface for PR_LOCK_SHADOW_STACK_STATUS and
> its feature bits */
> +int arch_lock_shadow_stack_status(struct task_struct *t, unsigned long
> status)
> +{
> +	return shstk_prctl(t, ARCH_SHSTK_LOCK, status);
> +}
> +
> +int arch_get_shadow_stack_status(struct task_struct *t, unsigned long __user
> *status)
> +{
> +	return shstk_prctl(t, ARCH_SHSTK_STATUS, (unsigned long)status);
> +}


  reply	other threads:[~2026-07-29 13:29 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-14 15:47 [PATCH 0/2] x86: Support shstk via prctl Bill Roberts
2026-07-14 15:47 ` [PATCH 1/2] x86/shstk: support " Bill Roberts
2026-07-29 13:29   ` Edgecombe, Rick P [this message]
2026-08-03 17:41     ` Bill Roberts
2026-08-03 18:14       ` Edgecombe, Rick P
2026-08-04 18:23         ` Bill Roberts
2026-08-04 18:49           ` Edgecombe, Rick P
2026-08-04 20:43             ` Bill Roberts
2026-08-04 21:59               ` Edgecombe, Rick P
2026-08-05 17:16                 ` Bill Roberts
2026-07-14 15:47 ` [PATCH 2/2] selftests/x86: add generic prctl shadow stack test Bill Roberts
2026-07-29 13:31   ` Edgecombe, Rick P
2026-08-03 17:50     ` Bill Roberts

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=33ac05a617a26b3d9c4a374d14a4f210bba0a991.camel@intel.com \
    --to=rick.p.edgecombe@intel.com \
    --cc=alex@ghiti.fr \
    --cc=aou@eecs.berkeley.edu \
    --cc=bill.roberts@arm.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=mingo@redhat.com \
    --cc=palmer@dabbelt.com \
    --cc=pjw@kernel.org \
    --cc=shuah@kernel.org \
    --cc=tglx@kernel.org \
    --cc=x86@kernel.org \
    /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