[PATCH RFT v8 4/9] fork: Add shadow stack support to clone3()

2024-08-08 Thread Mark Brown
-by: Mark Brown --- arch/x86/include/asm/shstk.h | 11 +++-- arch/x86/kernel/process.c| 2 +- arch/x86/kernel/shstk.c | 105 ++- include/linux/sched/task.h | 13 ++ include/uapi/linux/sched.h | 13 -- kernel/fork.c

[PATCH RFT v8 5/9] selftests/clone3: Remove redundant flushes of output streams

2024-08-08 Thread Mark Brown
Signed-off-by: Mark Brown --- tools/testing/selftests/clone3/clone3_selftests.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/tools/testing/selftests/clone3/clone3_selftests.h b/tools/testing/selftests/clone3/clone3_selftests.h index 3d2663fe50ba..39b5dcba663c 100644 --- a/tools/testing/s

[PATCH RFT v8 6/9] selftests/clone3: Factor more of main loop into test_clone3()

2024-08-08 Thread Mark Brown
change. Signed-off-by: Mark Brown --- tools/testing/selftests/clone3/clone3.c | 77 - 1 file changed, 37 insertions(+), 40 deletions(-) diff --git a/tools/testing/selftests/clone3/clone3.c b/tools/testing/selftests/clone3/clone3.c index e61f07973ce5..e066b201fa64

[PATCH RFT v8 7/9] selftests/clone3: Explicitly handle child exits due to signals

2024-08-08 Thread Mark Brown
In order to improve diagnostics and allow tests to explicitly look for signals check to see if the child exited due to a signal and if it did print the code and return it as a positive value, distinct from the negative errnos currently returned. Signed-off-by: Mark Brown --- tools/testing

[PATCH RFT v8 8/9] selftests/clone3: Allow tests to flag if -E2BIG is a valid error code

2024-08-08 Thread Mark Brown
lone3() may return -E2BIG due to the use of newer struct versions. Currently no tests need this but it will become an issue for testing clone3() support for shadow stacks, the support for shadow stacks is already present on x86. Signed-off-by: Mark Brown --- tools/testing/selftests/clone3/clone3.

[PATCH RFT v8 9/9] selftests/clone3: Test shadow stack support

2024-08-08 Thread Mark Brown
., this should be overly cautious. Signed-off-by: Mark Brown --- tools/testing/selftests/clone3/clone3.c | 134 +- tools/testing/selftests/clone3/clone3_selftests.h | 38 ++ 2 files changed, 171 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests

Re: [PATCH v10 38/40] kselftest/arm64: Add a GCS stress test

2024-08-08 Thread Mark Brown
On Thu, Aug 08, 2024 at 03:23:50AM -0300, Thiago Jung Bauermann wrote: > Thank you for the pointer. It turned out that I accidentally ran the > selftests binaries from the v9 version instead of the v10 version, and > the gcs-stress-thread binary failed because it was using the old value > for PR_S

Re: [PATCH RFT v8 4/9] fork: Add shadow stack support to clone3()

2024-08-09 Thread Mark Brown
On Fri, Aug 09, 2024 at 07:19:26PM +0100, Catalin Marinas wrote: > On Thu, Aug 08, 2024 at 09:15:25AM +0100, Mark Brown wrote: > > + /* This should really be an atomic cmpxchg. It is not. */ > > + if (access_remote_vm(mm, addr, &val, sizeof(val), > > +

Re: [PATCH] kselftest/arm64: signal: fix/refactor SVE vector length enumeration

2024-08-13 Thread Mark Brown
On Mon, Aug 12, 2024 at 03:09:24PM +0100, Andre Przywara wrote: > + /* Did we find the lowest supported VL? */ > + if (use_sme && vq < sve_vq_from_vl(vl)) > + break; We don't need the use_sme check here, SVE is just architecturally guaranteed to never t

Re: [PATCH RFT v8 4/9] fork: Add shadow stack support to clone3()

2024-08-13 Thread Mark Brown
On Tue, Aug 13, 2024 at 05:25:47PM +0100, Catalin Marinas wrote: > However, the x86 would be slightly inconsistent here between clone() and > clone3(). I guess it depends how you look at it. The classic clone() > syscall, if one doesn't pass CLONE_VM but does set new stack, there's no > new shadow

Re: [PATCH RFT v8 4/9] fork: Add shadow stack support to clone3()

2024-08-14 Thread Mark Brown
On Wed, Aug 14, 2024 at 10:38:54AM +0100, Catalin Marinas wrote: > On Tue, Aug 13, 2024 at 07:58:26PM +0100, Mark Brown wrote: > > ISTR the concerns were around someone being clever with vfork() but I > > don't remember anything super concrete. In terms of the inconsisten

Re: [PATCH v10 23/40] arm64/signal: Set up and restore the GCS context for signal handlers

2024-08-14 Thread Mark Brown
On Wed, Aug 14, 2024 at 03:51:42PM +0100, Dave Martin wrote: > On Thu, Aug 01, 2024 at 01:06:50PM +0100, Mark Brown wrote: > > + put_user_gcs((unsigned long)sigtramp, gcspr_el0 - 2, &ret); > > + put_user_gcs(GCS_SIGNAL_CAP(gcspr_el0 - 1), gcspr_el0 - 1, &ret

Re: [PATCH v10 24/40] arm64/signal: Expose GCS state in signal frames

2024-08-14 Thread Mark Brown
On Wed, Aug 14, 2024 at 04:09:51PM +0100, Dave Martin wrote: > On Thu, Aug 01, 2024 at 01:06:51PM +0100, Mark Brown wrote: > > + if (add_all || task_gcs_el0_enabled(current)) { > > + err = sigframe_alloc(user, &user->gcs_offset, > > +

Re: [PATCH RFT v8 4/9] fork: Add shadow stack support to clone3()

2024-08-15 Thread Mark Brown
On Thu, Aug 15, 2024 at 12:18:23AM +, Edgecombe, Rick P wrote: > On Thu, 2024-08-08 at 09:15 +0100, Mark Brown wrote: > > +   ssp = args->shadow_stack + args->shadow_stack_size; > > +   addr = ssp - SS_FRAME_SIZE; > > +   expected = ssp | BIT(0); >

Re: [PATCH v10 23/40] arm64/signal: Set up and restore the GCS context for signal handlers

2024-08-15 Thread Mark Brown
On Thu, Aug 15, 2024 at 02:37:22PM +0100, Dave Martin wrote: > Is there a test for taking and returning from a signal on an alternate > (main) stack, when a shadow stack is in use? Sounds like something > that would be good to check if not. Not specifically for any of the architectures. signat

Re: [PATCH v10 24/40] arm64/signal: Expose GCS state in signal frames

2024-08-15 Thread Mark Brown
On Thu, Aug 15, 2024 at 03:01:21PM +0100, Dave Martin wrote: > My thought was that if libc knows about shadow stacks, it is probably > going to be built to use them too and so would enable shadow stack > during startup to protect its own code. > (Technically those would be independent decisions,

Re: [PATCH v10 12/40] mm: Define VM_SHADOW_STACK for arm64 when we support GCS

2024-08-15 Thread Mark Brown
On Thu, Aug 15, 2024 at 03:20:52PM +, Edgecombe, Rick P wrote: > On Thu, 2024-08-01 at 13:06 +0100, Mark Brown wrote: > > Use VM_HIGH_ARCH_5 for guarded control stack pages. > FYI - If you want to have more complete guard gaps, you need to do this for > arm > too: > ht

Re: [PATCH v10 23/40] arm64/signal: Set up and restore the GCS context for signal handlers

2024-08-15 Thread Mark Brown
On Thu, Aug 15, 2024 at 04:11:56PM +0100, Dave Martin wrote: > On Thu, Aug 15, 2024 at 03:45:45PM +0100, Mark Brown wrote: > > On Thu, Aug 15, 2024 at 02:37:22PM +0100, Dave Martin wrote: > > > Is there a test for taking and returning from a signal on an alternate > >

Re: [PATCH v10 12/40] mm: Define VM_SHADOW_STACK for arm64 when we support GCS

2024-08-15 Thread Mark Brown
On Thu, Aug 15, 2024 at 04:26:47PM +0100, Mark Brown wrote: > On Thu, Aug 15, 2024 at 03:20:52PM +, Edgecombe, Rick P wrote: > > FYI - If you want to have more complete guard gaps, you need to do this for > > arm > > too: > > https://lore.kernel.org/linux-

Re: [PATCH v10 04/40] arm64: Document boot requirements for Guarded Control Stacks

2024-08-15 Thread Mark Brown
On Thu, Aug 15, 2024 at 06:00:15PM +0100, Catalin Marinas wrote: > On Thu, Aug 01, 2024 at 01:06:31PM +0100, Mark Brown wrote: > > + - If EL2 is present: > > +- GCSCR_EL2 must be initialised to 0. > > + - If the kernel is entered at EL1 and EL2 is present: > >

Re: [PATCH v10 12/40] mm: Define VM_SHADOW_STACK for arm64 when we support GCS

2024-08-15 Thread Mark Brown
On Thu, Aug 15, 2024 at 05:53:19PM +, Edgecombe, Rick P wrote: > On Thu, 2024-08-15 at 17:39 +0100, Mark Brown wrote: > > > Oh, thanks for the heads up - I'd missed that. > > Looking at this I think it makes sense to do as was done for x86 and > > split this out

Re: [PATCH RFT v8 4/9] fork: Add shadow stack support to clone3()

2024-08-16 Thread Mark Brown
On Fri, Aug 16, 2024 at 09:44:46AM +0100, Catalin Marinas wrote: > We could, in theory, consume this token in the parent before the child > mm is created. The downside is that if a parent forks multiple > processes using the same shadow stack, it will have to set the token > each time. I'd be fine

Re: [PATCH v10 05/40] arm64/gcs: Document the ABI for Guarded Control Stacks

2024-08-16 Thread Mark Brown
On Fri, Aug 16, 2024 at 12:09:01PM +0100, Catalin Marinas wrote: > On Thu, Aug 01, 2024 at 01:06:32PM +0100, Mark Brown wrote: > > +* EL0 GCS entries with bit 63 set are reserved for use, one such use is > > defined > Maybe "reserved for specific uses". The proposed

Re: [PATCH v10 14/40] KVM: arm64: Manage GCS access and registers for guests

2024-08-16 Thread Mark Brown
On Fri, Aug 16, 2024 at 03:15:19PM +0100, Marc Zyngier wrote: > Mark Brown wrote: > > + { SYS_DESC(SYS_GCSCR_EL1), NULL, reset_val, GCSCR_EL1, 0 }, > > + { SYS_DESC(SYS_GCSPR_EL1), NULL, reset_unknown, GCSPR_EL1 }, > > + { SYS_DESC(SYS_GCSCRE0_EL1), NULL, rese

Re: [PATCH RFT v8 4/9] fork: Add shadow stack support to clone3()

2024-08-16 Thread Mark Brown
On Fri, Aug 16, 2024 at 02:52:28PM +, Edgecombe, Rick P wrote: > On Fri, 2024-08-16 at 09:44 +0100, Catalin Marinas wrote: > > BTW, since it's the parent setting up the shadow stack in its own > > address space before forking, I think at least the read can avoid > > access_remote_vm() and we c

Re: [PATCH RFT v8 4/9] fork: Add shadow stack support to clone3()

2024-08-16 Thread Mark Brown
On Fri, Aug 16, 2024 at 04:29:13PM +0100, Catalin Marinas wrote: > On Fri, Aug 16, 2024 at 11:51:57AM +0100, Mark Brown wrote: > > I change back to parsing the token in the parent but I don't want to end > > up in a cycle of bouncing between the two implementations depending o

Re: [PATCH RFT v8 0/9] fork: Support shadow stacks in clone3()

2024-08-16 Thread Mark Brown
On Fri, Aug 16, 2024 at 05:52:20PM +0200, Jann Horn wrote: > As a heads-up so you don't get surprised by this in the future: > Because clone3() does not pass the flags in a register like clone() > does, it is not available in places like docker containers that use > the default Docker seccomp pol

Re: [PATCH 1/8] kselftest/arm64: signal: drop now redundant GNU_SOURCE definition

2024-08-16 Thread Mark Brown
are > not strictly identical, the compiler warns about it: > : warning: "_GNU_SOURCE" redefined > : note: this is the location of the previous definition Reviewed-by: Mark Brown signature.asc Description: PGP signature

Re: [PATCH 2/8] kselftest/arm64: hwcap: fix f8dp2 cpuinfo name

2024-08-16 Thread Mark Brown
On Fri, Aug 16, 2024 at 04:32:45PM +0100, Andre Przywara wrote: > The F8DP2 DPISA extension has a separate cpuinfo field, named > accordingly. > Change the erroneously placed name of "f8dp4" to "f8dp2". Reviewed-by: Mark Brown signature.asc Description: PGP signature

Re: [PATCH 3/8] kselftest/arm64: mte: use proper SKIP syntax

2024-08-16 Thread Mark Brown
On Fri, Aug 16, 2024 at 04:32:46PM +0100, Andre Przywara wrote: > If MTE is not available on a system, we detect this early and skip all > the MTE selftests. However this happens before we print the TAP plan, so > tools parsing the TAP output get confused and report an error. Reviewed

Re: [PATCH 4/8] kselftest/arm64: mte: use string literal for printf-style functions

2024-08-16 Thread Mark Brown
test/arm64: Add utilities and a test to validate > mte memory") I'm not sure this qualifies as a fix given that all the strings we're passing in here are trusted... otheriwse this looks good. Reviewed-by: Mark Brown signature.asc Description: PGP signature

Re: [PATCH 5/8] kselftest/arm64: mte: fix printf type warning about mask

2024-08-16 Thread Mark Brown
On Fri, Aug 16, 2024 at 04:32:48PM +0100, Andre Przywara wrote: > When masking the return value of a prctl, which is clearly an "int", we > use a uapi header provided mask, which is defined using an "UL" modifier, > so the whole expression is promoted to a long. This upsets the compiler's > printf

Re: [PATCH 6/8] kselftest/arm64: mte: fix printf type warnings about __u64

2024-08-16 Thread Mark Brown
question is defined in a > kernel uapi header, which uses a self defined __u64 type, and the arm64 > kernel headers define this using "int-ll64.h", so it becomes an > "unsigned long long". This mismatch leads to the usual compiler warning. Reviewed-by: Mark Brown signature.asc Description: PGP signature

Re: [PATCH 7/8] kselftest/arm64: mte: fix printf type warnings about pointers

2024-08-16 Thread Mark Brown
mte memory") This is another one where calling it a fix seems like it's pushing it, it's a modernisation rather than a correctness thing. Otherwise Reviewed-by: Mark Brown signature.asc Description: PGP signature

Re: [PATCH 8/8] kselftest/arm64: mte: fix printf type warnings about longs

2024-08-16 Thread Mark Brown
On Fri, Aug 16, 2024 at 04:32:51PM +0100, Andre Przywara wrote: > When checking MTE tags, we print some diagnostic messages when the tests > fail. Some variables uses there are "longs", however we only use "%x" > for the format specifier. Reviewed-by: Mark Brown s

Re: [PATCH RFT v8 4/9] fork: Add shadow stack support to clone3()

2024-08-16 Thread Mark Brown
On Fri, Aug 16, 2024 at 04:38:48PM +0100, Catalin Marinas wrote: > On Fri, Aug 16, 2024 at 02:52:28PM +, Edgecombe, Rick P wrote: > > On the x86 side, we don't have a shadow stack access CMPXCHG. We will have > > to > > GUP and do a normal CMPXCHG off of the direct map to handle it fully > >

Re: [PATCH 5/8] kselftest/arm64: mte: fix printf type warning about mask

2024-08-16 Thread Mark Brown
On Fri, Aug 16, 2024 at 05:55:48PM +0100, Andre Przywara wrote: > Mark Brown wrote: > > On Fri, Aug 16, 2024 at 04:32:48PM +0100, Andre Przywara wrote: > > > ksft_print_msg("Got %x, expected %x\n", > > > -

Re: [PATCH 7/8] kselftest/arm64: mte: fix printf type warnings about pointers

2024-08-16 Thread Mark Brown
On Fri, Aug 16, 2024 at 05:59:08PM +0100, Andre Przywara wrote: > Mark Brown wrote: > > On Fri, Aug 16, 2024 at 04:32:50PM +0100, Andre Przywara wrote: > > > Fixes: e9b60476bea0 ("kselftest/arm64: Add utilities and a test to > > > validate mte memory")

Re: [PATCH RFT v8 4/9] fork: Add shadow stack support to clone3()

2024-08-16 Thread Mark Brown
On Fri, Aug 16, 2024 at 07:08:09PM +0200, Jann Horn wrote: > Yeah, having a FOLL_FORCE write in clone3 would be a weakness for > userspace CFI and probably make it possible to violate mseal() > restrictions that are supposed to enforce that address space regions > are read-only. Note that this wi

Re: [PATCH v10 18/40] arm64/mm: Handle GCS data aborts

2024-08-19 Thread Mark Brown
On Mon, Aug 19, 2024 at 10:17:52AM +0100, Catalin Marinas wrote: > On Thu, Aug 01, 2024 at 01:06:45PM +0100, Mark Brown wrote: > > +static bool is_invalid_gcs_access(struct vm_area_struct *vma, u64 esr) > > +{ > > + if (unlikely(is_gcs_fault(esr))) { > > +

Re: [PATCH v10 19/40] arm64/gcs: Context switch GCS state for EL0

2024-08-19 Thread Mark Brown
On Mon, Aug 19, 2024 at 12:46:13PM +0100, Catalin Marinas wrote: > On Thu, Aug 01, 2024 at 01:06:46PM +0100, Mark Brown wrote: > > + /* > > +* Ensure that GCS changes are observable by/from other PEs in > > +* case of migration. > > +*/ > > +

Re: [PATCH v10 20/40] arm64/gcs: Ensure that new threads have a GCS

2024-08-19 Thread Mark Brown
On Mon, Aug 19, 2024 at 01:04:18PM +0100, Catalin Marinas wrote: > On Thu, Aug 01, 2024 at 01:06:47PM +0100, Mark Brown wrote: > > +static int copy_thread_gcs(struct task_struct *p, > > + const struct kernel_clone_args *args) > > +{ >

Re: [PATCH v2] kselftest/arm64: signal: fix/refactor SVE vector length enumeration

2024-08-19 Thread Mark Brown
er if only one vector length is > supported (but za_regs is correct) Reviewed-by: Mark Brown signature.asc Description: PGP signature

Re: [PATCH v10 13/40] arm64/mm: Map pages for guarded control stack

2024-08-19 Thread Mark Brown
On Mon, Aug 19, 2024 at 10:10:36AM +0100, Catalin Marinas wrote: > On Thu, Aug 01, 2024 at 01:06:40PM +0100, Mark Brown wrote: > > + if (system_supports_gcs() && (vm_flags & VM_SHADOW_STACK)) { > > + /* > > +* An executable

[PATCH RFT v9 0/8] fork: Support shadow stacks in clone3()

2024-08-19 Thread Mark Brown
adow stacks are supported it seemed sensible to roll it in here. [1] https://lore.kernel.org/r/20231009-arm64-gcs-v6-0-78e55deaa...@kernel.org/ Signed-off-by: Mark Brown --- Changes in v9: - Pull token validation earlier and report problems with an error return to parent rather than signal delive

[PATCH RFT v9 1/8] Documentation: userspace-api: Add shadow stack API documentation

2024-08-19 Thread Mark Brown
feature let's provide some documentation covering the common aspects. Reviewed-by: Catalin Marinas Reviewed-by: Kees Cook Tested-by: Kees Cook Acked-by: Shuah Khan Signed-off-by: Mark Brown --- Documentation/userspace-api/index.rst| 1 + Documentation/userspace-api/shadow_stack.rst

[PATCH RFT v9 2/8] selftests: Provide helper header for shadow stack testing

2024-08-19 Thread Mark Brown
interfaces. Reviewed-by: Rick Edgecombe Reviewed-by: Kees Cook Tested-by: Kees Cook Acked-by: Shuah Khan Signed-off-by: Mark Brown --- tools/testing/selftests/ksft_shstk.h | 63 1 file changed, 63 insertions(+) diff --git a/tools/testing/selftests/ksft_shstk.h b

[PATCH RFT v9 3/8] mm: Introduce ARCH_HAS_USER_SHADOW_STACK

2024-08-19 Thread Mark Brown
Gupta Reviewed-by: Rick Edgecombe Reviewed-by: Mike Rapoport (IBM) Reviewed-by: Catalin Marinas Reviewed-by: Kees Cook Tested-by: Kees Cook Acked-by: Shuah Khan Signed-off-by: Mark Brown --- arch/x86/Kconfig | 1 + fs/proc/task_mmu.c | 2 +- include/linux/mm.h | 2 +- mm/Kconfig | 6

[PATCH RFT v9 4/8] fork: Add shadow stack support to clone3()

2024-08-19 Thread Mark Brown
-by: Mark Brown --- arch/x86/include/asm/shstk.h | 11 +++-- arch/x86/kernel/process.c| 2 +- arch/x86/kernel/shstk.c | 103 +- include/linux/sched/task.h | 18 +++ include/uapi/linux/sched.h | 13 +++-- kernel/fork.c| 114

[PATCH RFT v9 5/8] selftests/clone3: Remove redundant flushes of output streams

2024-08-19 Thread Mark Brown
s. Reviewed-by: Kees Cook Tested-by: Kees Cook Acked-by: Shuah Khan Signed-off-by: Mark Brown --- tools/testing/selftests/clone3/clone3_selftests.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/tools/testing/selftests/clone3/clone3_selftests.h b/tools/testing/selftests/clone3/clone3_se

[PATCH RFT v9 6/8] selftests/clone3: Factor more of main loop into test_clone3()

2024-08-19 Thread Mark Brown
change. Reviewed-by: Kees Cook Tested-by: Kees Cook Acked-by: Shuah Khan Signed-off-by: Mark Brown --- tools/testing/selftests/clone3/clone3.c | 77 - 1 file changed, 37 insertions(+), 40 deletions(-) diff --git a/tools/testing/selftests/clone3/clone3.c b

[PATCH RFT v9 7/8] selftests/clone3: Allow tests to flag if -E2BIG is a valid error code

2024-08-19 Thread Mark Brown
d-off-by: Mark Brown --- tools/testing/selftests/clone3/clone3.c | 6 ++ 1 file changed, 6 insertions(+) diff --git a/tools/testing/selftests/clone3/clone3.c b/tools/testing/selftests/clone3/clone3.c index e066b201fa64..5b8b7d640e70 100644 --- a/tools/testing/selftests/clone3/clone3.c +++ b/

[PATCH RFT v9 8/8] selftests/clone3: Test shadow stack support

2024-08-19 Thread Mark Brown
., this should be overly cautious. Acked-by: Shuah Khan Signed-off-by: Mark Brown --- tools/testing/selftests/clone3/clone3.c | 147 +- tools/testing/selftests/clone3/clone3_selftests.h | 38 ++ 2 files changed, 184 insertions(+), 1 deletion(-) diff --git a/tools

Re: [PATCH v10 13/40] arm64/mm: Map pages for guarded control stack

2024-08-20 Thread Mark Brown
On Tue, Aug 20, 2024 at 03:59:21PM +0100, Catalin Marinas wrote: > On Mon, Aug 19, 2024 at 05:33:24PM +0100, Mark Brown wrote: > > On Mon, Aug 19, 2024 at 10:10:36AM +0100, Catalin Marinas wrote: > > > At a quick look, do_mmap() seems to always set VM_MAYEXEC but discar

Re: [PATCH v10 19/40] arm64/gcs: Context switch GCS state for EL0

2024-08-20 Thread Mark Brown
On Mon, Aug 19, 2024 at 04:44:52PM +0100, Mark Brown wrote: > On Mon, Aug 19, 2024 at 12:46:13PM +0100, Catalin Marinas wrote: > > On Thu, Aug 01, 2024 at 01:06:46PM +0100, Mark Brown wrote: > > > + /* > > > + * Ensure that GCS changes are observable by/from othe

Re: [PATCH RFT v9 4/8] fork: Add shadow stack support to clone3()

2024-08-20 Thread Mark Brown
On Tue, Aug 20, 2024 at 09:36:46PM +, Edgecombe, Rick P wrote: > On Mon, 2024-08-19 at 20:24 +0100, Mark Brown wrote: > > +   /* This should really be an atomic cmpxchg.  It is not. */ > > +   copy_from_user_page(vma, page, addr, &

Re: [PATCH RFT v9 4/8] fork: Add shadow stack support to clone3()

2024-08-20 Thread Mark Brown
On Tue, Aug 20, 2024 at 11:57:23PM +, Edgecombe, Rick P wrote: > On Wed, 2024-08-21 at 00:34 +0100, Mark Brown wrote: > > I was doing things this way for symmetry with how we specify the normal > > stack.  That's a bit different since the kernel will actually use the >

Re: [PATCH RFT v9 4/8] fork: Add shadow stack support to clone3()

2024-08-21 Thread Mark Brown
On Wed, Aug 21, 2024 at 01:45:16AM +, Edgecombe, Rick P wrote: > On Wed, 2024-08-21 at 01:19 +0100, Mark Brown wrote: > > I think it's going to be strange one way or another, either you specify > > a size that we don't currently really use or you have two things bot

Re: [PATCH v10 19/40] arm64/gcs: Context switch GCS state for EL0

2024-08-21 Thread Mark Brown
On Wed, Aug 21, 2024 at 09:50:22AM +0100, Catalin Marinas wrote: > On Tue, Aug 20, 2024 at 06:56:19PM +0100, Mark Brown wrote: > > I forgot when writing the above that we always allow reads from > > GCSPR_EL0 in order to avoid corner cases for unwinders in the case of > >

Re: [PATCH v10 21/40] arm64/gcs: Implement shadow stack prctl() interface

2024-08-21 Thread Mark Brown
On Wed, Aug 21, 2024 at 01:54:33PM +0100, Catalin Marinas wrote: > Otherwise it looks fine. > Reviewed-by: Catalin Marinas I've also added: + + /* Ensure we remember GCSPR_EL0 if we're disabling. */ + if (task_gcs_el0_enabled(current)) + current->thread.gcspr_el0 = re

Re: [PATCH RFT v9 4/8] fork: Add shadow stack support to clone3()

2024-08-21 Thread Mark Brown
On Wed, Aug 21, 2024 at 03:54:49PM +, Edgecombe, Rick P wrote: > On Wed, 2024-08-21 at 13:45 +0100, Mark Brown wrote: > > It's entirely possible it just leaked.  My own attempts to dig through > > the archives haven't turned up anything on the subjecti either, it see

Re: [PATCH v10 23/40] arm64/signal: Set up and restore the GCS context for signal handlers

2024-08-21 Thread Mark Brown
On Wed, Aug 21, 2024 at 06:28:49PM +0100, Catalin Marinas wrote: > On Thu, Aug 01, 2024 at 01:06:50PM +0100, Mark Brown wrote: > > + ret = copy_from_user(&cap, (__user void*)gcspr_el0, sizeof(cap)); > > + if (ret) > > + return -EFAULT; > Can the us

Re: [PATCH v10 25/40] arm64/ptrace: Expose GCS via ptrace and core files

2024-08-21 Thread Mark Brown
On Wed, Aug 21, 2024 at 06:57:16PM +0100, Catalin Marinas wrote: > On Thu, Aug 01, 2024 at 01:06:52PM +0100, Mark Brown wrote: > > + if (user_gcs.features_enabled & ~PR_SHADOW_STACK_SUPPORTED_STATUS_MASK) > > + return -EINVAL; > > + /* Do not allow enable

Re: [PATCH v10 25/40] arm64/ptrace: Expose GCS via ptrace and core files

2024-08-21 Thread Mark Brown
On Wed, Aug 21, 2024 at 07:28:08PM +0100, Mark Brown wrote: > part of an otherwise invalid write. The validation is checking for > unknown features and enables. With clone3() we could relax the enable > check, but I've just pulled that out of the series for the time being. Act

[PATCH RFT v10 0/8] fork: Support shadow stacks in clone3()

2024-08-21 Thread Mark Brown
adow stacks are supported it seemed sensible to roll it in here. [1] https://lore.kernel.org/r/20231009-arm64-gcs-v6-0-78e55deaa...@kernel.org/ Signed-off-by: Mark Brown --- Changes in v10: - Integrate fixes & improvements for the x86 implementation from Rick Edgecombe. - Require that the shado

[PATCH RFT v10 1/8] Documentation: userspace-api: Add shadow stack API documentation

2024-08-21 Thread Mark Brown
feature let's provide some documentation covering the common aspects. Reviewed-by: Catalin Marinas Reviewed-by: Kees Cook Tested-by: Kees Cook Acked-by: Shuah Khan Signed-off-by: Mark Brown --- Documentation/userspace-api/index.rst| 1 + Documentation/userspace-api/shadow_stack.rst

[PATCH RFT v10 2/8] selftests: Provide helper header for shadow stack testing

2024-08-21 Thread Mark Brown
interfaces. Reviewed-by: Rick Edgecombe Reviewed-by: Kees Cook Tested-by: Kees Cook Acked-by: Shuah Khan Signed-off-by: Mark Brown --- tools/testing/selftests/ksft_shstk.h | 61 1 file changed, 61 insertions(+) diff --git a/tools/testing/selftests/ksft_shstk.h b

[PATCH RFT v10 3/8] mm: Introduce ARCH_HAS_USER_SHADOW_STACK

2024-08-21 Thread Mark Brown
Gupta Reviewed-by: Rick Edgecombe Reviewed-by: Mike Rapoport (IBM) Reviewed-by: Catalin Marinas Reviewed-by: Kees Cook Tested-by: Kees Cook Acked-by: Shuah Khan Signed-off-by: Mark Brown --- arch/x86/Kconfig | 1 + fs/proc/task_mmu.c | 2 +- include/linux/mm.h | 2 +- mm/Kconfig | 6

[PATCH RFT v10 4/8] fork: Add shadow stack support to clone3()

2024-08-21 Thread Mark Brown
thread is executed. Since we are now using more fields from the kernel_clone_args we pass that into the shadow stack code rather than individual fields. Portions of the x86 architecture code were written by Rick Edgecombe. Signed-off-by: Mark Brown --- arch/x86/include/asm/shstk.h | 11

[PATCH RFT v10 5/8] selftests/clone3: Remove redundant flushes of output streams

2024-08-21 Thread Mark Brown
s. Reviewed-by: Kees Cook Tested-by: Kees Cook Acked-by: Shuah Khan Signed-off-by: Mark Brown --- tools/testing/selftests/clone3/clone3_selftests.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/tools/testing/selftests/clone3/clone3_selftests.h b/tools/testing/selftests/clone3/clone3_se

[PATCH RFT v10 6/8] selftests/clone3: Factor more of main loop into test_clone3()

2024-08-21 Thread Mark Brown
change. Reviewed-by: Kees Cook Tested-by: Kees Cook Acked-by: Shuah Khan Signed-off-by: Mark Brown --- tools/testing/selftests/clone3/clone3.c | 77 - 1 file changed, 37 insertions(+), 40 deletions(-) diff --git a/tools/testing/selftests/clone3/clone3.c b

[PATCH RFT v10 7/8] selftests/clone3: Allow tests to flag if -E2BIG is a valid error code

2024-08-21 Thread Mark Brown
d-off-by: Mark Brown --- tools/testing/selftests/clone3/clone3.c | 6 ++ 1 file changed, 6 insertions(+) diff --git a/tools/testing/selftests/clone3/clone3.c b/tools/testing/selftests/clone3/clone3.c index e066b201fa64..5b8b7d640e70 100644 --- a/tools/testing/selftests/clone3/clone3.c +++ b/

[PATCH RFT v10 8/8] selftests/clone3: Test shadow stack support

2024-08-21 Thread Mark Brown
., this should be overly cautious. Acked-by: Shuah Khan Signed-off-by: Mark Brown --- tools/testing/selftests/clone3/clone3.c | 171 +- tools/testing/selftests/clone3/clone3_selftests.h | 38 + 2 files changed, 208 insertions(+), 1 deletion(-) diff --git a/tools

[PATCH v11 00/39] arm64/gcs: Provide support for GCS in userspace

2024-08-21 Thread Mark Brown
hadow-stack-v9-0-962d74f99...@kernel.org Previous versions of this series depended on that, this dependency has been removed in order to make merging easier. [1] https://lore.kernel.org/lkml/20230213045351.3945824-1-de...@rivosinc.com/ Signed-off-by: Mark Brown --- Changes in v11: - Remove the depen

[PATCH v11 01/39] mm: Introduce ARCH_HAS_USER_SHADOW_STACK

2024-08-21 Thread Mark Brown
Gupta Reviewed-by: Rick Edgecombe Reviewed-by: Mike Rapoport (IBM) Reviewed-by: Catalin Marinas Reviewed-by: Kees Cook Tested-by: Kees Cook Acked-by: Shuah Khan Signed-off-by: Mark Brown --- arch/x86/Kconfig | 1 + fs/proc/task_mmu.c | 2 +- include/linux/mm.h | 2 +- mm/Kconfig | 6

[PATCH v11 02/39] arm64/mm: Restructure arch_validate_flags() for extensibility

2024-08-21 Thread Mark Brown
. Reviewed-by: Thiago Jung Bauermann Reviewed-by: Catalin Marinas Signed-off-by: Mark Brown --- arch/arm64/include/asm/mman.h | 14 ++ 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/arch/arm64/include/asm/mman.h b/arch/arm64/include/asm/mman.h index 5966ee4a6154

[PATCH v11 03/39] prctl: arch-agnostic prctl for shadow stack

2024-08-21 Thread Mark Brown
locking interface reworked. The set status prctl() is also reworked to just set flags, if setting/reading the shadow stack pointer is required this could be a separate prctl. Reviewed-by: Thiago Jung Bauermann Reviewed-by: Catalin Marinas Signed-off-by: Mark Brown --- include/linux/mm.h

[PATCH v11 04/39] mman: Add map_shadow_stack() flags

2024-08-21 Thread Mark Brown
stack marker suitable for use by unwinders should be added above that. For arm64 the top of stack marker is all bits 0. Reviewed-by: Thiago Jung Bauermann Reviewed-by: Catalin Marinas Signed-off-by: Mark Brown --- arch/x86/include/uapi/asm/mman.h | 3 --- include/uapi/asm-generic/mman.h | 4

[PATCH v11 05/39] arm64: Document boot requirements for Guarded Control Stacks

2024-08-21 Thread Mark Brown
fault we also require that the feature be specifically disabled, existing kernels implicitly have this requirement and especially given that the MMU must be disabled it is difficult to see a situation where leaving GCS enabled would be reasonable. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark

[PATCH v11 06/39] arm64/gcs: Document the ABI for Guarded Control Stacks

2024-08-21 Thread Mark Brown
Add some documentation of the userspace ABI for Guarded Control Stacks. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown --- Documentation/arch/arm64/gcs.rst | 230 + Documentation/arch/arm64/index.rst | 1 + 2 files changed, 231 insertions

[PATCH v11 07/39] arm64/sysreg: Add definitions for architected GCS caps

2024-08-21 Thread Mark Brown
The architecture defines a format for guarded control stack caps, used to mark the top of an unused GCS in order to limit the potential for exploitation via stack switching. Add definitions associated with these. Reviewed-by: Thiago Jung Bauermann Acked-by: Catalin Marinas Signed-off-by: Mark

[PATCH v11 08/39] arm64/gcs: Add manual encodings of GCS instructions

2024-08-21 Thread Mark Brown
sufficiently fast paths for this to be a problem. Note that GCSSTTR is used to store to EL0. Reviewed-by: Thiago Jung Bauermann Acked-by: Catalin Marinas Signed-off-by: Mark Brown --- arch/arm64/include/asm/gcs.h | 51 arch/arm64/include/asm/uaccess.h | 22

[PATCH v11 09/39] arm64/gcs: Provide put_user_gcs()

2024-08-21 Thread Mark Brown
In order for EL1 to write to an EL0 GCS it must use the GCSSTTR instruction rather than a normal STTR. Provide a put_user_gcs() which does this. Reviewed-by: Thiago Jung Bauermann Reviewed-by: Catalin Marinas Signed-off-by: Mark Brown --- arch/arm64/include/asm/uaccess.h | 18

[PATCH v11 10/39] arm64/gcs: Provide basic EL2 setup to allow GCS usage at EL0 and EL1

2024-08-21 Thread Mark Brown
function call instructions without faulting regardless of the state when the kernel is started. Reviewed-by: Thiago Jung Bauermann Reviewed-by: Catalin Marinas Signed-off-by: Mark Brown --- arch/arm64/include/asm/el2_setup.h | 29 + 1 file changed, 29 insertions(+) diff

[PATCH v11 11/39] arm64/cpufeature: Runtime detection of Guarded Control Stack (GCS)

2024-08-21 Thread Mark Brown
Add a cpufeature for GCS, allowing other code to conditionally support it at runtime. Reviewed-by: Thiago Jung Bauermann Reviewed-by: Catalin Marinas Signed-off-by: Mark Brown --- arch/arm64/include/asm/cpufeature.h | 6 ++ arch/arm64/kernel/cpufeature.c | 9 + arch/arm64

[PATCH v11 12/39] arm64/mm: Allocate PIE slots for EL0 guarded control stack

2024-08-21 Thread Mark Brown
-by: Mark Brown --- arch/arm64/include/asm/pgtable-prot.h | 14 -- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/pgtable-prot.h b/arch/arm64/include/asm/pgtable-prot.h index b11cfb9fdd37..545d54c88520 100644 --- a/arch/arm64/include/asm/pgtable

[PATCH v11 13/39] mm: Define VM_SHADOW_STACK for arm64 when we support GCS

2024-08-21 Thread Mark Brown
Use VM_HIGH_ARCH_5 for guarded control stack pages. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown --- Documentation/filesystems/proc.rst | 2 +- include/linux/mm.h | 12 +++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Documentation

[PATCH v11 14/39] arm64/mm: Map pages for guarded control stack

2024-08-21 Thread Mark Brown
Map pages flagged as being part of a GCS as such rather than using the full set of generic VM flags. This is done using a conditional rather than extending the size of protection_map since that would make for a very sparse array. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown

[PATCH v11 15/39] KVM: arm64: Manage GCS access and registers for guests

2024-08-21 Thread Mark Brown
deliberately conservative choice to avoid errors due to oversights. Further fields should be made writable in future. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown --- arch/arm64/include/asm/kvm_host.h | 12 arch/arm64/include/asm/vncr_mapping.h | 2 ++ arch/arm64/kvm

[PATCH v11 16/39] arm64/idreg: Add overrride for GCS

2024-08-21 Thread Mark Brown
Hook up an override for GCS, allowing it to be disabled from the command line by specifying arm64.nogcs in case there are problems. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown --- Documentation/admin-guide/kernel-parameters.txt | 3 +++ arch/arm64/kernel/pi/idreg-override.c

[PATCH v11 17/39] arm64/hwcap: Add hwcap for GCS

2024-08-21 Thread Mark Brown
Provide a hwcap to enable userspace to detect support for GCS. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown --- Documentation/arch/arm64/elf_hwcaps.rst | 2 ++ arch/arm64/include/asm/hwcap.h | 1 + arch/arm64/include/uapi/asm/hwcap.h | 1 + arch/arm64/kernel

[PATCH v11 18/39] arm64/traps: Handle GCS exceptions

2024-08-21 Thread Mark Brown
ating any GCS fault as fatal. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown --- arch/arm64/include/asm/esr.h | 28 +++- arch/arm64/include/asm/exception.h | 2 ++ arch/arm64/kernel/entry-common.c | 23 +++ arch/arm64/kernel/tr

[PATCH v11 19/39] arm64/mm: Handle GCS data aborts

2024-08-21 Thread Mark Brown
it attempts to do GCS operations outside a GCS. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown --- arch/arm64/mm/fault.c | 40 1 file changed, 40 insertions(+) diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index 451ba7cbd5ad

[PATCH v11 20/39] arm64/gcs: Context switch GCS state for EL0

2024-08-21 Thread Mark Brown
been disabled. Signed-off-by: Mark Brown --- arch/arm64/include/asm/gcs.h | 24 arch/arm64/include/asm/processor.h | 6 arch/arm64/kernel/process.c| 56 ++ arch/arm64/mm/Makefile | 1 + arch/arm64/mm/gcs.c

[PATCH v11 21/39] arm64/gcs: Ensure that new threads have a GCS

2024-08-21 Thread Mark Brown
allocate min(RLIMIT_STACK, 2G). Since the GCS only stores the call stack and not any variables this should be more than sufficient for most applications. GCSs allocated via this mechanism will be freed when the thread exits. Signed-off-by: Mark Brown --- arch/arm64/include/asm/gcs.h | 9

[PATCH v11 22/39] arm64/gcs: Implement shadow stack prctl() interface

2024-08-21 Thread Mark Brown
-by: Catalin Marinas Signed-off-by: Mark Brown --- arch/arm64/include/asm/gcs.h | 22 +++ arch/arm64/include/asm/processor.h | 1 + arch/arm64/mm/gcs.c| 79 ++ 3 files changed, 102 insertions(+) diff --git a/arch/arm64/include

[PATCH v11 23/39] arm64/mm: Implement map_shadow_stack()

2024-08-21 Thread Mark Brown
hiago Jung Bauermann Reviewed-by: Catalin Marinas Signed-off-by: Mark Brown --- arch/arm64/mm/gcs.c | 64 + 1 file changed, 64 insertions(+) diff --git a/arch/arm64/mm/gcs.c b/arch/arm64/mm/gcs.c index 5eb746fdd872..d9614900c910 100644 --- a/arc

[PATCH v11 24/39] arm64/signal: Set up and restore the GCS context for signal handlers

2024-08-21 Thread Mark Brown
;t be interpreted as a valid token or address. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown --- arch/arm64/include/asm/gcs.h | 1 + arch/arm64/kernel/signal.c | 112 +-- arch/arm64/mm/gcs.c | 1 + 3 files changed, 109 insertions(

[PATCH v11 25/39] arm64/signal: Expose GCS state in signal frames

2024-08-21 Thread Mark Brown
, there is a conflict between specifying GCSPR_EL0 and allocation of a new GCS and this is not an ancticipated use case. We also enforce GCS configuration locking on signal return. Reviewed-by: Thiago Jung Bauermann Signed-off-by: Mark Brown --- arch/arm64/include/uapi/asm/sigcontext.h | 9

[PATCH v11 26/39] arm64/ptrace: Expose GCS via ptrace and core files

2024-08-21 Thread Mark Brown
Signed-off-by: Mark Brown --- arch/arm64/include/uapi/asm/ptrace.h | 8 ++ arch/arm64/kernel/ptrace.c | 54 include/uapi/linux/elf.h | 1 + 3 files changed, 63 insertions(+) diff --git a/arch/arm64/include/uapi/asm/ptrace.h b

<    3   4   5   6   7   8   9   >